diff options
author | Tom Tromey <tromey@redhat.com> | 2002-12-10 01:39:32 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2002-12-10 01:39:32 +0000 |
commit | 78bb0444d2223d7b3b2089d4b50960f6464d4ba6 (patch) | |
tree | 59b0509caff8da0f2b263136eaf28134e6f4c188 /libjava | |
parent | c53be425f7985fd00baf4fbc49bf2e66d02e5ecb (diff) | |
download | gcc-78bb0444d2223d7b3b2089d4b50960f6464d4ba6.zip gcc-78bb0444d2223d7b3b2089d4b50960f6464d4ba6.tar.gz gcc-78bb0444d2223d7b3b2089d4b50960f6464d4ba6.tar.bz2 |
win32.h (_Jv_platform_solib_prefix): New define.
* include/win32.h (_Jv_platform_solib_prefix): New define.
(_Jv_platform_solib_suffix): Likewise.
* include/posix.h (_Jv_platform_solib_prefix): New define.
(_Jv_platform_solib_suffix): Likewise.
* java/lang/natRuntime.cc: Include StackTrace.h.
(_load): Use findLibrary and new platform defines.
(nativeGetLibname): Use new platform defines.
From-SVN: r59976
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 8 | ||||
-rw-r--r-- | libjava/include/posix.h | 4 | ||||
-rw-r--r-- | libjava/include/win32.h | 4 | ||||
-rw-r--r-- | libjava/java/lang/natRuntime.cc | 68 |
4 files changed, 65 insertions, 19 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 7ec6424..3e1fdda 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,13 @@ 2002-12-09 Tom Tromey <tromey@redhat.com> + * include/win32.h (_Jv_platform_solib_prefix): New define. + (_Jv_platform_solib_suffix): Likewise. + * include/posix.h (_Jv_platform_solib_prefix): New define. + (_Jv_platform_solib_suffix): Likewise. + * java/lang/natRuntime.cc: Include StackTrace.h. + (_load): Use findLibrary and new platform defines. + (nativeGetLibname): Use new platform defines. + * java/util/natResourceBundle.cc (getCallingClassLoader): Assume `t' won't be null. diff --git a/libjava/include/posix.h b/libjava/include/posix.h index 4bb1d56..cdcdb5d 100644 --- a/libjava/include/posix.h +++ b/libjava/include/posix.h @@ -40,6 +40,10 @@ details. */ #include <gcj/cni.h> #include <java/util/Properties.h> +// Prefix and suffix for shared libraries. +#define _Jv_platform_solib_prefix "lib" +#define _Jv_platform_solib_suffix ".so" + #ifndef DISABLE_JAVA_NET #include <java/net/InetAddress.h> #endif diff --git a/libjava/include/win32.h b/libjava/include/win32.h index 62bc0c3..f05f30d 100644 --- a/libjava/include/win32.h +++ b/libjava/include/win32.h @@ -22,6 +22,10 @@ details. */ #include <io.h> +// Prefix and suffix for shared libraries. +#define _Jv_platform_solib_prefix "" +#define _Jv_platform_solib_suffix ".dll" + #ifndef DISBALE_JAVA_NET // these errors cannot occur on Win32 diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index 6737dbc..f5177b0 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -27,6 +27,8 @@ details. */ #include <java/lang/StringBuffer.h> #include <java/lang/Process.h> #include <java/lang/ConcreteProcess.h> +#include <java/lang/ClassLoader.h> +#include <gnu/gcj/runtime/StackTrace.h> #include <jni.h> @@ -161,18 +163,56 @@ java::lang::Runtime::_load (jstring path, jboolean do_search) using namespace java::lang; #ifdef USE_LTDL jint len = _Jv_GetStringUTFLength (path); - char buf[len + 1 + 3]; + char buf[len + 1 + strlen (_Jv_platform_solib_prefix) + + strlen (_Jv_platform_solib_suffix)]; int offset = 0; -#ifndef WIN32 - // On Unix boxes, prefix library name with `lib', for loadLibrary. if (do_search) { - strcpy (buf, "lib"); - offset = 3; + strcpy (buf, _Jv_platform_solib_prefix); + offset = strlen (_Jv_platform_solib_prefix); } -#endif jsize total = JvGetStringUTFRegion (path, 0, path->length(), &buf[offset]); buf[offset + total] = '\0'; + + char *lib_name = buf; + + if (do_search) + { + ClassLoader *sys = ClassLoader::getSystemClassLoader(); + ClassLoader *look = NULL; + gnu::gcj::runtime::StackTrace *t = new gnu::gcj::runtime::StackTrace(10); + for (int i = 0; i < 10; ++i) + { + jclass klass = t->classAt(i); + if (klass != NULL) + { + ClassLoader *loader = klass->getClassLoaderInternal(); + if (loader != NULL && loader != sys) + { + look = loader; + break; + } + } + } + if (look != NULL) + { + // Don't include solib prefix in string passed to + // findLibrary. + jstring name = look->findLibrary(JvNewStringUTF(&buf[offset])); + if (name != NULL) + { + len = _Jv_GetStringUTFLength (name); + lib_name = (char *) _Jv_AllocBytes(len + 1); + total = JvGetStringUTFRegion (name, 0, + name->length(), lib_name); + lib_name[total] = '\0'; + // Don't append suffixes any more; we have the full file + // name. + do_search = false; + } + } + } + lt_dlhandle h; // FIXME: make sure path is absolute. { @@ -180,7 +220,7 @@ java::lang::Runtime::_load (jstring path, jboolean do_search) // concurrent modification by class registration calls which may be run // during the dlopen(). JvSynchronize sync (&java::lang::Class::class$); - h = do_search ? lt_dlopenext (buf) : lt_dlopen (buf); + h = do_search ? lt_dlopenext (lib_name) : lt_dlopen (lib_name); } if (h == NULL) { @@ -602,19 +642,9 @@ java::lang::Runtime::nativeGetLibname (jstring pathname, jstring libname) #endif } - // FIXME: use platform function here. -#ifndef WIN32 - sb->append (JvNewStringLatin1 ("lib")); -#endif - + sb->append (JvNewStringLatin1 (_Jv_platform_solib_prefix)); sb->append(libname); - - // FIXME: use platform function here. -#ifdef WIN32 - sb->append (JvNewStringLatin1 ("dll")); -#else - sb->append (JvNewStringLatin1 ("so")); -#endif + sb->append (JvNewStringLatin1 (_Jv_platform_solib_suffix)); return sb->toString(); } |