This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: gtk peer - jni fix
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 21 Apr 2004 09:20:09 +0200
- Subject: Patch: gtk peer - jni fix
Hi list,
I just commited the attached patch to merge a fix for JNI.
Michael
2004-04-21 Mark Wielaard <mark@klomp.org>
* native/jni/gtk-peer/gthread-jni.c (maybe_rethrow): Explicitly
malloc and free buf.
Index: jni/gtk-peer/gthread-jni.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gthread-jni.c,v
retrieving revision 1.4
diff -u -r1.4 gthread-jni.c
--- jni/gtk-peer/gthread-jni.c 21 Apr 2004 06:52:26 -0000 1.4
+++ jni/gtk-peer/gthread-jni.c 21 Apr 2004 07:05:59 -0000
@@ -91,28 +91,40 @@
static void maybe_rethrow(JNIEnv *gdk_env, char *message, char *file, int line) {
jthrowable cause;
- /* rethrow if an exception happened */
- if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL) {
jstring jmessage;
- jclass obj_class;
+ jclass obj_class;
jobject obj;
jmethodID ctor;
+ int len;
+ char *buf;
- /* allocate local message in Java */
- int len = strlen(message) + strlen(file) + 25;
- char buf[ len ];
- bzero(buf, len);
- sprintf(buf, "%s (at %s:%d)", message, file, line);
- jmessage = (*gdk_env)->NewStringUTF(gdk_env, buf);
+ /* rethrow if an exception happened */
+ if ((cause = (*gdk_env)->ExceptionOccurred(gdk_env)) != NULL)
+ {
+
+ /* allocate local message in Java */
+ len = strlen(message) + strlen(file) + 25;
+ buf = (char *) malloc(len);
+ if (buf != NULL)
+ {
+ bzero(buf, len);
+ sprintf(buf, "%s (at %s:%d)", message, file, line);
+ jmessage = (*gdk_env)->NewStringUTF(gdk_env, buf);
+ free(buf);
+ }
+ else
+ jmessage = NULL;
- /* create RuntimeException wrapper object */
- obj_class = (*gdk_env)->FindClass (gdk_env, "java/lang/RuntimeException");
- ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>", "(Ljava/langString;Ljava/lang/Throwable)V");
- obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause);
+ /* create RuntimeException wrapper object */
+ obj_class = (*gdk_env)->FindClass (gdk_env,
+ "java/lang/RuntimeException");
+ ctor = (*gdk_env)->GetMethodID(gdk_env, obj_class, "<init>",
+ "(Ljava/langString;Ljava/lang/Throwable)V");
+ obj = (*gdk_env)->NewObject (gdk_env, obj_class, ctor, jmessage, cause);
- /* throw it */
- (*gdk_env)->Throw(gdk_env, (jthrowable)obj);
- }
+ /* throw it */
+ (*gdk_env)->Throw(gdk_env, (jthrowable)obj);
+ }
}
/* This macro is used to include a source location in the exception message */