diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | alc/backends/alsa.cpp | 2 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 1 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 2 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 2 | ||||
-rw-r--r-- | alc/backends/pulseaudio.cpp | 3 | ||||
-rw-r--r-- | alc/compat.h | 16 | ||||
-rw-r--r-- | alc/helpers.cpp | 45 | ||||
-rw-r--r-- | common/dynload.cpp | 62 | ||||
-rw-r--r-- | common/dynload.h | 14 |
10 files changed, 84 insertions, 65 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fd0b69a..6fe05f35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -598,6 +598,8 @@ SET(COMMON_OBJS common/aloptional.h common/alspan.h common/atomic.h + common/dynload.cpp + common/dynload.h common/endiantest.h common/intrusive_ptr.h common/math_defs.h diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index c133df68..64f9cf46 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -44,7 +44,7 @@ #include "alnumeric.h" #include "aloptional.h" #include "alu.h" -#include "compat.h" +#include "dynload.h" #include "logging.h" #include "ringbuffer.h" #include "threads.h" diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 5a156d54..b9e52c0c 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -48,6 +48,7 @@ #include "alu.h" #include "ringbuffer.h" #include "compat.h" +#include "dynload.h" #include "threads.h" /* MinGW-w64 needs this for some unknown reason now. */ diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 3f81d08c..e688b96b 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -32,9 +32,9 @@ #include "alcmain.h" #include "alu.h" #include "alconfig.h" +#include "dynload.h" #include "ringbuffer.h" #include "threads.h" -#include "compat.h" #include <jack/jack.h> #include <jack/ringbuffer.h> diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 73e972c5..fcfd4b01 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -29,8 +29,8 @@ #include "alcmain.h" #include "alu.h" #include "alconfig.h" +#include "dynload.h" #include "ringbuffer.h" -#include "compat.h" #include <portaudio.h> diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 2ddcc86d..ca2ecb43 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -37,8 +37,9 @@ #include "alcmain.h" #include "alu.h" #include "alconfig.h" -#include "compat.h" #include "alexcpt.h" +#include "compat.h" +#include "dynload.h" #include <pulse/pulseaudio.h> diff --git a/alc/compat.h b/alc/compat.h index 4ffc40bf..648fa5b1 100644 --- a/alc/compat.h +++ b/alc/compat.h @@ -1,8 +1,6 @@ #ifndef AL_COMPAT_H #define AL_COMPAT_H -#ifdef __cplusplus - #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -86,8 +84,6 @@ public: } // namespace al -#define HAVE_DYNLOAD 1 - #else /* _WIN32 */ #include <fstream> @@ -99,10 +95,6 @@ using ifstream = std::ifstream; } // namespace al -#if defined(HAVE_DLFCN_H) -#define HAVE_DYNLOAD 1 -#endif - #endif /* _WIN32 */ #include <string> @@ -110,12 +102,4 @@ using ifstream = std::ifstream; struct PathNamePair { std::string path, fname; }; const PathNamePair &GetProcBinary(void); -#ifdef HAVE_DYNLOAD -void *LoadLib(const char *name); -void CloseLib(void *handle); -void *GetSymbol(void *handle, const char *name); -#endif - -#endif /* __cplusplus */ - #endif /* AL_COMPAT_H */ diff --git a/alc/helpers.cpp b/alc/helpers.cpp index d1401c3c..b952c5ed 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -81,9 +81,6 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x #endif #endif /* AL_NO_UID_DEFS */ -#ifdef HAVE_DLFCN_H -#include <dlfcn.h> -#endif #ifdef HAVE_INTRIN_H #include <intrin.h> #endif @@ -454,21 +451,6 @@ const PathNamePair &GetProcBinary() } -void *LoadLib(const char *name) -{ - std::wstring wname{utf8_to_wstr(name)}; - return LoadLibraryW(wname.c_str()); -} -void CloseLib(void *handle) -{ FreeLibrary(static_cast<HMODULE>(handle)); } -void *GetSymbol(void *handle, const char *name) -{ - void *ret{reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name))}; - if(!ret) ERR("Failed to load %s\n", name); - return ret; -} - - void al_print(FILE *logfile, const char *fmt, ...) { al::vector<char> dynmsg; @@ -683,33 +665,6 @@ const PathNamePair &GetProcBinary() } -#ifdef HAVE_DLFCN_H - -void *LoadLib(const char *name) -{ - dlerror(); - void *handle{dlopen(name, RTLD_NOW)}; - const char *err{dlerror()}; - if(err) handle = nullptr; - return handle; -} -void CloseLib(void *handle) -{ dlclose(handle); } -void *GetSymbol(void *handle, const char *name) -{ - dlerror(); - void *sym{dlsym(handle, name)}; - const char *err{dlerror()}; - if(err) - { - WARN("Failed to load %s: %s\n", name, err); - sym = nullptr; - } - return sym; -} - -#endif /* HAVE_DLFCN_H */ - void al_print(FILE *logfile, const char *fmt, ...) { va_list ap; diff --git a/common/dynload.cpp b/common/dynload.cpp new file mode 100644 index 00000000..89824f78 --- /dev/null +++ b/common/dynload.cpp @@ -0,0 +1,62 @@ + +#include "config.h" + +#include "dynload.h" + + +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +#include <string> + +inline std::wstring utf8_to_wstr(const char *str) +{ + std::wstring ret; + + int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); + if(len > 0) + { + ret.resize(len); + MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len); + ret.pop_back(); + } + + return ret; +} + +void *LoadLib(const char *name) +{ + std::wstring wname{utf8_to_wstr(name)}; + return LoadLibraryW(wname.c_str()); +} +void CloseLib(void *handle) +{ FreeLibrary(static_cast<HMODULE>(handle)); } +void *GetSymbol(void *handle, const char *name) +{ return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name)); } + +#elif defined(HAVE_DLFCN_H) + +#include <dlfcn.h> + +void *LoadLib(const char *name) +{ + dlerror(); + void *handle{dlopen(name, RTLD_NOW)}; + const char *err{dlerror()}; + if(err) handle = nullptr; + return handle; +} +void CloseLib(void *handle) +{ dlclose(handle); } +void *GetSymbol(void *handle, const char *name) +{ + dlerror(); + void *sym{dlsym(handle, name)}; + const char *err{dlerror()}; + if(err) sym = nullptr; + return sym; +} + +#endif diff --git a/common/dynload.h b/common/dynload.h new file mode 100644 index 00000000..bd9e86f7 --- /dev/null +++ b/common/dynload.h @@ -0,0 +1,14 @@ +#ifndef AL_DYNLOAD_H +#define AL_DYNLOAD_H + +#if defined(_WIN32) || defined(HAVE_DLFCN_H) + +#define HAVE_DYNLOAD + +void *LoadLib(const char *name); +void CloseLib(void *handle); +void *GetSymbol(void *handle, const char *name); + +#endif + +#endif /* AL_DYNLOAD_H */ |