]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Resolve the JNI FTS5 test5() failure and remove some nearby dead code.
authorstephan <stephan@noemail.net>
Sun, 24 Sep 2023 19:13:31 +0000 (19:13 +0000)
committerstephan <stephan@noemail.net>
Sun, 24 Sep 2023 19:13:31 +0000 (19:13 +0000)
FossilOrigin-Name: 5655c51f103c6dfade799ffb5ca2eb21b4360ada598741f373c952ae732535aa

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

index 717ae284cbf2e490130fc91e8691e4b43d901459..c9ee75cb9ba28163932f7eae8e4e178e8b84de81 100644 (file)
@@ -242,6 +242,8 @@ static void * s3jni_malloc_or_die(JNIEnv * const env, size_t n){
 #define s3jni_malloc(SIZE) s3jni_malloc_or_die(env, SIZE)
 #else
 #define s3jni_malloc(SIZE) sqlite3_malloc(((void)env,(SIZE)))
+/* the ((void)env) trickery here is to avoid ^^^^^^ an otherwise
+   unused arg in at least one place. */
 #endif
 
 /*
@@ -5218,10 +5220,13 @@ JniDeclFtsXA(jint,xPhraseSize)(JniArgsEnvObj,jobject jCtx, jint iPhrase){
 /* State for use with xQueryPhrase() and xTokenize(). */
 struct s3jni_xQueryPhraseState {
   Fts5ExtensionApi const * ext;
-  S3JniEnv const * jc;
-  jmethodID midCallback;
-  jobject jCallback;
-  jobject jFcx;
+  jmethodID midCallback; /* jCallback->call() method */
+  jobject jCallback;   /* Fts5ExtensionApi.XQueryPhraseCallback instance */
+  jobject jFcx;        /* (Fts5Context*) for xQueryPhrase()
+                          callback. This is NOT the instance that is
+                          passed to xQueryPhrase(), it's the one
+                          created by xQueryPhrase() for use by its
+                          callback. */
   /* State for xTokenize() */
   struct {
     const char * zPrev;
@@ -5232,11 +5237,13 @@ struct s3jni_xQueryPhraseState {
 
 static int s3jni_xQueryPhrase(const Fts5ExtensionApi *xapi,
                               Fts5Context * pFcx, void *pData){
-  /* TODO: confirm that the Fts5Context passed to this function is
-     guaranteed to be the same one passed to xQueryPhrase(). If it's
-     not, we'll have to create a new wrapper object on every call. */
-  struct s3jni_xQueryPhraseState const * s = pData;
+  struct s3jni_xQueryPhraseState * const s = pData;
   S3JniDeclLocal_env;
+
+  if( !s->jFcx ){
+    s->jFcx = new_java_Fts5Context(env, pFcx);
+    if( !s->jFcx ) return SQLITE_NOMEM;
+  }
   int rc = (int)(*env)->CallIntMethod(env, s->jCallback, s->midCallback,
                                       SJG.fts5.jExt, s->jFcx);
   S3JniIfThrew{
@@ -5250,22 +5257,23 @@ static int s3jni_xQueryPhrase(const Fts5ExtensionApi *xapi,
 JniDeclFtsXA(jint,xQueryPhrase)(JniArgsEnvObj,jobject jFcx, jint iPhrase,
                             jobject jCallback){
   Fts5ExtDecl;
-  S3JniEnv * const jc = S3JniEnv_get();
+  int rc;
   struct s3jni_xQueryPhraseState s;
   jclass klazz = jCallback ? (*env)->GetObjectClass(env, jCallback) : NULL;
 
   if( !klazz ) return SQLITE_MISUSE;
-  s.jc = jc;
   s.jCallback = jCallback;
-  s.jFcx = jFcx;
+  s.jFcx = 0;
   s.ext = ext;
   s.midCallback = (*env)->GetMethodID(env, klazz, "call",
                                       "(Lorg/sqlite/jni/fts5/Fts5ExtensionApi;"
                                       "Lorg/sqlite/jni/fts5/Fts5Context;)I");
   S3JniUnrefLocal(klazz);
   S3JniExceptionIsFatal("Could not extract xQueryPhraseCallback.call() method.");
-  return (jint)ext->xQueryPhrase(PtrGet_Fts5Context(jFcx), iPhrase, &s,
-                                  s3jni_xQueryPhrase);
+  rc = ext->xQueryPhrase(PtrGet_Fts5Context(jFcx), iPhrase, &s,
+                         s3jni_xQueryPhrase);
+  S3JniUnrefLocal(s.jFcx);
+  return (jint)rc;
 }
 
 
@@ -5334,7 +5342,6 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef,
                                  jint tokFlags, jobject jFcx,
                                  jbyteArray jbaText, jobject jCallback){
   Fts5ExtDecl;
-  S3JniEnv * const jc = S3JniEnv_get();
   struct s3jni_xQueryPhraseState s;
   int rc = 0;
   jbyte * const pText = jCallback ? s3jni_jbyteArray_bytes(jbaText) : 0;
@@ -5343,7 +5350,6 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef,
 
   if( !klazz ) return SQLITE_MISUSE;
   memset(&s, 0, sizeof(s));
-  s.jc = jc;
   s.jCallback = jCallback;
   s.jFcx = jFcx;
   s.ext = ext;
index def3777e74a93bfd485b3c18700b427ba2fc0285..6f9c60806776feff3ddec31e3e1a24b91c2fe629 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sextra\stests\sfor\sthe\sfts5\sxPhraseQuery\sAPI.
-D 2023-09-23T15:34:02.590
+C Resolve\sthe\sJNI\sFTS5\stest5()\sfailure\sand\sremove\ssome\snearby\sdead\scode.
+D 2023-09-24T19:13:31.100
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -238,7 +238,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3
 F ext/jni/GNUmakefile 42e00052401b6dd41c0cdd53b31450606ea37486283abdb038dff9be74bff71e
 F ext/jni/README.md 9fceaeb17cecdc5d699dfc83c0cbc3a03fdb3b86bf676381894166c73375ee75
 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
-F ext/jni/src/c/sqlite3-jni.c 85f9dfec5873ff7eb1c6065df11b9dd2ead4b12d33fd3fa6381e8dfb97539edc
+F ext/jni/src/c/sqlite3-jni.c e8e0ac79c23a1f31c8c7d070776e6438872e309359bf9105c568b5f146d1761b
 F ext/jni/src/c/sqlite3-jni.h c934b646b62c0fd13dfceea7a54d8fc0d1274d0520d0edc58ad220753f4c4f7d
 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436
 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4
@@ -2121,8 +2121,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 0233f310bf6bbb84f76b25205af160951e0bf6d8b2f1bca4537384af4fe47e58
-R a79093123e8657d8e8898c97d0afc8e9
-U dan
-Z 25c3994310f2c0eef206c81ad1921212
+P b5edea16317ccc896394011f45442af44d5ea1041b6abfe152c90412c78bfc5b
+R e953b1803753c8b191ad714c0d30fec2
+U stephan
+Z 3ee8d5bd34ec986d01785356a75c837f
 # Remove this line to create a well-formed Fossil manifest.
index 35fdb0d7040f2d62994220315b61aa49235b0acb..c67f420d3ce900a1eee818b405804a1e21782524 100644 (file)
@@ -1 +1 @@
-b5edea16317ccc896394011f45442af44d5ea1041b6abfe152c90412c78bfc5b
\ No newline at end of file
+5655c51f103c6dfade799ffb5ca2eb21b4360ada598741f373c952ae732535aa
\ No newline at end of file