diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2008-08-05 14:53:12 +0000 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2008-08-05 14:53:12 +0000 |
commit | 9406c648c5bb08ec048bee4d48976220cb3c47a4 (patch) | |
tree | 68207ed2518264fe730dad314ef6ddbf6c9e0cd5 /bindings | |
parent | d61eb5307089c0dec8feca03af08316d2b273b10 (diff) | |
download | lasso-9406c648c5bb08ec048bee4d48976220cb3c47a4.tar.gz lasso-9406c648c5bb08ec048bee4d48976220cb3c47a4.tar.xz lasso-9406c648c5bb08ec048bee4d48976220cb3c47a4.zip |
use new util function to throw exceptions
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/java/lang.py | 4 | ||||
-rw-r--r-- | bindings/java/wrapper_top.c | 19 |
2 files changed, 18 insertions, 5 deletions
diff --git a/bindings/java/lang.py b/bindings/java/lang.py index 044e468e..e517ed21 100644 --- a/bindings/java/lang.py +++ b/bindings/java/lang.py @@ -568,7 +568,7 @@ protected static native void destroy(long cptr); print >> fd, ' if (gobj) {' print >> fd, ' %s;' % self.c_to_java_value ('ret','gobj->%s' % m[1], mtype, m[2]) print >> fd, ' } else {' - print >> fd, ' (*env)->ThrowNew(env, "java/lang/NullPointerException", "no gobject correspond to the given object");' + print >> fd, ' throw_by_name(env, "java/lang/NullPointerException", "no gobject correspond to the given object");' print >> fd, ' }' print >> fd, ' return ret;' print >> fd, '}' @@ -582,7 +582,7 @@ protected static native void destroy(long cptr); print >> fd, ' printf("%s_set %%p %%p\\n", gobj, value);' % prefix print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);' print >> fd, ' if (!gobj) {' - print >> fd, ' (*env)->ThrowNew(env, "java/lang/NullPointerException", "no gobject correspond to the given object");' + print >> fd, ' throw_by_name(env, "java/lang/NullPointerException", "no gobject correspond to the given object");' print >> fd, ' }' if not self.is_int_type(mtype) and not is_collection(mtype): print >> fd, ' if (gobj->%s) {' % m[1] diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c index 03736866..191c14f5 100644 --- a/bindings/java/wrapper_top.c +++ b/bindings/java/wrapper_top.c @@ -41,7 +41,7 @@ static int gobject_to_jobject(JNIEnv *env, GObject *obj, jobject *jobj); static int gobject_to_jobject_and_ref(JNIEnv *env, GObject *obj, jobject *jobj); static int jobject_to_gobject(JNIEnv *env, jobject obj, GObject **gobj); -static int jobject_to_gobject_for_list(JNIEnv *env, jobject *obj, GObject **gobj); +static int jobject_to_gobject_for_list(JNIEnv *env, jobject obj, GObject **gobj); static void free_glist(GList **list, GFunc free_function); static int get_list(JNIEnv *env, char *clsName, GList *list, Converter convert, jobjectArray *jarr); static int set_list(JNIEnv *env, GList **list, jobjectArray jarr, GFunc free_function, OutConverter convert); @@ -75,6 +75,7 @@ static int get_hash_by_name(JNIEnv *env, GHashTable *hashtable, jstring jkey, Co #define add_to_hash_of_objects(env,hash,key,obj) add_to_hash(env,hash,key,obj,(OutConverter)jobject_to_gobject_for_list,(GFunc)g_object_unref) //#define get_hash_of_strings_by_name(end,hash,key) get_hash_by_name(end,hash,key,(Converter)string_to_jstring) //#define get_hash_of_objects_by_name(end,hash,key) get_hash_by_name(end,hash,key,(Converter)gobject_to_jobject_and_ref) +static void throw_by_name(JNIEnv *env, const char *name, const char *msg); static int @@ -219,7 +220,7 @@ static void exception(JNIEnv *env, char *message) { jclass cls = (*env)->FindClass(env, "java/lang/RuntimeException"); if (cls != NULL) { - (*env)->ThrowNew(env, "java/lang/RuntimeException", message); + throw_by_name(env, "java/lang/RuntimeException", message); } (*env)->DeleteLocalRef(env, cls); } @@ -432,7 +433,7 @@ jobject_to_gobject(JNIEnv *env, jobject obj, GObject **gobj) { /** Get the gobject encapsulated by the java object obj and increase its ref count. The only * use for this function is composed with set_list_of_objects or set_hash_of_object. */ static int -jobject_to_gobject_for_list(JNIEnv *env, jobject *obj, GObject **gobj) { +jobject_to_gobject_for_list(JNIEnv *env, jobject obj, GObject **gobj) { g_return_val_if_fail(jobject_to_gobject(env, obj, gobj), 0); if (*gobj) { g_object_ref(*gobj); @@ -765,6 +766,18 @@ get_hash_by_name(JNIEnv *env, GHashTable *hashtable, jstring jkey, Converter con release_local_string(env, jkey, key); return convert(env, value, jvalue); } +static void +throw_by_name(JNIEnv *env, const char *name, const char *msg) +{ + jclass cls = (*env)->FindClass(env, name); + /* if cls is NULL, an exception has already been thrown */ + if (cls != NULL) { + (*env)->ThrowNew(env, cls, msg); + } + /* free the local ref */ + (*env)->DeleteLocalRef(env, cls); +} + /* JNI Functions */ JNIEXPORT void JNICALL Java_com_entrouvert_lasso_LassoJNI_init2(JNIEnv *env, jclass cls) { |