]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Consolidate triplicated xDestroy()-calling code. Remove some unnecessary casts.
authorstephan <stephan@noemail.net>
Mon, 31 Jul 2023 07:15:25 +0000 (07:15 +0000)
committerstephan <stephan@noemail.net>
Mon, 31 Jul 2023 07:15:25 +0000 (07:15 +0000)
FossilOrigin-Name: 24c0763d0e025187c74002ffee11fd48d3cd7b40e01469d28484bb67f701884b

ext/jni/src/c/sqlite3-jni.c
manifest
manifest.uuid

index bf5118bf644cb1af93d06332013855ba95de2885..c9f3b1df50876040e23d4880d9244e70b9cfb89b 100644 (file)
@@ -454,17 +454,22 @@ static int s3jni_db_error(sqlite3*db, int err_code, const char *zMsg){
 }
 
 /**
-   Clears s's state, releasing any Java references. Before doing so,
-   it calls s's xDestroy() method, ignoring the lack of that method or
-   any exceptions it throws. This is a no-op of s has no current
-   state.
+   Extracts the (void xDestroy()) method from the given jclass and
+   applies it to jobj. If jobs is NULL, this is a no-op. If klazz is
+   NULL then it's derived from jobj. The lack of an xDestroy() method
+   is silently ignored and any exceptions thrown by the method trigger
+   a warning to stdout or stderr and then the exception is suppressed.
 */
-static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){
-  if(s->base.jObj){
-    const jmethodID method =
-      (*env)->GetMethodID(env, s->klazz, "xDestroy", "()V");
+static void s3jni_call_xDestroy(JNIEnv *env, jobject jobj, jclass klazz){
+  if(jobj){
+    jmethodID method;
+    if(!klazz){
+      klazz = (*env)->GetObjectClass(env, jobj);
+      assert(klazz);
+    }
+    method = (*env)->GetMethodID(env, klazz, "xDestroy", "()V");
     if(method){
-      (*env)->CallVoidMethod(env, s->base.jObj, method);
+      (*env)->CallVoidMethod(env, jobj, method);
       IFTHREW{
         EXCEPTION_WARN_CALLBACK_THREW;
         EXCEPTION_CLEAR;
@@ -472,6 +477,19 @@ static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){
     }else{
       EXCEPTION_CLEAR;
     }
+  }
+}
+
+
+/**
+   Clears s's state, releasing any Java references. Before doing so,
+   it calls s's xDestroy() method, ignoring the lack of that method or
+   any exceptions it throws. This is a no-op of s has no current
+   state.
+*/
+static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){
+  if(s->base.jObj){
+    s3jni_call_xDestroy(env, s->base.jObj, s->klazz);
     UNREF_G(s->base.jObj);
     UNREF_G(s->klazz);
     memset(s, 0, sizeof(BusyHandlerJni));
@@ -909,19 +927,19 @@ static CollationState * CollationState_alloc(void){
   return rc;
 }
 
-static void CollationState_free(CollationState * cs){
+static void CollationState_free(CollationState * const cs){
   JNIEnv * const env = cs->env;
   if(env){
     //MARKER(("Collation cleanup...\n"));
-    if(cs->oCollation) UNREF_G(cs->oCollation);
-    if(cs->klazz) UNREF_G(cs->klazz);
+    UNREF_G(cs->oCollation);
+    UNREF_G(cs->klazz);
   }
   sqlite3_free(cs);
 }
 
-static int collation_xCompare_proxy(void *pArg, int nLhs, const void *lhs,
-                                    int nRhs, const void *rhs){
-  CollationState * const cs = (CollationState*)pArg;
+static int CollationState_xCompare(void *pArg, int nLhs, const void *lhs,
+                                   int nRhs, const void *rhs){
+  CollationState * const cs = pArg;
   JNIEnv * env = cs->env;
   jint rc;
   jbyteArray jbaLhs = (*env)->NewByteArray(env, (jint)nLhs);
@@ -937,20 +955,10 @@ static int collation_xCompare_proxy(void *pArg, int nLhs, const void *lhs,
   return (int)rc;
 }
 
-static void collation_xDestroy_proxy(void *pArg){
-  CollationState * const cs = (CollationState*)pArg;
-  if(cs->oCollation){
-    JNIEnv * const env = cs->env;
-    const jmethodID method = (*env)->GetMethodID(env, cs->klazz, "xDestroy",
-                                                 "()V");
-    //MARKER(("Calling Collation.xDestroy()...\n"));
-    (*env)->CallVoidMethod(env, cs->oCollation, method);
-    IFTHREW {
-      EXCEPTION_WARN_CALLBACK_THREW;
-      EXCEPTION_CLEAR;
-    }
-    //MARKER(("Returned from Collation.xDestroy().\n"));
-  }
+/* Collation finalizer for use by the sqlite3 internals. */
+static void CollationState_xDestroy(void *pArg){
+  CollationState * const cs = pArg;
+  s3jni_call_xDestroy(cs->env, cs->oCollation, cs->klazz);
   CollationState_free(cs);
 }
 
@@ -1132,19 +1140,8 @@ static UDFState * UDFState_alloc(JNIEnv *env, jobject jObj){
 static void UDFState_free(UDFState * s){
   JNIEnv * const env = s->env;
   if(env){
-    //MARKER(("Collation cleanup...\n"));
-    if(s->jObj){
-      const jmethodID method =
-        (*env)->GetMethodID(env, s->klazz, "xDestroy", "()V");
-      if(method){
-        //MARKER(("aCalling SQLFunction.xDestroy()...\n"));
-        (*env)->CallVoidMethod(env, s->jObj, method);
-        EXCEPTION_IGNORE;
-        //MARKER(("Returned from SQLFunction.xDestroy().\n"));
-      }else{
-        (*env)->ExceptionClear(env);
-      }
-    }
+    //MARKER(("UDF cleanup...\n"));
+    s3jni_call_xDestroy(env, s->jObj, s->klazz);
     UNREF_G(s->jObj);
     UNREF_G(s->klazz);
   }
@@ -1734,10 +1731,10 @@ JDECL(jint,1create_1collation)(JENV_JSELF, jobject jpDb,
                                     "([B[B)I");
   zName = JSTR_TOC(name);
   rc = sqlite3_create_collation_v2(PtrGet_sqlite3(jpDb), zName, (int)eTextRep,
-                                   cs, collation_xCompare_proxy,
-                                   collation_xDestroy_proxy);
+                                   cs, CollationState_xCompare,
+                                   CollationState_xDestroy);
   JSTR_RELEASE(name, zName);
-  if(0 != rc) collation_xDestroy_proxy(cs);
+  if(0 != rc) CollationState_xDestroy(cs);
   return (jint)rc;
 }
 
index 795dd4ed3186abe4f3f87275574996ba3eb0e147..4aa0d7abb893bf97b04bcef30714facdc412e828 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Internal\sJNI\sAPI\srenaming.
-D 2023-07-30T18:41:25.803
+C Consolidate\striplicated\sxDestroy()-calling\scode.\sRemove\ssome\sunnecessary\scasts.
+D 2023-07-31T07:15:25.615
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -232,7 +232,7 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
 F ext/jni/GNUmakefile 56a014dbff9516774d895ec1ae9df0ed442765b556f79a0fc0b5bc438217200d
 F ext/jni/README.md c0e6e80935e7761acead89b69c87765b23a6bcb2858c321c3d05681fd338292a
-F ext/jni/src/c/sqlite3-jni.c e1dc9820a9a68fad2d06e15022e4288817a29ca83bf804e3926985115f1f1a1d
+F ext/jni/src/c/sqlite3-jni.c 2d61ba074e851ad010307fd901581030a3f234771c266306ff9ccf33ae1a5542
 F ext/jni/src/c/sqlite3-jni.h 28def286ee305c1c89a43ac5918a6862d985d0534f7ccbbd74df4885d3918b73
 F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c
 F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1
@@ -2071,8 +2071,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 120983a570d6de055cef9d916096de3410897ea9f46d23ea6eff1f9b549e423a
-R 6a2910fdd19645a78e675ea1b5f3006c
+P fcfc070673cef2f657f4737f096678439ed7c011fb2e5391e0721f82f5d8af51
+R cfdb6b4bc4a7852f0b4b2fc4d64b3f33
 U stephan
-Z 307d46c1a84b2aab03be2e0da79180c9
+Z 7456fbe378da7eba9d869800225a0ec8
 # Remove this line to create a well-formed Fossil manifest.
index 68ed83bbaa21bec2de3ac7cf30174f94c8b39aaf..5d723d64c82876924391272944709537226072d1 100644 (file)
@@ -1 +1 @@
-fcfc070673cef2f657f4737f096678439ed7c011fb2e5391e0721f82f5d8af51
\ No newline at end of file
+24c0763d0e025187c74002ffee11fd48d3cd7b40e01469d28484bb67f701884b
\ No newline at end of file