Skip to content

Commit

Permalink
Use plugin_module.print_libpath() as the way to get the libpath
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed May 17, 2023
1 parent d24a03e commit 65a1a30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
12 changes: 6 additions & 6 deletions blosc/blosc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ static int blosc2_initialize_context_from_header(blosc2_context* context, blosc_


int fill_filter(blosc2_filter *filter) {
char path[PATH_MAX];
void *lib = load_lib(filter->name, path);
char libpath[PATH_MAX];
void *lib = load_lib(filter->name, libpath);
if(lib == NULL) {
BLOSC_TRACE_ERROR("Error while loading the library");
return BLOSC2_ERROR_FAILURE;
Expand All @@ -813,8 +813,8 @@ int fill_filter(blosc2_filter *filter) {


int fill_codec(blosc2_codec *codec) {
char path[PATH_MAX];
void *lib = load_lib(codec->compname, path);
char libpath[PATH_MAX];
void *lib = load_lib(codec->compname, libpath);
if(lib == NULL) {
BLOSC_TRACE_ERROR("Error while loading the library");
return BLOSC2_ERROR_FAILURE;
Expand All @@ -835,8 +835,8 @@ int fill_codec(blosc2_codec *codec) {


int fill_tuner(blosc2_tuner *tuner) {
char path[PATH_MAX] = {0};
void *lib = load_lib(tuner->name, path);
char libpath[PATH_MAX] = {0};
void *lib = load_lib(tuner->name, libpath);
if(lib == NULL) {
BLOSC_TRACE_ERROR("Error while loading the library");
return BLOSC2_ERROR_FAILURE;
Expand Down
34 changes: 10 additions & 24 deletions include/blosc2/plugins-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,29 @@ const char *dlerror (void) {
#endif


static inline void* load_lib(char *plugin_name, char *path) {
static inline void* load_lib(char *plugin_name, char *libpath) {
char python_cmd[PATH_MAX] = {0};
char python_path[PATH_MAX] = {0};
sprintf(python_cmd, "python -c \"import blosc2_%s; print(blosc2_%s.__path__[0], end='')\"", plugin_name, plugin_name);
sprintf(python_cmd, "python -c \"import blosc2_%s; blosc2_%s.print_libpath()\"", plugin_name, plugin_name);
FILE *fp = popen(python_cmd, "r");
if (fp == NULL) {
BLOSC_TRACE_ERROR("Could not run python");
return NULL;
}
if (fgets(python_path, PATH_MAX, fp) == NULL) {
if (fgets(libpath, PATH_MAX, fp) == NULL) {
BLOSC_TRACE_ERROR("Could not read python output");
return NULL;
} BLOSC_TRACE_WARNING("python path for plugin blosc2_%s: %s\n", plugin_name, python_path);
}
pclose(fp);

if (strlen(python_path) == 0) {
BLOSC_TRACE_ERROR("Could not find python path");
if (strlen(libpath) == 0) {
BLOSC_TRACE_ERROR("Could not find plugin libpath");
return NULL;
}
void* loaded_lib;
#if defined(_WIN32)
sprintf(path, "%s/libblosc2_%s.dll", python_path, plugin_name);
#else
sprintf(path, "%s/libblosc2_%s.so", python_path, plugin_name);
BLOSC_TRACE_WARNING("Trying first path: %s\n", path);
loaded_lib = dlopen(path, RTLD_LAZY);
if (loaded_lib != NULL) {
return loaded_lib;
}
#endif
BLOSC_TRACE_WARNING("First attempt loading library %s. Trying 2nd path", dlerror());

sprintf(path, "%s/libblosc2_%s.dylib", python_path, plugin_name);
BLOSC_TRACE_WARNING("Trying second path: %s\n", path);
loaded_lib = dlopen(path, RTLD_LAZY);
BLOSC_TRACE_WARNING("libpath for plugin blosc2_%s: %s\n", plugin_name, libpath);
loaded_lib = dlopen(libpath, RTLD_LAZY);
if (loaded_lib == NULL) {
BLOSC_TRACE_ERROR("Second attempt loading library %s", dlerror());
BLOSC_TRACE_ERROR("Attempt to load plugin in path '%s' failed with error: %s",
libpath, dlerror());
}
return loaded_lib;
}

0 comments on commit 65a1a30

Please sign in to comment.