]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Correct the signature mismatch between JNI sqlite3_column/value_text16() and add...
authorstephan <stephan@noemail.net>
Sun, 27 Aug 2023 11:28:57 +0000 (11:28 +0000)
committerstephan <stephan@noemail.net>
Sun, 27 Aug 2023 11:28:57 +0000 (11:28 +0000)
FossilOrigin-Name: 77f6e70f17c0cb6d031f983c458c9ec2e88d92b4716397533a029af39da2d128

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

index c7d6a48e5bfab517ef5b3d3ab4ca3ffcc3204086..39feafc8a713b6d1a62378eebd99f25b1201a1ff 100644 (file)
   Java_org_sqlite_jni_SQLite3Jni_sqlite3_ ## Suffix
 
 /* Prologue for JNI function declarations and definitions. */
-#define JniDecl(ReturnType,Suffix)                \
-  JNIEXPORT ReturnType JNICALL                  \
-  JniFuncName(Suffix)
+#define JniDecl(ReturnType,Suffix) \
+  JNIEXPORT ReturnType JNICALL JniFuncName(Suffix)
 
 /*
 ** S3JniApi's intent is that CFunc be the C API func(s) the
@@ -377,7 +376,9 @@ enum {
 
 /*
 ** Cache entry for NativePointerHolder subclasses and OutputPointer
-** types.
+** types. The pRef and klazz fields are set up the first time the
+** entry is fetched using S3JniGlobal_nph(). The other fields are
+** populated as needed by the routines which use them.
 */
 typedef struct S3JniNphClass S3JniNphClass;
 struct S3JniNphClass {
@@ -1745,8 +1746,9 @@ typedef struct {
 
 /*
 ** Converts the given (cx, argc, argv) into arguments for the given
-** UDF, placing the result in the final argument. Returns 0 on
-** success, SQLITE_NOMEM on allocation error.
+** UDF, writing the result (Java wrappers for cx and argv) in the
+** final 2 arguments. Returns 0 on success, SQLITE_NOMEM on allocation
+** error. On error *jCx and *jArgv will be set to 0.
 */
 static int udf_args(JNIEnv *env,
                     sqlite3_context * const cx,
@@ -1775,7 +1777,6 @@ static int udf_args(JNIEnv *env,
   *jArgv = ja;
   return 0;
 error_oom:
-  sqlite3_result_error_nomem(cx);
   S3JniUnrefLocal(jcx);
   S3JniUnrefLocal(ja);
   return SQLITE_NOMEM;
@@ -1789,7 +1790,7 @@ error_oom:
 ** not do so. In either case, it clears the exception state.
 **
 ** Returns SQLITE_NOMEM if an allocation fails, else SQLITE_ERROR. In
-** the latter case it calls sqlite3_result_error_nomem().
+** the former case it calls sqlite3_result_error_nomem().
 */
 static int udf_report_exception(JNIEnv * const env, int translateToErr,
                                 sqlite3_context * cx,
@@ -1816,7 +1817,7 @@ static int udf_report_exception(JNIEnv * const env, int translateToErr,
       rc = SQLITE_NOMEM;
     }
   }else{
-    S3JniExceptionWarnCallbackThrew("Client-defined SQL function");
+    S3JniExceptionWarnCallbackThrew("client-defined SQL function");
     S3JniExceptionClear;
   }
   S3JniUnrefLocal(ex);
@@ -1857,6 +1858,7 @@ static int udf_xFV(sqlite3_context* cx, S3JniUdf * s,
   jobject jcx = new_sqlite3_context_wrapper(env, cx);
   int rc = 0;
   int const isFinal = 'F'==zFuncType[1]/*xFinal*/;
+
   if( jcx ){
     (*env)->CallVoidMethod(env, s->jObj, xMethodID, jcx);
     S3JniIfThrew{
@@ -4099,20 +4101,13 @@ S3JniApi(sqlite3_value_text_utf8(),jbyteArray,1value_1text_1utf8)(
   return p ? s3jni_new_jbyteArray(env, p, n) : 0;
 }
 
-S3JniApi(sqlite3_value_text16(),jbyteArray,1value_1text16)(
+S3JniApi(sqlite3_value_text16(),jstring,1value_1text16)(
   JniArgsEnvClass, jobject jpSVal
 ){
   sqlite3_value * const sv = PtrGet_sqlite3_value(jpSVal);
-  jbyteArray jba = 0;
-  if( sv ){
-    int const nLen = sqlite3_value_bytes16(sv);
-    const jbyte * const pBytes =
-      nLen ? sqlite3_value_text16(sv) : 0;
-
-    s3jni_oom_check( nLen ? !!pBytes : 1 );
-    jba = s3jni_new_jbyteArray(env, pBytes, nLen);
-  }
-  return jba;
+  const int n = sqlite3_value_bytes16(sv);
+  const void * const p = sqlite3_value_text16(sv);
+  return s3jni_text16_to_jstring(env, p, n);
 }
 
 JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){
index ed64a45033679a9a319ca503003dd1129fa418ef..a4fc6619c2649604f60ae9035eda3064d1963493 100644 (file)
@@ -1701,10 +1701,10 @@ JNIEXPORT jdouble JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1double
 
 /*
  * Class:     org_sqlite_jni_SQLite3Jni
- * Method:    sqlite3_value_dupe
+ * Method:    sqlite3_value_dup
  * Signature: (Lorg/sqlite/jni/sqlite3_value;)Lorg/sqlite/jni/sqlite3_value;
  */
-JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1dupe
+JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1dup
   (JNIEnv *, jclass, jobject);
 
 /*
@@ -1758,9 +1758,9 @@ JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text
 /*
  * Class:     org_sqlite_jni_SQLite3Jni
  * Method:    sqlite3_value_text16
- * Signature: (Lorg/sqlite/jni/sqlite3_value;)[B
+ * Signature: (Lorg/sqlite/jni/sqlite3_value;)Ljava/lang/String;
  */
-JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text16
+JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text16
   (JNIEnv *, jclass, jobject);
 
 /*
index f8bc36d8e7c168164a2825f7b63d503faffcb6db..b53e921b6523036ccd20433860605a8738cf717f 100644 (file)
@@ -367,7 +367,7 @@ public final class SQLite3Jni {
     Object rv = null;
     sqlite3_value v = sqlite3_column_value(stmt, ndx);
     if(null!=v){
-      v = sqlite3_value_dupe(v) /* we need a "protected" value */;
+      v = sqlite3_value_dup(v) /* we need a "protected" value */;
       if(null!=v){
         rv = sqlite3_value_java_object(v);
         sqlite3_value_free(v);
@@ -1244,7 +1244,7 @@ public final class SQLite3Jni {
 
   public static native double sqlite3_value_double(@NotNull sqlite3_value v);
 
-  public static native sqlite3_value sqlite3_value_dupe(
+  public static native sqlite3_value sqlite3_value_dup(
     @NotNull sqlite3_value v
   );
 
@@ -1290,7 +1290,7 @@ public final class SQLite3Jni {
     return null==ba ? null : new String(ba, StandardCharsets.UTF_8);
   }
 
-  public static native byte[] sqlite3_value_text16(@NotNull sqlite3_value v);
+  public static native String sqlite3_value_text16(@NotNull sqlite3_value v);
 
   public static native int sqlite3_value_type(@NotNull sqlite3_value v);
 
index 1a4ee178c695f302592b241428f540fb1532ec7e..2647575ee52f4c31c0727600121c8c3f4d3cd054 100644 (file)
@@ -435,9 +435,13 @@ public class Tester1 implements Runnable {
     StringBuilder sbuf = new StringBuilder();
     n = 0;
     while( SQLITE_ROW == sqlite3_step(stmt) ){
-      String txt = sqlite3_column_text16(stmt, 0);
-      //outln("txt = "+txt);
+      final sqlite3_value sv = sqlite3_value_dup(sqlite3_column_value(stmt,0));
+      final String txt = sqlite3_column_text16(stmt, 0);
       sbuf.append( txt );
+      affirm( txt.equals(sqlite3_column_text(stmt, 0)) );
+      affirm( txt.equals(sqlite3_value_text(sv)) );
+      affirm( txt.equals(sqlite3_value_text16(sv)) );
+      sqlite3_value_free(sv);
       ++n;
     }
     sqlite3_finalize(stmt);
index c88153f39908a2463777d57fc0505588b03a5c93..9806221478b888ad72d5577e805e8ff2844f2f72 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\sJNI\ssqlite3_trace_v2()\sthread-safe.\sRe-add\sa\spiece\sremoved\sin\s[bae4d022aad9b]\sto\swork\saround\sa\sJVM\scrash\swhich\sis\sunpredictably\striggered\sby\sits\ssubstitute.\sFix\sthe\sTHREADMODE=0\sJNI\sbuild.\sFurther\sinternal\sAPI\ssimplifications.
-D 2023-08-27T10:40:00.984
+C Correct\sthe\ssignature\smismatch\sbetween\sJNI\ssqlite3_column/value_text16()\sand\sadd\srelated\stests.
+D 2023-08-27T11:28:57.220
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -236,8 +236,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3
 F ext/jni/GNUmakefile 527f7c72360ba081c9ad120a9a00834973dac0115c6272fad94963651ed15bab
 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9
 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
-F ext/jni/src/c/sqlite3-jni.c 79360ee5b71ce2d90e712768456756e5d57c63bce4e8238c23417caabb790a92
-F ext/jni/src/c/sqlite3-jni.h a410d05ca47a676b75ff7b8980e75ad604ea15f3c29965f88989703abc2eeaf6
+F ext/jni/src/c/sqlite3-jni.c fd9f52e536528ffaa4a98a8eebd0e15e438b3289e8f00947abcf011d5c8f9afb
+F ext/jni/src/c/sqlite3-jni.h c035d576158137e620da870eef685e6d96ade54565817fe3988fd209514eace1
 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 0a5a74bea5ee12a99407e9432d0ca393525af912c2b0ca55c7ee5dbd019c00ef
 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java c374bb76409cce7a0bdba94877706b59ac6127fa5d9e6af3e8058c99ce99c030
 F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java 4290d8b0937b07d466b50e6ca4136cec037f3ce658277af0d0c2d371e5f4b459
@@ -262,9 +262,9 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c
 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java be7f7a26d1102fb514d835e11198d51302af8053d97188bfb2e34c2133208568
 F ext/jni/src/org/sqlite/jni/SQLFunction.java d060f302b2cc4cf7a4f5a6b2d36458a2e6fc9648374b5d09c36a43665af41207
 F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java 13c4ea6f35871261eba63fa4117715515e0beecbdebfb879ec5b1f340ed36904
-F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e27b7b75f561a8a04b222b6306c59e65dcf7c1fc9408523da0d65c1ffb0e1590
+F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 2f45ac5e5fcfc03b8be6d3385a6a5a11fff40ba29735d6fde00b686d878017fe
 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 21301a947e49f0dd9c682dfe2cc8a6518226c837253dd791cd512f847eeca52c
-F ext/jni/src/org/sqlite/jni/Tester1.java 37b46dc15ac8fbeb916dcf1f7771023d2be025d05422d725d5891935eda506ac
+F ext/jni/src/org/sqlite/jni/Tester1.java ec5622933b896679a1297db6ed70e0619149913c0043a063c3723ee4645f1c8a
 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 bae4d022aad9bbeb78cb027ecad799af87afe331e697add44ec22297c873141d
-R 3800367f7606fbafc862156daf2d0dd5
+P 3f9f7a9cb08b0687ad206605a5109306762df9ae8bdeab2d8d60bf9373c9ad32
+R e2ef8e56417f07ac504c27650de35a3d
 U stephan
-Z e92f2dfe5d2f02a04f8aac3861297f02
+Z 3bfd1e616266221f5a840c6c97fab6d0
 # Remove this line to create a well-formed Fossil manifest.
index 98d663accaf39760c0a417b306e5b9d20490154c..4be733d0913a57f30da3cff442d6a94420d0f5c0 100644 (file)
@@ -1 +1 @@
-3f9f7a9cb08b0687ad206605a5109306762df9ae8bdeab2d8d60bf9373c9ad32
\ No newline at end of file
+77f6e70f17c0cb6d031f983c458c9ec2e88d92b4716397533a029af39da2d128
\ No newline at end of file