Changeset: 1eea294e3c5f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1eea294e3c5f
Modified Files:
        gdk/gdk.h
        gdk/gdk_storage.c
        monetdb5/mal/mal_linker.c
Branch: default
Log Message:

In LoadLibrary, if a dynamic library exists but dlopen() fails throw an error 
message.

This should help when debugging runtime linking issues, currently only 
"sql.prelude() is missing" is displayed when linking fails. Now the actual 
linking error should be displayed.

e.g.:

!LoaderException:loadLibrary:Loading error failed to open library pyapi (from 
within file '/Users/myth/opt/lib/monetdb5/lib_pyapi.so'): 
dlopen(/Users/myth/opt/lib/monetdb5/lib_pyapi.so, 10): Symbol not found: 
_undefined_function
!  Referenced from: /Users/myth/opt/lib/monetdb5/lib_pyapi.so
!  Expected in: flat namespace
! in /Users/myth/opt/lib/monetdb5/lib_pyapi.so


diffs (63 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1494,6 +1494,7 @@ gdk_export size_t BATmemsize(BAT *b, int
 
 #define NOFARM (-1) /* indicate to GDKfilepath to create relative path */
 
+gdk_export int GDKfileexists(const char *path);
 gdk_export char *GDKfilepath(int farmid, const char *dir, const char *nme, 
const char *ext);
 gdk_export gdk_return GDKcreatedir(const char *nme);
 
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -87,6 +87,16 @@ GDKfilepath(int farmid, const char *dir,
        return path;
 }
 
+/*
+ * returns 1 if the file exists
+ */
+int 
+GDKfileexists(const char *path) {
+       struct stat st;
+       int ret = stat(path, &st);
+       return (ret == 0);
+}
+
 /* make sure the parent directory of DIR exists (the argument itself
  * is usually a file that is to be created) */
 gdk_return
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -178,12 +178,18 @@ loadLibrary(str filename, int flag)
                                 mod_path, DIR_SEP, SO_PREFIX, s, SO_EXT);
 #endif
                handle = dlopen(nme, mode);
+               if (handle == NULL && GDKfileexists(nme)) {
+                       throw(LOADER, "loadLibrary", RUNTIME_LOAD_ERROR " 
failed to open library %s (from within file '%s'): %s", s, nme, dlerror());
+               }
                if (handle == NULL && strcmp(SO_EXT, ".so") != 0) {
                        /* try .so */
                        snprintf(nme, PATHLENGTH, "%.*s%c%s_%s.so",
                                         (int) (p - mod_path),
                                         mod_path, DIR_SEP, SO_PREFIX, s);
                        handle = dlopen(nme, mode);
+                       if (handle == NULL && GDKfileexists(nme)) {
+                               throw(LOADER, "loadLibrary", RUNTIME_LOAD_ERROR 
" failed to open library %s (from within file '%s'): %s", s, nme, dlerror());
+                       }
                }
 #ifdef __APPLE__
                if (handle == NULL && strcmp(SO_EXT, ".bundle") != 0) {
@@ -192,6 +198,9 @@ loadLibrary(str filename, int flag)
                                         (int) (p - mod_path),
                                         mod_path, DIR_SEP, SO_PREFIX, s);
                        handle = dlopen(nme, mode);
+                       if (handle == NULL && GDKfileexists(nme)) {
+                               throw(LOADER, "loadLibrary", RUNTIME_LOAD_ERROR 
" failed to open library %s (from within file '%s'): %s", s, nme, dlerror());
+                       }
                }
 #endif
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to