rpms/jna/devel jna-callback-exception.patch,NONE,1.1

Colin Walters walters at fedoraproject.org
Mon Nov 10 18:02:02 UTC 2008


Author: walters

Update of /cvs/pkgs/rpms/jna/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv4282

Added Files:
	jna-callback-exception.patch 
Log Message:
in-progress patch

jna-callback-exception.patch:

--- NEW FILE jna-callback-exception.patch ---
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~




More information about the fedora-extras-commits mailing list