Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add option to not unload LV2 binaries
  • Loading branch information
x42 committed Sep 2, 2019
1 parent 0d21308 commit 1081994
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -60,7 +60,7 @@ endif

PLUGIN_SRC= \
src/instantiate.cc \
src/loadlib.c \
src/loadlib.cc \
src/lv2ttl.cc \
src/lv2vst.cc \
src/lv2vstui.cc \
Expand Down
22 changes: 20 additions & 2 deletions src/loadlib.c → src/loadlib.cc
Expand Up @@ -32,10 +32,28 @@ static inline const char* dlerror(void) { return "Unknown error"; }

#include "loadlib.h"

void* open_lv2_lib (const char* lib_path)
void* open_lv2_lib (const char* lib_path, bool persist)
{
dlerror();
void* lib = dlopen (lib_path, RTLD_NOW);

#ifndef _WIN32
int flags = RTLD_NOW;
#endif

#if ! (defined BUNDLES || defined _WIN32 || defined __APPLE__)
/* Linux, likely with system-wide, dynamically linked plugins.
*
* In many such cases unloading UI libs can cause issues
* (e.g. re-initialize pango font-cache, re-use gobject, because
* static variables are initialized when the object is reloaded).
* To allows to work around this issue, by not unloading the module.
*/
if (persist) {
flags |= RTLD_NODELETE;
}
#endif

void* lib = dlopen (lib_path, flags);
if (!lib) {
fprintf (stderr, "LV2Host: Failed to open library %s (%s)\n", lib_path, dlerror());
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/loadlib.h
Expand Up @@ -21,7 +21,7 @@

typedef void (*VstVoidFunc)(void);
VstVoidFunc x_dlfunc (void* handle, const char* symbol);
void* open_lv2_lib (const char* lib_path);
void* open_lv2_lib (const char* lib_path, bool persist = false);
void close_lv2_lib (void*);

const char* get_lib_path ();
Expand Down

0 comments on commit 1081994

Please sign in to comment.