From bff2e9181f3abac5f946b0252ba9906cd167f764 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 10 Nov 2008 18:02:02 +0000 Subject: [PATCH] in-progress patch --- jna-callback-exception.patch | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 jna-callback-exception.patch diff --git a/jna-callback-exception.patch b/jna-callback-exception.patch new file mode 100644 index 0000000..d870f70 --- /dev/null +++ b/jna-callback-exception.patch @@ -0,0 +1,57 @@ +diff -ur jna-3.0.4-svn729/native/callback.c jna-3.0.4-svn729.orig/native/callback.c +--- jna-3.0.4-svn729/native/callback.c 2008-09-07 13:32:02.000000000 -0400 ++++ jna-3.0.4-svn729.orig/native/callback.c 2008-10-21 00:05:24.000000000 -0400 +@@ -119,6 +119,42 @@ + } + + static void ++call_thread_uncaught(JNIEnv *env) ++{ ++ jthrowable e; ++ jclass threadCls; ++ jclass handlerCls; ++ jmethodID mid; ++ jobject threadObj; ++ jobject handler; ++ ++ /* Get the exception */ ++ e = (*env)->ExceptionOccurred(env); ++ ++ /* Now clear it from JNI's point of view, holding our ref to it */ ++ (*env)->ExceptionClear(env); ++ ++ threadCls = (*env)->FindClass(env, "java/lang/Thread"); ++ if (threadCls == NULL) ++ return; ++ ++ mid = (*env)->GetMethodID(env, threadCls, "getCurrentThread", ++ "()Ljava/lang/Thread;"); ++ threadObj = (*env)->CallStaticObjectMethod(env, threadCls, mid); ++ mid = (*env)->GetMethodID(env, threadCls, "getUncaughtExceptionHandler", ++ "()Ljava/lang/Thread$UncaughtExceptionHandler;"); ++ handler = (*env)->CallObjectMethod(env, threadObj, mid); ++ if (handler == NULL) ++ return; ++ ++ handlerCls = (*env)->GetObjectClass(env, handler); ++ mid = (*env)->GetMethodID(env, handlerCls, "uncaughtException", ++ "(Ljava/lang/Thread;Ljava/lang/Throwable;)V"); ++ ++ (*env)->CallObjectMethod(env, handler, mid, threadObj, e); ++} ++ ++static void + callback_invoke(JNIEnv* env, callback *cb, ffi_cif* cif, void *resp, void **cbargs) { + jobject self; + +@@ -140,7 +176,8 @@ + } + result = (*env)->CallObjectMethod(env, self, cb->methodID, array); + if ((*env)->ExceptionCheck(env)) { +- fprintf(stderr, "JNA: uncaught exception in callback, continuing\n"); ++ /* Toss it over to the current thread's uncaught handler */ ++ call_thread_uncaught(env); + memset(resp, 0, cif->rtype->size); + } + else { +Only in jna-3.0.4-svn729.orig/native: callback.c~