]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Remove the Java BusyHandler.xDestroy() method - it should not have had one. Eliminate...
authorstephan <stephan@noemail.net>
Sat, 26 Aug 2023 10:51:19 +0000 (10:51 +0000)
committerstephan <stephan@noemail.net>
Sat, 26 Aug 2023 10:51:19 +0000 (10:51 +0000)
FossilOrigin-Name: c852f1ebbde273c3d28fe5aff0bf73cfc06b41dd371a94d7520536dc7a1dbcc1

ext/jni/src/c/sqlite3-jni.c
ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java
ext/jni/src/org/sqlite/jni/Tester1.java
manifest
manifest.uuid

index 45813e63bb464e85f60890fd740c45476cc28127..1446992c95c0c78061748bd333de7e507ca0d749 100644 (file)
@@ -997,7 +997,7 @@ static void S3JniDb_set_aside_unlocked(JNIEnv * env, S3JniDb * const s){
     sqlite3_free( s->zMainDbName );
 #define UNHOOK(MEMBER,XDESTROY) S3JniHook_unref(env, &s->hooks.MEMBER, XDESTROY)
     UNHOOK(auth, 0);
-    UNHOOK(busyHandler, 1);
+    UNHOOK(busyHandler, 0);
     UNHOOK(collation, 1);
     UNHOOK(collationNeeded, 0);
     UNHOOK(commit, 0);
@@ -2121,7 +2121,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)(
       return 0;
     }
     jclass klazz;
-    S3JniHook_unref(env, pHook, 1);
+    S3JniHook_unref(env, pHook, 0);
     pHook->jObj = S3JniRefGlobal(jBusy);
     klazz = (*env)->GetObjectClass(env, jBusy);
     pHook->midCallback = (*env)->GetMethodID(env, klazz, "call", "(I)I");
@@ -2131,7 +2131,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)(
       rc = SQLITE_ERROR;
     }
   }else{
-    S3JniHook_unref(env, pHook, 1);
+    S3JniHook_unref(env, pHook, 0);
   }
   if( 0==rc ){
     rc = jBusy
@@ -2146,11 +2146,14 @@ S3JniApi(sqlite3_busy_timeout(),jint,1busy_1timeout)(
   JniArgsEnvClass, jobject jDb, jint ms
 ){
   S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0);
+  int rc = SQLITE_MISUSE;
   if( ps ){
-    S3JniHook_unref(env, &ps->hooks.busyHandler, 1);
-    return sqlite3_busy_timeout(ps->pDb, (int)ms);
+    S3JniMutex_S3JniDb_enter;
+    S3JniHook_unref(env, &ps->hooks.busyHandler, 0);
+    rc = sqlite3_busy_timeout(ps->pDb, (int)ms);
+    S3JniMutex_S3JniDb_leave;
   }
-  return SQLITE_MISUSE;
+  return rc;
 }
 
 S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)(
@@ -2551,7 +2554,6 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(),
 )(JniArgsEnvClass, jobject jDb, jstring name, jint eTextRep,
   jobject oCollation){
   int rc;
-  const char *zName;
   jclass klazz;
   S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0);
   jmethodID midCallback;
@@ -2565,17 +2567,21 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(),
     rc = s3jni_db_error(ps->pDb, SQLITE_ERROR,
                         "Could not get xCompare() method for object.");
   }else{
-    zName = s3jni_jstring_to_mutf8(name);
-    rc = sqlite3_create_collation_v2(ps->pDb, zName, (int)eTextRep,
-                                     ps, CollationState_xCompare,
-                                     CollationState_xDestroy);
-    s3jni_mutf8_release(name, zName);
-    if( 0==rc ){
+    char * const zName = s3jni_jstring_to_utf8(env, name, 0);
+    if( zName ){
       S3JniMutex_S3JniDb_enter;
-      S3JniHook_unref( env, &ps->hooks.collation, 1 );
-      ps->hooks.collation.midCallback = midCallback;
-      ps->hooks.collation.jObj = S3JniRefGlobal(oCollation);
+      rc = sqlite3_create_collation_v2(ps->pDb, zName, (int)eTextRep,
+                                       ps, CollationState_xCompare,
+                                       CollationState_xDestroy);
+      sqlite3_free(zName);
+      if( 0==rc ){
+        S3JniHook_unref( env, &ps->hooks.collation, 1 );
+        ps->hooks.collation.midCallback = midCallback;
+        ps->hooks.collation.jObj = S3JniRefGlobal(oCollation);
+      }
       S3JniMutex_S3JniDb_leave;
+    }else{
+      rc = SQLITE_NOMEM;
     }
   }
   return (jint)rc;
@@ -2627,9 +2633,9 @@ S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() sqlite3_create_w
                                     xFunc, xStep, xFinal, S3JniUdf_finalizer);
   }
 error_cleanup:
+  /* Reminder: on sqlite3_create_function() error, s will be
+  ** destroyed via create_function(). */
   sqlite3_free(zFuncName);
-  /* on sqlite3_create_function() error, s will be destroyed via
-  ** create_function(), so we're not leaking s. */
   return (jint)rc;
 }
 
@@ -4228,11 +4234,11 @@ JniDeclFtsApi(jint,xCreateFunction)(JniArgsEnvObj, jstring jName,
                                   jobject jUserData, jobject jFunc){
   fts5_api * const pApi = PtrGet_fts5_api(jSelf);
   int rc;
-  char const * zName;
+  char * zName;
   Fts5JniAux * pAux;
 
   assert(pApi);
-  zName = s3jni_jstring_to_mutf8(jName);
+  zName = s3jni_jstring_to_utf8(env, jName, 0);
   if(!zName) return SQLITE_NOMEM;
   pAux = Fts5JniAux_alloc(env, jFunc);
   if( pAux ){
@@ -4244,10 +4250,10 @@ JniDeclFtsApi(jint,xCreateFunction)(JniArgsEnvObj, jstring jName,
   }
   if( 0==rc ){
     pAux->jUserData = jUserData ? S3JniRefGlobal(jUserData) : 0;
-    pAux->zFuncName = sqlite3_mprintf("%s", zName)
-      /* OOM here is non-fatal. Ignore it. */;
+    pAux->zFuncName = zName;
+  }else{
+    sqlite3_free(zName);
   }
-  s3jni_mutf8_release(jName, zName);
   return (jint)rc;
 }
 
index e8740865e46473e95204c95edcfb218767bd322c..77180e2c245a936f3da31003e790f534dfde8ead 100644 (file)
@@ -17,8 +17,7 @@ package org.sqlite.jni;
 /**
    Callback for use with sqlite3_busy_handler()
 */
-public abstract class BusyHandlerCallback
-  implements SQLite3CallbackProxy, XDestroyCallback {
+public abstract class BusyHandlerCallback implements SQLite3CallbackProxy {
   /**
      Must function as documented for the C-level
      sqlite3_busy_handler() callback argument, minus the (void*)
@@ -28,20 +27,4 @@ public abstract class BusyHandlerCallback
      retain the C-style API semantics of the JNI bindings.
   */
   public abstract int call(int n);
-
-  /**
-     Optionally override to perform any cleanup when this busy
-     handler is destroyed. It is destroyed when:
-
-     - The associated db is passed to sqlite3_close() or
-     sqlite3_close_v2().
-
-     - sqlite3_busy_handler() is called to replace the handler,
-     whether it's passed a null handler or any other instance of
-     this class.
-
-     - sqlite3_busy_timeout() is called, which implicitly installs
-     a busy handler.
-  */
-  public void xDestroy(){}
 }
index 5d3712f2d6e15e97ae663644a65c87b32247c4a0..bd585528cc247211e8d86e6320721b940c1a797c 100644 (file)
@@ -940,31 +940,24 @@ public class Tester1 implements Runnable {
     rc = sqlite3_db_config(db1, SQLITE_DBCONFIG_MAINDBNAME, "foo");
     affirm( sqlite3_db_filename(db1, "foo").endsWith(dbName) );
 
-    final ValueHolder<Boolean> xDestroyed = new ValueHolder<>(false);
     final ValueHolder<Integer> xBusyCalled = new ValueHolder<>(0);
     BusyHandlerCallback handler = new BusyHandlerCallback(){
         @Override public int call(int n){
           //outln("busy handler #"+n);
           return n > 2 ? 0 : ++xBusyCalled.value;
         }
-        @Override public void xDestroy(){
-          xDestroyed.value = true;
-        }
       };
     rc = sqlite3_busy_handler(db2, handler);
     affirm(0 == rc);
 
     // Force a locked condition...
     execSql(db1, "BEGIN EXCLUSIVE");
-    affirm(!xDestroyed.value);
     rc = sqlite3_prepare_v2(db2, "SELECT * from t", outStmt);
     affirm( SQLITE_BUSY == rc);
     assert( null == outStmt.get() );
     affirm( 3 == xBusyCalled.value );
     sqlite3_close_v2(db1);
-    affirm(!xDestroyed.value);
     sqlite3_close_v2(db2);
-    affirm(xDestroyed.value);
     try{
       final java.io.File f = new java.io.File(dbName);
       f.delete();
index b2f4d0e247ae0c084957f60228d738839f90a761..db9eb67524e4221f8e94acb877355189a32cd9e7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improve\sthreading\ssupport\sfor\sall\stypes\sof\sJNI-side\scallback\shooks,\smaking\sthem\ssafe\sto\sinvoke\sif\sanother\sthread\sis\sbusy\sreplacing\sthem.
-D 2023-08-26T10:20:38.261
+C Remove\sthe\sJava\sBusyHandler.xDestroy()\smethod\s-\sit\sshould\snot\shave\shad\sone.\sEliminate\sthe\slast\sof\sthe\spotentially-significant\sMUTF-8\scases.
+D 2023-08-26T10:51:19.217
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -236,12 +236,12 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3
 F ext/jni/GNUmakefile b28f8b304ef97db8250857cb463aea1b329bfcb584a2902d4c1a490a831e2c9d
 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9
 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
-F ext/jni/src/c/sqlite3-jni.c b34328504aa8a3e761e097ac3454a665dcb770e577d09f665191d98fe4a5a7b6
+F ext/jni/src/c/sqlite3-jni.c 86a9f9182e8c0b1f058196ac4017f3290b948bcfbea1bc55198bdd0ad10a2ea1
 F ext/jni/src/c/sqlite3-jni.h 2745c4abd0933a4e8cc48989fffbad3936b4eaada64cce9ce11453dcd30e4184
 F ext/jni/src/org/sqlite/jni/AggregateFunction.java e0aac6ccae05702f8ee779820570866a2760aaa57a73135c57c8d3580bef52d5
 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java c374bb76409cce7a0bdba94877706b59ac6127fa5d9e6af3e8058c99ce99c030
 F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java 4290d8b0937b07d466b50e6ca4136cec037f3ce658277af0d0c2d371e5f4b459
-F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java 99248b76e9b124f60a25329309ac6a03c197b3e1a493e8f8ae2e577651ea58e5
+F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java efef1892e404f5780d81c46a7997cab874aff5db5131985dd3af319fc5e3adc7
 F ext/jni/src/org/sqlite/jni/CollationCallback.java 4391351e10f26ca61e9c461f969c12f36e0146e50a8c5b66ff549142bbf41f64
 F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java b2adbe0cb41b67bcb638885e00950abe0265e885326a96451f6ab114fb11ef59
 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java c2b4deec20acf9c72ab487ba1a408c54cb5cc12c45baa46490b555b80bd3579f
@@ -264,7 +264,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java d060f302b2cc4cf7a4f5a6b2d36458a2e6
 F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java 13c4ea6f35871261eba63fa4117715515e0beecbdebfb879ec5b1f340ed36904
 F ext/jni/src/org/sqlite/jni/SQLite3Jni.java cb3040fcfe35199bb10b4bca2cc541ca383563f85c9b460412c3bd15f413ae23
 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 21301a947e49f0dd9c682dfe2cc8a6518226c837253dd791cd512f847eeca52c
-F ext/jni/src/org/sqlite/jni/Tester1.java 1a9c6c8252d854398e37f5e4f8d9f66de0fd4767e60e43af26f4fdc681fab8b9
+F ext/jni/src/org/sqlite/jni/Tester1.java 2921142fff8cd5a09d1cee30853457926dc63e647df9a687265bb4e678bc9570
 F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629
 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 25a45e800b0c57f506c237d111bcfd09da584e936fee395d4bd802100ebeff8c
 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java f5eadfa44462c050658230884b41477274f34306accd85c8201a7afbc00d2429
@@ -2103,8 +2103,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 21fd47a68db9df1828f4cc4131d326a193b5751d56a40ae77ed0a78dc0621af1
-R b5acfb602720e59e7b14d5c62b0da1bf
+P f2af7bbf493fe28d92fc9c77425f8bb9d48c02af9a5eabceb0365c705651e114
+R 0a5c5021d2a5ccca7e44db0ac1e86f8f
 U stephan
-Z 1a4a2d91841b9730ebb4db624f2ef288
+Z 3f70be94b4b4f3d48d8c6e932937aea1
 # Remove this line to create a well-formed Fossil manifest.
index e19b4b0c78a88197fe391ba0808adb94aa09d36d..8ec48b7eebdb3789f41417a35262e71f3be38e17 100644 (file)
@@ -1 +1 @@
-f2af7bbf493fe28d92fc9c77425f8bb9d48c02af9a5eabceb0365c705651e114
\ No newline at end of file
+c852f1ebbde273c3d28fe5aff0bf73cfc06b41dd371a94d7520536dc7a1dbcc1
\ No newline at end of file