[Sablevm-developer] Patch for Runtime.nativeLoad()
Brought to you by:
egagnon
From: Archie C. <ar...@de...> - 2002-11-15 06:27:21
|
Here's a patch to fix a problem with Runtime.nativeLoad(). The problem is that if the dlopen() operation fails, the error message is lost. This caused me a lot of head scratching the other day trying to figure out why something wasn't working. With this patch the underlying error message (from lt_dlerror()) will appear in the Exception message string. Thanks, -Archie __________________________________________________________________________ Archie Cobbs * Packet Design * http://www.packetdesign.com --- sablevm-class-library-1.0.5/src/java/lang/Runtime.java.orig Thu Nov 14 16:52:41 2002 +++ sablevm-class-library-1.0.5/src/java/lang/Runtime.java Thu Nov 14 16:51:11 2002 @@ -629,8 +629,10 @@ SecurityManager sm = securityManager; // Be thread-safe! if (sm != null) sm.checkLink(filename); - if (nativeLoad(filename) == 0) - throw new UnsatisfiedLinkError("Could not load library " + filename); + String errmsg = nativeLoad(filename); + if (errmsg != null) + throw new UnsatisfiedLinkError("Could not load library " + filename + + ": " + errmsg); } /** @@ -747,9 +749,9 @@ * already been mapped to a true filename. * * @param filename the file to load - * @return 0 on failure, nonzero on success + * @return error message on failure, null on success */ - private native int nativeLoad(String filename); + private native String nativeLoad(String filename); /** * Map a system-independent "short name" to the full file name, and append --- sablevm-1.0.5/src/libsablevm/java_lang_Runtime.h.orig Thu Nov 14 17:08:12 2002 +++ sablevm-1.0.5/src/libsablevm/java_lang_Runtime.h Thu Nov 14 17:07:27 2002 @@ -93,9 +93,9 @@ /* * Class: java_lang_Runtime * Method: nativeLoad - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)Ljava/lang/String; */ - JNIEXPORT jint JNICALL Java_java_lang_Runtime_nativeLoad + JNIEXPORT jstring JNICALL Java_java_lang_Runtime_nativeLoad (JNIEnv *, jobject, jstring); /* --- sablevm-1.0.5/src/libsablevm/java_lang_Runtime.c.orig Thu Nov 14 16:56:03 2002 +++ sablevm-1.0.5/src/libsablevm/java_lang_Runtime.c Thu Nov 14 17:11:15 2002 @@ -166,16 +166,17 @@ /* * Class: java_lang_Runtime * Method: nativeLoad - * Signature: (Ljava/lang/String;)I + * Signature: (Ljava/lang/String;)Ljava/lang/String; */ -JNIEXPORT jint JNICALL +JNIEXPORT jstring JNICALL Java_java_lang_Runtime_nativeLoad (JNIEnv *_env, jobject this, jstring _filename) { _svmt_JNIEnv *env = _svmf_cast_svmt_JNIEnv (_env); _svmt_JavaVM *vm = env->vm; - jint result = 0; + const char *errmsg = "unknown error"; + jstring result = NULL; _svmf_resuming_java (env); @@ -207,6 +208,7 @@ if (handle == NULL) { + errmsg = lt_dlerror(); _svmm_gfree_utf_chars (filename); goto end; } @@ -215,7 +217,7 @@ { if (native_library->handle == handle) { - result = 1; + errmsg = NULL; _svmm_gfree_utf_chars (filename); goto end; } @@ -257,7 +259,7 @@ class_loader_info->native_library_list_tail = &(*(class_loader_info->native_library_list_tail))->next; - result = 1; + errmsg = NULL; end: @@ -272,6 +274,14 @@ { goto end; } + } + + if (errmsg != NULL) + { + /* as we do nothing else after, we can safely ignore the return + value (any exception being also set in the environment) */ + result = _svmf_get_jni_frame_native_local (env); + _svmf_get_string (env, errmsg, result); } } |