Browse Source

Use lib_t type for lib_* functions

tags/1.9.6
falkTX 10 years ago
parent
commit
90805901b5
5 changed files with 18 additions and 15 deletions
  1. +2
    -2
      source/backend/plugin/CarlaPluginInternal.hpp
  2. +1
    -1
      source/bridges-ui/CarlaBridgeClient.hpp
  3. +1
    -1
      source/discovery/carla-discovery.cpp
  4. +4
    -4
      source/utils/CarlaLibCounter.hpp
  5. +10
    -7
      source/utils/CarlaLibUtils.hpp

+ 2
- 2
source/backend/plugin/CarlaPluginInternal.hpp View File

@@ -217,8 +217,8 @@ struct CarlaPlugin::ProtectedData {
bool enabled; bool enabled;
bool needsReset; bool needsReset;


void* lib;
void* uiLib;
lib_t lib;
lib_t uiLib;


// misc // misc
int8_t ctrlChannel; int8_t ctrlChannel;


+ 1
- 1
source/bridges-ui/CarlaBridgeClient.hpp View File

@@ -117,7 +117,7 @@ private:
struct UI { struct UI {
CarlaBridgeToolkit* const toolkit; CarlaBridgeToolkit* const toolkit;
CarlaString filename; CarlaString filename;
void* lib;
lib_t lib;
bool quit; bool quit;


UI(CarlaBridgeToolkit* const toolkit_) UI(CarlaBridgeToolkit* const toolkit_)


+ 1
- 1
source/discovery/carla-discovery.cpp View File

@@ -1638,7 +1638,7 @@ int main(int argc, char* argv[])
} }


bool openLib = false; bool openLib = false;
void* handle = nullptr;
lib_t handle = nullptr;


switch (type) switch (type)
{ {


+ 4
- 4
source/utils/CarlaLibCounter.hpp View File

@@ -58,7 +58,7 @@ public:
fLibs.clear(); fLibs.clear();
} }


void* open(const char* const filename, const bool canDelete = true) noexcept
lib_t open(const char* const filename, const bool canDelete = true) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr); CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr);


@@ -87,7 +87,7 @@ public:
} }
} }


void* const libPtr(lib_open(filename));
const lib_t libPtr(lib_open(filename));


if (libPtr == nullptr) if (libPtr == nullptr)
{ {
@@ -108,7 +108,7 @@ public:
return nullptr; return nullptr;
} }


bool close(void* const libPtr) noexcept
bool close(const lib_t libPtr) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(libPtr != nullptr, false); CARLA_SAFE_ASSERT_RETURN(libPtr != nullptr, false);


@@ -151,7 +151,7 @@ public:


private: private:
struct Lib { struct Lib {
void* lib;
lib_t lib;
const char* filename; const char* filename;
int count; int count;
bool canDelete; bool canDelete;


+ 10
- 7
source/utils/CarlaLibUtils.hpp View File

@@ -20,8 +20,11 @@


#include "CarlaUtils.hpp" #include "CarlaUtils.hpp"


#ifndef CARLA_OS_WIN
#ifdef CARLA_OS_WIN
typedef HMODULE lib_t;
#else
# include <dlfcn.h> # include <dlfcn.h>
typedef void* lib_t;
#endif #endif


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -32,13 +35,13 @@
* May return null, in which case "lib_error" has the error. * May return null, in which case "lib_error" has the error.
*/ */
static inline static inline
void* lib_open(const char* const filename) noexcept
lib_t lib_open(const char* const filename) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr); CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', nullptr);


try { try {
#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
return (void*)::LoadLibraryA(filename);
return ::LoadLibraryA(filename);
#else #else
return ::dlopen(filename, RTLD_NOW|RTLD_LOCAL); return ::dlopen(filename, RTLD_NOW|RTLD_LOCAL);
#endif #endif
@@ -50,13 +53,13 @@ void* lib_open(const char* const filename) noexcept
* If false is returned, "lib_error" has the error. * If false is returned, "lib_error" has the error.
*/ */
static inline static inline
bool lib_close(void* const lib) noexcept
bool lib_close(const lib_t lib) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(lib != nullptr, false); CARLA_SAFE_ASSERT_RETURN(lib != nullptr, false);


try { try {
#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
return ::FreeLibrary((HMODULE)lib);
return ::FreeLibrary(lib);
#else #else
return (::dlclose(lib) == 0); return (::dlclose(lib) == 0);
#endif #endif
@@ -69,14 +72,14 @@ bool lib_close(void* const lib) noexcept
*/ */
template<typename Func> template<typename Func>
static inline static inline
Func lib_symbol(void* const lib, const char* const symbol) noexcept
Func lib_symbol(const lib_t lib, const char* const symbol) noexcept
{ {
CARLA_SAFE_ASSERT_RETURN(lib != nullptr, nullptr); CARLA_SAFE_ASSERT_RETURN(lib != nullptr, nullptr);
CARLA_SAFE_ASSERT_RETURN(symbol != nullptr && symbol[0] != '\0', nullptr); CARLA_SAFE_ASSERT_RETURN(symbol != nullptr && symbol[0] != '\0', nullptr);


try { try {
#ifdef CARLA_OS_WIN #ifdef CARLA_OS_WIN
return (Func)::GetProcAddress((HMODULE)lib, symbol);
return (Func)::GetProcAddress(lib, symbol);
#else #else
return (Func)(uintptr_t)::dlsym(lib, symbol); return (Func)(uintptr_t)::dlsym(lib, symbol);
#endif #endif


Loading…
Cancel
Save