From: ishmal Date: Wed, 12 Mar 2008 19:55:00 +0000 (+0000) Subject: Split getException into method and function, so it can be used in native functions. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=16dbc2190f077af19da9778f98a2140e96b009e5;p=inkscape.git Split getException into method and function, so it can be used in native functions. --- diff --git a/src/bind/dobinding.cpp b/src/bind/dobinding.cpp index 29d61b722..e2157de0b 100644 --- a/src/bind/dobinding.cpp +++ b/src/bind/dobinding.cpp @@ -74,6 +74,11 @@ typedef struct static jlong getPointer(JNIEnv *env, jobject obj) { jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); + if (!id) + { + err("getPointer: %s", getException(env).c_str()); + return 0; + } jlong val = env->GetLongField(obj, id); return val; } @@ -81,9 +86,49 @@ static jlong getPointer(JNIEnv *env, jobject obj) static void setPointer(JNIEnv *env, jobject obj, jlong val) { jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); + if (!id) + { + err("setPointer: %s", getException(env).c_str()); + return; + } env->SetLongField(obj, id, val); } +static void JNICALL BaseObject_construct + (JNIEnv *env, jobject obj) +{ + setPointer(env, obj, 0L); +} + +static void JNICALL BaseObject_destruct + (JNIEnv *env, jobject obj) +{ + NodePtr *ptr = (NodePtr *)getPointer(env, obj); + if (ptr) + { + delete ptr; + } + setPointer(env, obj, 0L); +} + + +static JNINativeMethod nm_BaseObject[] = +{ +{ (char *)"construct", (char *)"()V", (void *)BaseObject_construct }, +{ (char *)"destruct", (char *)"()V", (void *)BaseObject_destruct }, +{ NULL, NULL, NULL } +}; + +static NativeClass nc_BaseObject = +{ + "org/inkscape/cmn/BaseObject", + nm_BaseObject +}; + +//######################################################################## +//# BASE OBJECT +//######################################################################## + static void JNICALL DOMBase_construct (JNIEnv *env, jobject obj) { @@ -114,6 +159,8 @@ static NativeClass nc_DOMBase = "org/inkscape/dom/DOMBase", nm_DOMBase }; + + //######################################################################## //# DOMImplementation //######################################################################## @@ -157,6 +204,7 @@ static NativeClass nc_DOMImplementation = */ static NativeClass *allClasses[] = { + &nc_BaseObject, &nc_DOMBase, &nc_DOMImplementation, NULL diff --git a/src/bind/javabind-private.h b/src/bind/javabind-private.h index 5a810480b..c4dbd5e9a 100644 --- a/src/bind/javabind-private.h +++ b/src/bind/javabind-private.h @@ -91,6 +91,13 @@ void msg(const char *fmt, ...); //# UTILITY //######################################################################## +String normalizePath(const String &str); + +String getExceptionString(JNIEnv *env); + +String getException(JNIEnv *env) + { return getExceptionString(env); } + jint getInt(JNIEnv *env, jobject obj, const char *name); void setInt(JNIEnv *env, jobject obj, const char *name, jint val); diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp index b03d562ce..1424a527b 100644 --- a/src/bind/javabind.cpp +++ b/src/bind/javabind.cpp @@ -102,6 +102,21 @@ String normalizePath(const String &str) return buf; } +String getExceptionString(JNIEnv *env) +{ + String buf; + jthrowable exc = env->ExceptionOccurred(); + if (!exc) + return buf; + jclass cls = env->GetObjectClass(exc); + jmethodID mid = env->GetMethodID(cls, "toString", "()Ljava/lang/String;"); + jstring jstr = (jstring) env->CallObjectMethod(exc, mid); + const char *str = env->GetStringUTFChars(jstr, JNI_FALSE); + buf.append(str); + env->ReleaseStringUTFChars(jstr, str); + env->ExceptionClear(); + return buf; +} jint getInt(JNIEnv *env, jobject obj, const char *name) { @@ -901,6 +916,7 @@ bool JavaBinderyImpl::callStatic(int type, + /** * Fetch the last exception from the JVM, if any. Clear it to * continue processing @@ -909,18 +925,7 @@ bool JavaBinderyImpl::callStatic(int type, */ String JavaBinderyImpl::getException() { - String buf; - jthrowable exc = env->ExceptionOccurred(); - if (!exc) - return buf; - jclass cls = env->GetObjectClass(exc); - jmethodID mid = env->GetMethodID(cls, "toString", "()Ljava/lang/String;"); - jstring jstr = (jstring) env->CallObjectMethod(exc, mid); - const char *str = env->GetStringUTFChars(jstr, JNI_FALSE); - buf.append(str); - env->ReleaseStringUTFChars(jstr, str); - env->ExceptionClear(); - return buf; + return getExceptionString(env); }