[libbluray-devel] [Git][videolan/libbluray][master] 4 commits: Use dladdr() when available.

Petri Hintukainen gitlab at videolan.org
Fri Jan 22 16:53:20 UTC 2021



Petri Hintukainen pushed to branch master at VideoLAN / libbluray


Commits:
2ebd99c6 by hpi1 at 2021-01-22T18:28:17+02:00
Use dladdr() when available.

Used to search for JVM and .jar files from libbluray installation directory.

- - - - -
521294c1 by hpi1 at 2021-01-22T18:36:07+02:00
bdj: Avoid probing the same JVM library multiple times.

Triggered when trying to load JVM without absolute path (=default library path for dynamic loader).

- - - - -
534d6cd5 by hpi1 at 2021-01-22T18:44:13+02:00
bdj: Optimize JVM probing.

Do not check subdirs of non-existing top-level directory.

- - - - -
093fdbb6 by hpi1 at 2021-01-22T18:47:08+02:00
bdj: Add new JVM search paths.

- - - - -


3 changed files:

- configure.ac
- src/file/dl_posix.c
- src/libbluray/bdj/bdj.c


Changes:

=====================================
configure.ac
=====================================
@@ -154,6 +154,23 @@ AS_IF([test "${SYS}" != "mingw32"], [
   AS_CASE([$DLOPEN_LIBS],
     [no|none\ required], [DLOPEN_LIBS=""])
   AC_SUBST([DLOPEN_LIBS])
+
+  AC_MSG_CHECKING([for dladdr])
+  saved_LIBS="$LIBS"
+  LIBS="$LIBS $DLOPEN_LIBS"
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+        #define _GNU_SOURCE
+        #include <dlfcn.h>
+      ]], [[
+        Dl_info dl_info;
+        return dladdr(&dl_info, &dl_info);
+    ]])], [
+      AC_MSG_RESULT([yes])
+      AC_DEFINE([HAVE_DLADDR], 1, [Define to 1 if you have a dladdr().])
+    ], [
+      AC_MSG_RESULT([no])
+    ])
+  LIBS="$saved_LIBS"
 ])
 
 dnl libxml2 for metadata parser


=====================================
src/file/dl_posix.c
=====================================
@@ -22,6 +22,10 @@
 #include "config.h"
 #endif
 
+#ifdef HAVE_DLADDR
+#  define _GNU_SOURCE  /* dladdr */
+#endif
+
 #include "dl.h"
 #include "util/macro.h"
 #include "util/logging.h"
@@ -127,10 +131,9 @@ const char *dl_get_path(void)
     if (!initialized) {
         initialized = 1;
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(HAVE_DLADDR)
         Dl_info dl_info;
         int ret = dladdr((void *)dl_get_path, &dl_info);
-
         if (ret != 0) {
             lib_path = strdup(dl_info.dli_fname);
 


=====================================
src/libbluray/bdj/bdj.c
=====================================
@@ -301,7 +301,6 @@ static char *_java_home_macos()
 
 static void *_jvm_dlopen(const char *java_home, const char *jvm_dir, const char *jvm_lib)
 {
-    if (java_home) {
         char *path = str_printf("%s" DIR_SEP "%s" DIR_SEP "%s", java_home, jvm_dir, jvm_lib);
         if (!path) {
             BD_DEBUG(DBG_CRIT, "out of memory\n");
@@ -319,10 +318,6 @@ static void *_jvm_dlopen(const char *java_home, const char *jvm_dir, const char
 # endif
         X_FREE(path);
         return h;
-    } else {
-        BD_DEBUG(DBG_BDJ, "Opening %s ...\n", jvm_lib);
-        return dl_dlopen(jvm_lib, NULL);
-    }
 }
 
 static void *_jvm_dlopen_a(const char *java_home,
@@ -332,6 +327,11 @@ static void *_jvm_dlopen_a(const char *java_home,
   unsigned ii;
   void *dll = NULL;
 
+  if (!java_home) {
+      BD_DEBUG(DBG_BDJ, "Opening %s ...\n", jvm_lib);
+      return dl_dlopen(jvm_lib, NULL);
+  }
+
   for (ii = 0; !dll && ii < num_jvm_dir; ii++) {
       dll = _jvm_dlopen(java_home, jvm_dir[ii], jvm_lib);
   }
@@ -414,7 +414,10 @@ static void *_load_jvm(const char **p_java_home)
 #    endif
     };
     static const char * const jvm_dir[]  = {"jre/lib/" JAVA_ARCH "/server",
+                                            "lib/" JAVA_ARCH "/server",
                                             "lib/server",
+                                            "jre/lib/" JAVA_ARCH "/client",
+                                            "lib/" JAVA_ARCH "/client",
                                             "lib/client",
     };
 #  endif
@@ -463,8 +466,14 @@ static void *_load_jvm(const char **p_java_home)
 
     /* try our pre-defined locations */
     for (path_ind = 0; !handle && path_ind < num_jvm_path; path_ind++) {
-        *p_java_home = jvm_path[path_ind];
-        handle = _jvm_dlopen_a(jvm_path[path_ind], jvm_dir, num_jvm_dir, jvm_lib);
+        if (jvm_path[path_ind] && !jvm_path[path_ind][0]) {
+            /* skip empty JVM_HOME */
+        } else if (jvm_path[path_ind] && file_path_exists(jvm_path[path_ind]) < 0) {
+            BD_DEBUG(DBG_BDJ, "Skipping %s (not found)\n", jvm_path[path_ind]);
+        } else {
+            *p_java_home = jvm_path[path_ind];
+            handle = _jvm_dlopen_a(jvm_path[path_ind], jvm_dir, num_jvm_dir, jvm_lib);
+        }
     }
 
     if (!*p_java_home) {



View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/88d899498c7089f02c617e7b7df23fda2cea7e7b...093fdbb61843a202deb7a433aedfcd8004cc6122

-- 
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/compare/88d899498c7089f02c617e7b7df23fda2cea7e7b...093fdbb61843a202deb7a433aedfcd8004cc6122
You're receiving this email because of your account on code.videolan.org.




More information about the libbluray-devel mailing list