|
1 | | -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. |
| 1 | +// Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O. |
2 | 2 | // This file is part of the "Nabla Engine". |
3 | 3 | // For conditions of distribution and use, see copyright notice in nabla.h |
4 | | - |
5 | 4 | #ifndef _NBL_SYSTEM_DEFAULT_FUNC_PTR_LOADER_H_INCLUDED_ |
6 | 5 | #define _NBL_SYSTEM_DEFAULT_FUNC_PTR_LOADER_H_INCLUDED_ |
7 | 6 |
|
8 | | -#include "nbl/system/FuncPtrLoader.h" |
9 | 7 |
|
10 | | -#if defined(_NBL_WINDOWS_API_) |
11 | | - #define WIN32_LEAN_AND_MEAN |
12 | | - #include <windows.h> |
13 | | - #include <stdio.h> |
14 | | -#elif defined(_NBL_POSIX_API_) |
15 | | - #include <dlfcn.h> |
16 | | -#endif |
| 8 | +#include "nbl/system/FuncPtrLoader.h" |
17 | 9 |
|
18 | 10 |
|
19 | 11 | namespace nbl::system |
20 | 12 | { |
21 | 13 |
|
22 | 14 | class DefaultFuncPtrLoader final : FuncPtrLoader |
23 | 15 | { |
24 | | - protected: |
25 | | - #if defined(_NBL_WINDOWS_API_) |
26 | | - HMODULE lib; |
27 | | - #elif defined(_NBL_POSIX_API_) |
28 | | - void* lib; |
29 | | - #endif |
30 | | - public: |
31 | | - DefaultFuncPtrLoader() : lib(NULL) {} |
32 | | - DefaultFuncPtrLoader(const char* name) : DefaultFuncPtrLoader() |
33 | | - { |
34 | | - if (!name) |
35 | | - return; |
| 16 | + void* lib; |
36 | 17 |
|
37 | | - // TODO: redo with either LoadLibraryExA or SetDllDirectoryA and linux equivalents to allow loading shared libraries |
38 | | - // with other shared library dependencies from regular directories without changing CWD (which is not thread safe) |
39 | | - #if defined(_NBL_WINDOWS_API_) |
40 | | - std::string libname(name); |
41 | | - libname += ".dll"; |
42 | | - lib = LoadLibraryA(libname.c_str()); |
43 | | - if (!lib) |
44 | | - lib = LoadLibraryA(name); |
45 | | - #elif defined(_NBL_POSIX_API_) |
46 | | - std::string libname("lib"); |
47 | | - libname += name; |
48 | | - libname += ".so"; |
49 | | - lib = dlopen(libname.c_str(),RTLD_LAZY); |
50 | | - if (!lib) |
51 | | - lib = dlopen(name,RTLD_LAZY); |
52 | | - #endif |
53 | | - } |
54 | | - DefaultFuncPtrLoader(DefaultFuncPtrLoader&& other) : DefaultFuncPtrLoader() |
| 18 | + public: |
| 19 | + inline DefaultFuncPtrLoader() : lib(nullptr) {} |
| 20 | + NBL_API2 DefaultFuncPtrLoader(const char* name); |
| 21 | + inline DefaultFuncPtrLoader(DefaultFuncPtrLoader&& other) : DefaultFuncPtrLoader() |
55 | 22 | { |
56 | 23 | operator=(std::move(other)); |
57 | 24 | } |
58 | | - ~DefaultFuncPtrLoader() |
59 | | - { |
60 | | - if (lib != NULL) |
61 | | - #if defined(_NBL_WINDOWS_API_) |
62 | | - FreeLibrary(lib); |
63 | | - #elif defined(_NBL_POSIX_API_) |
64 | | - dlclose(lib); |
65 | | - #endif |
66 | | - } |
| 25 | + NBL_API2 ~DefaultFuncPtrLoader(); |
67 | 26 |
|
68 | 27 | inline DefaultFuncPtrLoader& operator=(DefaultFuncPtrLoader&& other) |
69 | 28 | { |
70 | | - std::swap(lib, other.lib); |
| 29 | + std::swap(lib,other.lib); |
71 | 30 | return *this; |
72 | 31 | } |
73 | 32 |
|
74 | 33 | inline bool isLibraryLoaded() override final |
75 | 34 | { |
76 | | - return lib!=NULL; |
| 35 | + return lib!=nullptr; |
77 | 36 | } |
78 | 37 |
|
79 | | - inline void* loadFuncPtr(const char* funcname) override final |
80 | | - { |
81 | | - if (isLibraryLoaded()) |
82 | | - { |
83 | | - #if defined(_NBL_WINDOWS_API_) |
84 | | - return GetProcAddress(lib,funcname); |
85 | | - #elif defined(_NBL_POSIX_API_) |
86 | | - return dlsym(lib,funcname); |
87 | | - #endif |
88 | | - } |
89 | | - return nullptr; |
90 | | - } |
| 38 | + void* loadFuncPtr(const char* funcname) override final; |
91 | 39 | }; |
92 | 40 |
|
93 | 41 | } |
|
0 commit comments