[libbluray-devel] bdj: unregister native functions at close

hpi1 git at videolan.org
Wed Feb 26 09:22:48 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Feb 25 15:14:38 2014 +0200| [af991675912b31f176a72e5a57856236d0022e93] | committer: hpi1

bdj: unregister native functions at close

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=af991675912b31f176a72e5a57856236d0022e93
---

 src/libbluray/bdj/bdj.c                    |    2 ++
 src/libbluray/bdj/bdj_util.c               |   32 ++++++++++++++++++++++++++++
 src/libbluray/bdj/bdj_util.h               |    1 +
 src/libbluray/bdj/native/register_native.c |    8 +++++++
 src/libbluray/bdj/native/register_native.h |    1 +
 5 files changed, 44 insertions(+)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 842950c..83b6790 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -491,6 +491,8 @@ void bdj_close(BDJAVA *bdjava)
             (*env)->DeleteLocalRef(env, shutdown_class);
         }
 
+        bdj_unregister_native_methods(env);
+
         if (attach) {
             (*bdjava->jvm)->DetachCurrentThread(bdjava->jvm);
         }
diff --git a/src/libbluray/bdj/bdj_util.c b/src/libbluray/bdj/bdj_util.c
index c1b7fb1..35178e0 100644
--- a/src/libbluray/bdj/bdj_util.c
+++ b/src/libbluray/bdj/bdj_util.c
@@ -104,3 +104,35 @@ int bdj_register_methods(JNIEnv *env, const char *class_name,
 
     return !error;
 }
+
+int bdj_unregister_methods(JNIEnv *env, const char *class_name)
+{
+    jclass cls;
+    int error;
+
+    (*env)->ExceptionClear(env);
+
+    cls = (*env)->FindClass(env, class_name);
+
+    if (!cls) {
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to locate class %s\n", class_name);
+        (*env)->ExceptionDescribe(env);
+        (*env)->ExceptionClear(env);
+        return 0;
+    }
+
+    error =  (*env)->UnregisterNatives(env, cls);
+
+    if ((*env)->ExceptionOccurred(env)) {
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to unregister native methods for class %s\n", class_name);
+        (*env)->ExceptionDescribe(env);
+        (*env)->ExceptionClear(env);
+        return 0;
+    }
+
+    if (error) {
+        BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to runegister native methods for class %s\n", class_name);
+    }
+
+    return !error;
+}
diff --git a/src/libbluray/bdj/bdj_util.h b/src/libbluray/bdj/bdj_util.h
index fa28188..25fd64a 100644
--- a/src/libbluray/bdj/bdj_util.h
+++ b/src/libbluray/bdj/bdj_util.h
@@ -38,5 +38,6 @@ BD_PRIVATE int bdj_get_method(JNIEnv *env, jclass *cls, jmethodID *method_id,
 // register native methods for class
 BD_PRIVATE int bdj_register_methods(JNIEnv *env, const char *class_name,
                                     const JNINativeMethod *methods, int methods_count);
+BD_PRIVATE int bdj_unregister_methods(JNIEnv *env, const char *class_name);
 
 #endif
diff --git a/src/libbluray/bdj/native/register_native.c b/src/libbluray/bdj/native/register_native.c
index 5803d56..18e72ce 100644
--- a/src/libbluray/bdj/native/register_native.c
+++ b/src/libbluray/bdj/native/register_native.c
@@ -51,3 +51,11 @@ int bdj_register_native_methods(JNIEnv *env)
                            Java_java_awt_BDGraphics_methods_count)
       ;
 }
+
+void bdj_unregister_native_methods(JNIEnv *env)
+{
+    bdj_unregister_methods(env, "java/awt/BDGraphics");
+    bdj_unregister_methods(env, "java/awt/BDFontMetrics");
+    bdj_unregister_methods(env, "org/videolan/Libbluray");
+    bdj_unregister_methods(env, "org/videolan/Logger");
+}
diff --git a/src/libbluray/bdj/native/register_native.h b/src/libbluray/bdj/native/register_native.h
index d326598..1077384 100644
--- a/src/libbluray/bdj/native/register_native.h
+++ b/src/libbluray/bdj/native/register_native.h
@@ -25,5 +25,6 @@
 #include <jni.h>
 
 BD_PRIVATE int bdj_register_native_methods(JNIEnv *env);
+BD_PRIVATE void bdj_unregister_native_methods(JNIEnv *env);
 
 #endif /* _REGISTER_NATIVE_H_ */



More information about the libbluray-devel mailing list