| @@ -684,11 +684,6 @@ bool CarlaPlugin::ProtectedData::libClose() noexcept | |||
| return ret; | |||
| } | |||
| void* CarlaPlugin::ProtectedData::libSymbol(const char* const symbol) const noexcept | |||
| { | |||
| return lib_symbol(lib, symbol); | |||
| } | |||
| bool CarlaPlugin::ProtectedData::uiLibOpen(const char* const fname, const bool canDelete) noexcept | |||
| { | |||
| uiLib = sLibCounter.open(fname, canDelete); | |||
| @@ -702,11 +697,6 @@ bool CarlaPlugin::ProtectedData::uiLibClose() noexcept | |||
| return ret; | |||
| } | |||
| void* CarlaPlugin::ProtectedData::uiLibSymbol(const char* const symbol) const noexcept | |||
| { | |||
| return lib_symbol(uiLib, symbol); | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| void CarlaPlugin::ProtectedData::tryTransient() noexcept | |||
| @@ -21,6 +21,7 @@ | |||
| #include "CarlaPlugin.hpp" | |||
| #include "CarlaPluginThread.hpp" | |||
| #include "CarlaLibUtils.hpp" | |||
| #include "CarlaOscUtils.hpp" | |||
| #include "CarlaStateUtils.hpp" | |||
| @@ -330,13 +331,23 @@ struct CarlaPlugin::ProtectedData { | |||
| static const char* libError(const char* const filename) noexcept; | |||
| bool libOpen(const char* const filename) noexcept; | |||
| bool libClose() noexcept; | |||
| void* libSymbol(const char* const symbol) const noexcept; | |||
| bool libOpen(const char* const filename) noexcept; | |||
| bool libClose() noexcept; | |||
| bool uiLibOpen(const char* const filename, const bool canDelete) noexcept; | |||
| bool uiLibClose() noexcept; | |||
| void* uiLibSymbol(const char* const symbol) const noexcept; | |||
| bool uiLibOpen(const char* const filename, const bool canDelete) noexcept; | |||
| bool uiLibClose() noexcept; | |||
| template<typename Func> | |||
| Func libSymbol(const char* const symbol) const noexcept | |||
| { | |||
| return lib_symbol<Func>(lib, symbol); | |||
| } | |||
| template<typename Func> | |||
| Func uiLibSymbol(const char* const symbol) const noexcept | |||
| { | |||
| return lib_symbol<Func>(uiLib, symbol); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| // Misc | |||
| @@ -2025,7 +2025,7 @@ public: | |||
| // --------------------------------------------------------------- | |||
| // get DLL main entry | |||
| const DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)pData->libSymbol("dssi_descriptor"); | |||
| const DSSI_Descriptor_Function descFn = pData->libSymbol<DSSI_Descriptor_Function>("dssi_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -1551,7 +1551,7 @@ public: | |||
| // --------------------------------------------------------------- | |||
| // get DLL main entry | |||
| const LADSPA_Descriptor_Function descFn = (LADSPA_Descriptor_Function)pData->libSymbol("ladspa_descriptor"); | |||
| const LADSPA_Descriptor_Function descFn = pData->libSymbol<LADSPA_Descriptor_Function>("ladspa_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -4581,7 +4581,7 @@ public: | |||
| // --------------------------------------------------------------- | |||
| // try to get DLL main entry via new mode | |||
| if (const LV2_Lib_Descriptor_Function libDescFn = (LV2_Lib_Descriptor_Function)pData->libSymbol("lv2_lib_descriptor")) | |||
| if (const LV2_Lib_Descriptor_Function libDescFn = pData->libSymbol<LV2_Lib_Descriptor_Function>("lv2_lib_descriptor")) | |||
| { | |||
| // ----------------------------------------------------------- | |||
| // all ok, get lib descriptor | |||
| @@ -4609,7 +4609,7 @@ public: | |||
| // ----------------------------------------------------------- | |||
| // get DLL main entry (old mode) | |||
| const LV2_Descriptor_Function descFn = (LV2_Descriptor_Function)pData->libSymbol("lv2_descriptor"); | |||
| const LV2_Descriptor_Function descFn = pData->libSymbol<LV2_Descriptor_Function>("lv2_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -5110,7 +5110,7 @@ public: | |||
| // --------------------------------------------------------------- | |||
| // get UI DLL main entry | |||
| LV2UI_DescriptorFunction uiDescFn = (LV2UI_DescriptorFunction)pData->uiLibSymbol("lv2ui_descriptor"); | |||
| LV2UI_DescriptorFunction uiDescFn = pData->uiLibSymbol<LV2UI_DescriptorFunction>("lv2ui_descriptor"); | |||
| if (uiDescFn == nullptr) | |||
| { | |||
| @@ -2212,11 +2212,11 @@ public: | |||
| // --------------------------------------------------------------- | |||
| // get DLL main entry | |||
| VST_Function vstFn = (VST_Function)pData->libSymbol("VSTPluginMain"); | |||
| VST_Function vstFn = pData->libSymbol<VST_Function>("VSTPluginMain"); | |||
| if (vstFn == nullptr) | |||
| { | |||
| vstFn = (VST_Function)pData->libSymbol("main"); | |||
| vstFn = pData->libSymbol<VST_Function>("main"); | |||
| if (vstFn == nullptr) | |||
| { | |||
| @@ -245,14 +245,6 @@ bool CarlaBridgeClient::uiLibClose() | |||
| return closed; | |||
| } | |||
| void* CarlaBridgeClient::uiLibSymbol(const char* const symbol) | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr); | |||
| carla_debug("CarlaBridgeClient::uiLibSymbol(\"%s\")", symbol); | |||
| return lib_symbol(fUI.lib, symbol); | |||
| } | |||
| const char* CarlaBridgeClient::uiLibError() | |||
| { | |||
| carla_debug("CarlaBridgeClient::uiLibError()"); | |||
| @@ -20,6 +20,7 @@ | |||
| #include "CarlaBridgeOsc.hpp" | |||
| #include "CarlaBridgeToolkit.hpp" | |||
| #include "CarlaLibUtils.hpp" | |||
| CARLA_BRIDGE_START_NAMESPACE | |||
| @@ -91,11 +92,22 @@ protected: | |||
| void* getContainerId(); | |||
| void* getContainerId2(); | |||
| bool uiLibOpen(const char* const filename); | |||
| bool uiLibClose(); | |||
| void* uiLibSymbol(const char* const symbol); | |||
| // --------------------------------------------------------------------- | |||
| bool uiLibOpen(const char* const filename); | |||
| bool uiLibClose(); | |||
| const char* uiLibError(); | |||
| template<typename Func> | |||
| Func uiLibSymbol(const char* const symbol) | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(fUI.lib != nullptr, nullptr); | |||
| carla_debug("CarlaBridgeClient::uiLibSymbol(\"%s\")", symbol); | |||
| return lib_symbol<Func>(fUI.lib, symbol); | |||
| } | |||
| // --------------------------------------------------------------------- | |||
| private: | |||
| @@ -415,7 +415,7 @@ public: | |||
| // ----------------------------------------------------------------- | |||
| // get DLL main entry | |||
| const LV2UI_DescriptorFunction ui_descFn = (LV2UI_DescriptorFunction)uiLibSymbol("lv2ui_descriptor"); | |||
| const LV2UI_DescriptorFunction ui_descFn = uiLibSymbol<LV2UI_DescriptorFunction>("lv2ui_descriptor"); | |||
| if (ui_descFn == nullptr) | |||
| return false; | |||
| @@ -72,10 +72,10 @@ public: | |||
| // ----------------------------------------------------------------- | |||
| // get DLL main entry | |||
| VST_Function vstFn = (VST_Function)uiLibSymbol("VSTPluginMain"); | |||
| VST_Function vstFn = uiLibSymbol<VST_Function>("VSTPluginMain"); | |||
| if (vstFn == nullptr) | |||
| vstFn = (VST_Function)uiLibSymbol("main"); | |||
| vstFn = uiLibSymbol<VST_Function>("main"); | |||
| if (vstFn == nullptr) | |||
| return false; | |||
| @@ -403,7 +403,7 @@ private: | |||
| static void do_ladspa_check(void*& libHandle, const char* const filename, const bool doInit) | |||
| { | |||
| LADSPA_Descriptor_Function descFn = (LADSPA_Descriptor_Function)lib_symbol(libHandle, "ladspa_descriptor"); | |||
| LADSPA_Descriptor_Function descFn = lib_symbol<LADSPA_Descriptor_Function>(libHandle, "ladspa_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -443,7 +443,7 @@ static void do_ladspa_check(void*& libHandle, const char* const filename, const | |||
| return; | |||
| } | |||
| descFn = (LADSPA_Descriptor_Function)lib_symbol(libHandle, "ladspa_descriptor"); | |||
| descFn = lib_symbol<LADSPA_Descriptor_Function>(libHandle, "ladspa_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -636,7 +636,7 @@ static void do_ladspa_check(void*& libHandle, const char* const filename, const | |||
| static void do_dssi_check(void*& libHandle, const char* const filename, const bool doInit) | |||
| { | |||
| DSSI_Descriptor_Function descFn = (DSSI_Descriptor_Function)lib_symbol(libHandle, "dssi_descriptor"); | |||
| DSSI_Descriptor_Function descFn = lib_symbol<DSSI_Descriptor_Function>(libHandle, "dssi_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -684,7 +684,7 @@ static void do_dssi_check(void*& libHandle, const char* const filename, const bo | |||
| return; | |||
| } | |||
| descFn = (DSSI_Descriptor_Function)lib_symbol(libHandle, "dssi_descriptor"); | |||
| descFn = lib_symbol<DSSI_Descriptor_Function>(libHandle, "dssi_descriptor"); | |||
| if (descFn == nullptr) | |||
| { | |||
| @@ -1144,11 +1144,11 @@ static void do_lv2_check(const char* const bundle, const bool doInit) | |||
| #ifndef CARLA_OS_MAC | |||
| static void do_vst_check(void*& libHandle, const bool doInit) | |||
| { | |||
| VST_Function vstFn = (VST_Function)lib_symbol(libHandle, "VSTPluginMain"); | |||
| VST_Function vstFn = lib_symbol<VST_Function>(libHandle, "VSTPluginMain"); | |||
| if (vstFn == nullptr) | |||
| { | |||
| vstFn = (VST_Function)lib_symbol(libHandle, "main"); | |||
| vstFn = lib_symbol<VST_Function>(libHandle, "main"); | |||
| if (vstFn == nullptr) | |||
| { | |||
| @@ -228,7 +228,7 @@ private: \ | |||
| # ifdef BUILDING_CARLA | |||
| # define CARLA_API __declspec (dllexport) | |||
| # else | |||
| # define CARLA_API __declspec (imexport) | |||
| # define CARLA_API __declspec (dllimport) | |||
| # endif | |||
| # else | |||
| # define CARLA_API __attribute__ ((visibility("default"))) | |||
| @@ -368,7 +368,7 @@ struct JackBridge { | |||
| } | |||
| #define JOIN(a, b) a ## b | |||
| #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = (jacksym_##NAME)lib_symbol(lib, "jack_" #NAME); | |||
| #define LIB_SYMBOL(NAME) JOIN(NAME, _ptr) = lib_symbol<jacksym_##NAME>(lib, "jack_" #NAME); | |||
| LIB_SYMBOL(get_version) | |||
| LIB_SYMBOL(get_version_string) | |||
| @@ -34,7 +34,7 @@ public: | |||
| #endif | |||
| CARLA_SAFE_ASSERT_RETURN(lib != nullptr,); | |||
| func = (jackbridge_exported_function_type)lib_symbol(lib, "jackbridge_get_exported_functions"); | |||
| func = lib_symbol<jackbridge_exported_function_type>(lib, "jackbridge_get_exported_functions"); | |||
| CARLA_SAFE_ASSERT_RETURN(func != nullptr,); | |||
| } | |||
| @@ -71,6 +71,8 @@ static void test_CarlaJuceUtils() | |||
| // ----------------------------------------------------------------------- | |||
| typedef void (*nullFunc)(); | |||
| static void test_CarlaLibUtils() noexcept | |||
| { | |||
| void* const libNot = lib_open("/libzzzzz..."); | |||
| @@ -80,7 +82,7 @@ static void test_CarlaLibUtils() noexcept | |||
| void* const lib = lib_open("/usr/lib/liblo.so"); | |||
| CARLA_SAFE_ASSERT_RETURN(lib != nullptr,); | |||
| void* const libS = lib_symbol(lib, "lo_server_new"); | |||
| const nullFunc libS = lib_symbol<nullFunc>(lib, "lo_server_new"); | |||
| CARLA_SAFE_ASSERT(libS != nullptr); | |||
| const bool closed = lib_close(lib); | |||
| @@ -52,7 +52,9 @@ TARGETS += ansi-pedantic-test_cxx11 | |||
| TARGETS += CarlaRingBuffer | |||
| TARGETS += CarlaString | |||
| TARGETS += CarlaUtils1 | |||
| ifneq ($(WIN32),true) | |||
| TARGETS += CarlaUtils2 | |||
| endif | |||
| TARGETS += CarlaUtils3 | |||
| TARGETS += CarlaUtils4 | |||
| TARGETS += Exceptions | |||
| @@ -82,15 +84,21 @@ ansi-pedantic-test_cxx11: ansi-pedantic-test.cpp ../backend/Carla*.h ../includes | |||
| CarlaRingBuffer: CarlaRingBuffer.cpp ../utils/CarlaRingBuffer.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| CarlaString: CarlaString.cpp ../utils/CarlaString.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| CarlaUtils1: CarlaUtils1.cpp ../utils/*.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| CarlaUtils2: CarlaUtils2.cpp ../utils/*.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ \ | |||
| @@ -99,24 +107,34 @@ CarlaUtils2: CarlaUtils2.cpp ../utils/*.hpp | |||
| CarlaUtils3: CarlaUtils3.cpp ../utils/*.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ -ldl -lrt | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| CarlaUtils4: CarlaUtils4.cpp ../utils/CarlaStateUtils.cpp ../utils/*.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ \ | |||
| ../modules/juce_core.a -ldl -lpthread -lrt | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| Exceptions: Exceptions.cpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| Print: Print.cpp ../utils/CarlaUtils.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| RDF: RDF.cpp ../modules/ladspa_rdf.hpp ../modules/lv2_rdf.hpp | |||
| $(CXX) $< $(PEDANTIC_CXX_FLAGS) -o $@ | |||
| ifneq ($(WIN32),true) | |||
| ./$@ && valgrind --leak-check=full ./$@ | |||
| endif | |||
| # -------------------------------------------------------------- | |||
| @@ -67,17 +67,20 @@ bool lib_close(void* const lib) noexcept | |||
| * Get a library symbol (must not be null). | |||
| * Returns null if the symbol is not found. | |||
| */ | |||
| template<typename Func> | |||
| static inline | |||
| void* lib_symbol(void* const lib, const char* const symbol) noexcept | |||
| Func lib_symbol(void* const lib, const char* const symbol) noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(lib != nullptr, nullptr); | |||
| CARLA_SAFE_ASSERT_RETURN(symbol != nullptr && symbol[0] != '\0', nullptr); | |||
| try { | |||
| #ifdef CARLA_OS_WIN | |||
| return (void*)::GetProcAddress((HMODULE)lib, symbol); | |||
| return (Func)::GetProcAddress((HMODULE)lib, symbol); | |||
| #else | |||
| return ::dlsym(lib, symbol); | |||
| return (Func)(uintptr_t)::dlsym(lib, symbol); | |||
| #endif | |||
| } CARLA_SAFE_EXCEPTION_RETURN("lib_symbol", nullptr); | |||
| } | |||
| /* | |||
| @@ -117,7 +117,7 @@ shm_t carla_shm_attach(const char* const filename) noexcept | |||
| try { | |||
| #ifdef CARLA_OS_WIN | |||
| ret.shm = ::CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); | |||
| ret.shm = ::CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); | |||
| ret.map = nullptr; | |||
| #else | |||
| ret.fd = ::shm_open(filename, O_RDWR, 0); | |||
| @@ -174,7 +174,7 @@ void* carla_shm_map(shm_t& shm, const std::size_t size) noexcept | |||
| try { | |||
| #ifdef CARLA_OS_WIN | |||
| const HANDLE map = ::CreateFileMapping(shm.shm, NULL, PAGE_READWRITE, size, size, NULL); | |||
| const HANDLE map = ::CreateFileMapping(shm.shm, nullptr, PAGE_READWRITE, size, size, nullptr); | |||
| CARLA_SAFE_ASSERT_RETURN(map != nullptr, nullptr); | |||
| HANDLE ptr = ::MapViewOfFile(map, FILE_MAP_COPY, 0, 0, size); | |||