Commit 3fd64b5a by Tom Tromey Committed by Tom Tromey

Runtime.java (_load): Declare.

	* java/lang/Runtime.java (_load): Declare.
	(load, loadLibrary): Wrote in terms of _load.
	* java/lang/natRuntime.cc (load): Call JNI_OnLoad if it appears in
	library.
	(loadLibrary): Likewise.
	Include <jni.h>.
	(_load): New method.
	(loadLibrary, load): Removed.

From-SVN: r31846
parent 278abd28
2000-02-07 Tom Tromey <tromey@cygnus.com> 2000-02-07 Tom Tromey <tromey@cygnus.com>
* java/lang/Runtime.java (_load): Declare.
(load, loadLibrary): Wrote in terms of _load.
* java/lang/natRuntime.cc (load): Call JNI_OnLoad if it appears in
library.
(loadLibrary): Likewise.
Include <jni.h>.
(_load): New method.
(loadLibrary, load): Removed.
* jni.cc (ThrowableClass): New define. * jni.cc (ThrowableClass): New define.
(_Jv_JNI_Throw): Check argument. (_Jv_JNI_Throw): Check argument.
(_Jv_JNI_ThrowNew): Likewise. (_Jv_JNI_ThrowNew): Likewise.
......
...@@ -23,8 +23,7 @@ import java.util.StringTokenizer; ...@@ -23,8 +23,7 @@ import java.util.StringTokenizer;
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1 * "The Java Language Specification", ISBN 0-201-63451-1
* plus online API docs for JDK 1.2 beta from http://www.javasoft.com. * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
* Status: All 1.1 methods exist. exec(), load(), and loadLibrary() * Status: All 1.1 methods exist. exec() is not fully implemented.
* are not fully implemented.
*/ */
public class Runtime public class Runtime
...@@ -94,8 +93,17 @@ public class Runtime ...@@ -94,8 +93,17 @@ public class Runtime
s.checkLink(lib); s.checkLink(lib);
} }
public native void load (String pathname); private native void _load (String pathname, boolean do_search);
public native void loadLibrary (String libname);
public void load (String pathname)
{
_load (pathname, false);
}
public void loadLibrary (String libname)
{
_load (libname, true);
}
// This is a helper function for the ClassLoader which can load // This is a helper function for the ClassLoader which can load
// compiled libraries. Returns true if library (which is just the // compiled libraries. Returns true if library (which is just the
......
...@@ -18,6 +18,8 @@ details. */ ...@@ -18,6 +18,8 @@ details. */
#include <java/lang/UnknownError.h> #include <java/lang/UnknownError.h>
#include <java/lang/UnsatisfiedLinkError.h> #include <java/lang/UnsatisfiedLinkError.h>
#include <jni.h>
#ifdef USE_LTDL #ifdef USE_LTDL
#include <ltdl.h> #include <ltdl.h>
...@@ -99,7 +101,7 @@ java::lang::Runtime::gc (void) ...@@ -99,7 +101,7 @@ java::lang::Runtime::gc (void)
} }
void void
java::lang::Runtime::load (jstring path) java::lang::Runtime::_load (jstring path, jboolean do_search)
{ {
JvSynchronize sync (this); JvSynchronize sync (this);
checkLink (path); checkLink (path);
...@@ -110,39 +112,29 @@ java::lang::Runtime::load (jstring path) ...@@ -110,39 +112,29 @@ java::lang::Runtime::load (jstring path)
jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
buf[total] = '\0'; buf[total] = '\0';
// FIXME: make sure path is absolute. // FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopen (buf); lt_dlhandle h = do_search ? lt_dlopenext (buf) : lt_dlopen (buf);
if (h == NULL) if (h == NULL)
{ {
const char *msg = lt_dlerror (); const char *msg = lt_dlerror ();
_Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg))); _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
} }
#else
_Jv_Throw (new UnknownError
(JvNewStringLatin1 ("Runtime.load not implemented")));
#endif /* USE_LTDL */
}
void void *onload = lt_dlsym (h, "JNI_OnLoad");
java::lang::Runtime::loadLibrary (jstring lib) if (onload != NULL)
{
JvSynchronize sync (this);
checkLink (lib);
using namespace java::lang;
#ifdef USE_LTDL
jint len = _Jv_GetStringUTFLength (lib);
char buf[len + 1];
jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
buf[total] = '\0';
// FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopenext (buf);
if (h == NULL)
{ {
const char *msg = lt_dlerror (); // FIXME: need invocation API to get JavaVM.
_Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg))); jint vers = ((jint (*) (...)) onload) (NULL, NULL);
if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2)
{
// FIXME: unload the library.
_Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 ("unrecognized version from JNI_OnLoad")));
}
} }
#else #else
_Jv_Throw (new UnknownError _Jv_Throw (new UnknownError
(JvNewStringLatin1 ("Runtime.loadLibrary not implemented"))); (JvNewStringLatin1 (do_search
? "Runtime.loadLibrary not implemented"
: "Runtime.load not implemented")));
#endif /* USE_LTDL */ #endif /* USE_LTDL */
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment