From 0c2ba994d2ad30225afe26c02f0575534c8ff71e Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 31 Aug 2023 14:57:01 +0000 Subject: [PATCH 01/36] Export sqlite3_(db_)free_memory() and sqlite3_table_column_metadata() to JNI. Further internals renaming for consistency and legibility. FossilOrigin-Name: 7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2 --- ext/jni/src/c/sqlite3-jni.c | 381 ++++++++++-------- ext/jni/src/c/sqlite3-jni.h | 24 ++ ext/jni/src/org/sqlite/jni/OutputPointer.java | 20 + ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 18 +- ext/jni/src/org/sqlite/jni/Tester1.java | 26 ++ manifest | 25 +- manifest.uuid | 2 +- 7 files changed, 319 insertions(+), 177 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 20bc5cc986..4fe788a007 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -217,7 +217,8 @@ /* ** Declares local var env = s3jni_env(). All JNI calls involve a ** JNIEnv somewhere, always named env, and many of our macros assume -** env is in scope. +** env is in scope. Where it's not, but should be, use this to make it +** so. */ #define S3JniDeclLocal_env JNIEnv * const env = s3jni_env() @@ -316,6 +317,7 @@ static const struct { const S3JniNphRef sqlite3_stmt; const S3JniNphRef sqlite3_context; const S3JniNphRef sqlite3_value; + const S3JniNphRef OutputPointer_Bool; const S3JniNphRef OutputPointer_Int32; const S3JniNphRef OutputPointer_Int64; const S3JniNphRef OutputPointer_sqlite3; @@ -341,22 +343,23 @@ static const struct { RefN(1, "sqlite3_stmt"), RefN(2, "sqlite3_context"), RefN(3, "sqlite3_value"), - RefO(4, "OutputPointer$Int32", "I"), - RefO(5, "OutputPointer$Int64", "J"), - RefO(6, "OutputPointer$sqlite3", + RefO(4, "OutputPointer$Bool", "Z"), + RefO(5, "OutputPointer$Int32", "I"), + RefO(6, "OutputPointer$Int64", "J"), + RefO(7, "OutputPointer$sqlite3", "Lorg/sqlite/jni/sqlite3;"), - RefO(7, "OutputPointer$sqlite3_stmt", + RefO(8, "OutputPointer$sqlite3_stmt", "Lorg/sqlite/jni/sqlite3_stmt;"), - RefO(8, "OutputPointer$sqlite3_value", + RefO(9, "OutputPointer$sqlite3_value", "Lorg/sqlite/jni/sqlite3_value;"), #ifdef SQLITE_ENABLE_FTS5 - RefO(9, "OutputPointer$String", "Ljava/lang/String;"), - RefO(10, "OutputPointer$ByteArray", "[B"), - RefN(11, "Fts5Context"), - RefN(12, "Fts5ExtensionApi"), - RefN(13, "fts5_api"), - RefN(14, "fts5_tokenizer"), - RefN(15, "Fts5Tokenizer") + RefO(10, "OutputPointer$String", "Ljava/lang/String;"), + RefO(11, "OutputPointer$ByteArray", "[B"), + RefN(12, "Fts5Context"), + RefN(13, "Fts5ExtensionApi"), + RefN(14, "fts5_api"), + RefN(15, "fts5_tokenizer"), + RefN(16, "Fts5Tokenizer") #endif #undef MkRef #undef RefN @@ -449,6 +452,9 @@ struct S3JniDb { #endif S3JniDb * pNext /* Next entry in SJG.perDb.aFree */; }; +#define S3JniDb_clientdata_key "S3JniDb" +#define S3JniDb_from_clientdata(pDb) \ + (pDb ? sqlite3_get_clientdata(pDb, S3JniDb_clientdata_key) : 0) /* ** Cache for per-JNIEnv (i.e. per-thread) data. @@ -690,77 +696,77 @@ static void s3jni_incr( volatile unsigned int * const p ){ /* Helpers for working with specific mutexes. */ #if SQLITE_THREADSAFE -#define S3JniMutex_Env_assertLocked \ +#define S3JniEnv_mutex_assertLocked \ assert( 0 != SJG.envCache.locker && "Misuse of S3JniGlobal.envCache.mutex" ) -#define S3JniMutex_Env_assertLocker \ +#define S3JniEnv_mutex_assertLocker \ assert( (env) == SJG.envCache.locker && "Misuse of S3JniGlobal.envCache.mutex" ) -#define S3JniMutex_Env_assertNotLocker \ +#define S3JniEnv_mutex_assertNotLocker \ assert( (env) != SJG.envCache.locker && "Misuse of S3JniGlobal.envCache.mutex" ) -#define S3JniMutex_Env_enter \ - S3JniMutex_Env_assertNotLocker; \ +#define S3JniEnv_mutex_enter \ + S3JniEnv_mutex_assertNotLocker; \ sqlite3_mutex_enter( SJG.envCache.mutex ); \ s3jni_incr(&SJG.metrics.nMutexEnv); \ SJG.envCache.locker = env -#define S3JniMutex_Env_leave \ - S3JniMutex_Env_assertLocker; \ +#define S3JniEnv_mutex_leave \ + S3JniEnv_mutex_assertLocker; \ SJG.envCache.locker = 0; \ sqlite3_mutex_leave( SJG.envCache.mutex ) -#define S3JniMutex_Ext_enter \ +#define S3JniAutoExt_mutex_enter \ sqlite3_mutex_enter( SJG.autoExt.mutex ); \ SJG.autoExt.locker = env; \ s3jni_incr( &SJG.metrics.nMutexAutoExt ) -#define S3JniMutex_Ext_leave \ +#define S3JniAutoExt_mutex_leave \ assert( env == SJG.autoExt.locker && "Misuse of S3JniGlobal.autoExt.mutex" ); \ sqlite3_mutex_leave( SJG.autoExt.mutex ) -#define S3JniMutex_Ext_assertLocker \ +#define S3JniAutoExt_mutex_assertLocker \ assert( env == SJG.autoExt.locker && "Misuse of S3JniGlobal.autoExt.mutex" ) -#define S3JniMutex_Global_enter \ +#define S3JniGlobal_mutex_enter \ sqlite3_mutex_enter( SJG.mutex ); \ s3jni_incr(&SJG.metrics.nMutexGlobal); -#define S3JniMutex_Global_leave \ +#define S3JniGlobal_mutex_leave \ sqlite3_mutex_leave( SJG.mutex ) -#define S3JniMutex_Nph_enter \ - S3JniMutex_Env_assertNotLocker; \ +#define S3JniNph_mutex_enter \ + S3JniEnv_mutex_assertNotLocker; \ sqlite3_mutex_enter( SJG.envCache.mutex ); \ s3jni_incr( &SJG.metrics.nMutexEnv2 ); \ SJG.envCache.locker = env -#define S3JniMutex_Nph_leave \ - S3JniMutex_Env_assertLocker; \ +#define S3JniNph_mutex_leave \ + S3JniEnv_mutex_assertLocker; \ SJG.envCache.locker = 0; \ sqlite3_mutex_leave( SJG.envCache.mutex ) -#define S3JniMutex_S3JniDb_assertLocker \ +#define S3JniDb_mutex_assertLocker \ assert( (env) == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ) -#define S3JniMutex_S3JniDb_enter \ +#define S3JniDb_mutex_enter \ sqlite3_mutex_enter( SJG.perDb.mutex ); \ assert( 0==SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ s3jni_incr( &SJG.metrics.nMutexPerDb ); \ SJG.perDb.locker = env; -#define S3JniMutex_S3JniDb_leave \ +#define S3JniDb_mutex_leave \ assert( env == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ SJG.perDb.locker = 0; \ sqlite3_mutex_leave( SJG.perDb.mutex ) #else /* SQLITE_THREADSAFE==0 */ -#define S3JniMutex_Env_assertLocked -#define S3JniMutex_Env_assertLocker -#define S3JniMutex_Env_assertNotLocker -#define S3JniMutex_Env_enter -#define S3JniMutex_Env_leave -#define S3JniMutex_Ext_assertLocker -#define S3JniMutex_Ext_enter -#define S3JniMutex_Ext_leave -#define S3JniMutex_Global_enter -#define S3JniMutex_Global_leave -#define S3JniMutex_Nph_enter -#define S3JniMutex_Nph_leave -#define S3JniMutex_S3JniDb_assertLocker -#define S3JniMutex_S3JniDb_enter -#define S3JniMutex_S3JniDb_leave +#define S3JniEnv_mutex_assertLocked +#define S3JniEnv_mutex_assertLocker +#define S3JniEnv_mutex_assertNotLocker +#define S3JniEnv_mutex_enter +#define S3JniEnv_mutex_leave +#define S3JniAutoExt_mutex_assertLocker +#define S3JniAutoExt_mutex_enter +#define S3JniAutoExt_mutex_leave +#define S3JniGlobal_mutex_enter +#define S3JniGlobal_mutex_leave +#define S3JniNph_mutex_enter +#define S3JniNph_mutex_leave +#define S3JniDb_mutex_assertLocker +#define S3JniDb_mutex_enter +#define S3JniDb_mutex_leave #endif /* Helpers for jstring and jbyteArray. */ @@ -805,12 +811,12 @@ static JNIEnv * s3jni_env(void){ */ static S3JniEnv * S3JniEnv__get(JNIEnv * const env){ struct S3JniEnv * row; - S3JniMutex_Env_enter; + S3JniEnv_mutex_enter; row = SJG.envCache.aHead; for( ; row; row = row->pNext ){ if( row->env == env ){ s3jni_incr( &SJG.metrics.nEnvHit ); - S3JniMutex_Env_leave; + S3JniEnv_mutex_leave; return row; } } @@ -827,7 +833,7 @@ static S3JniEnv * S3JniEnv__get(JNIEnv * const env){ SJG.envCache.aHead = row; row->env = env; - S3JniMutex_Env_leave; + S3JniEnv_mutex_leave; return row; } @@ -1038,12 +1044,12 @@ static int s3jni__db_exception(JNIEnv * const env, S3JniDb * const ps, if( ex ){ char * zMsg; S3JniExceptionClear; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; zMsg = s3jni_exception_error_msg(env, ex); s3jni_db_error(ps->pDb, errCode, zMsg ? zMsg : zDfltMsg); sqlite3_free(zMsg); S3JniUnrefLocal(ex); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } return errCode; } @@ -1097,12 +1103,12 @@ static void s3jni__call_xDestroy(JNIEnv * const env, jobject jObj){ */ static void S3JniHook__localdup( JNIEnv * const env, S3JniHook const * const src, S3JniHook * const dest ){ - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; *dest = *src; if(src->jObj) dest->jObj = S3JniRefLocal(src->jObj); if(src->jExtra) dest->jExtra = S3JniRefLocal(src->jExtra); dest->doXDestroy = 0; - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } #define S3JniHook_localdup(src,dest) S3JniHook__localdup(env,src,dest) @@ -1140,14 +1146,14 @@ static void S3JniHook__unref(JNIEnv * const env, S3JniHook * const s){ */ static S3JniHook *S3JniHook__alloc(JNIEnv * const env){ S3JniHook * p = 0; - S3JniMutex_Global_enter; + S3JniGlobal_mutex_enter; if( SJG.hooks.aFree ){ p = SJG.hooks.aFree; SJG.hooks.aFree = p->pNext; p->pNext = 0; s3jni_incr(&SJG.metrics.nHookRecycled); } - S3JniMutex_Global_leave; + S3JniGlobal_mutex_leave; if( 0==p ){ p = s3jni_malloc(sizeof(S3JniHook)); if( p ){ @@ -1169,10 +1175,10 @@ static void S3JniHook__free(JNIEnv * const env, S3JniHook * const p){ if(p){ assert( !p->pNext ); S3JniHook_unref(p); - S3JniMutex_Global_enter; + S3JniGlobal_mutex_enter; p->pNext = SJG.hooks.aFree; SJG.hooks.aFree = p; - S3JniMutex_Global_leave; + S3JniGlobal_mutex_leave; } } #define S3JniHook_free(hook) S3JniHook__free(env, hook) @@ -1197,7 +1203,7 @@ static void S3JniHook__free_unlocked(JNIEnv * const env, S3JniHook * const p){ ** s->pNext and s->pPrev before calling this, as this clears them. */ static void S3JniDb_clear(JNIEnv * const env, S3JniDb * const s){ - S3JniMutex_S3JniDb_assertLocker; + S3JniDb_mutex_assertLocker; sqlite3_free( s->zMainDbName ); #define UNHOOK(MEMBER) \ S3JniHook_unref(&s->hooks.MEMBER) @@ -1223,7 +1229,7 @@ static void S3JniDb_clear(JNIEnv * const env, S3JniDb * const s){ */ static void S3JniDb__set_aside_unlocked(JNIEnv * const env, S3JniDb * const s){ assert( s ); - S3JniMutex_S3JniDb_assertLocker; + S3JniDb_mutex_assertLocker; if( s ){ S3JniDb_clear(env, s); s->pNext = SJG.perDb.aFree; @@ -1233,9 +1239,9 @@ static void S3JniDb__set_aside_unlocked(JNIEnv * const env, S3JniDb * const s){ #define S3JniDb_set_aside_unlocked(JniDb) S3JniDb__set_aside_unlocked(env, JniDb) static void S3JniDb__set_aside(JNIEnv * const env, S3JniDb * const s){ - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; S3JniDb_set_aside_unlocked(s); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } #define S3JniDb_set_aside(JNIDB) S3JniDb__set_aside(env, JNIDB) @@ -1250,7 +1256,7 @@ static void S3JniDb__set_aside(JNIEnv * const env, S3JniDb * const s){ static int S3JniEnv_uncache(JNIEnv * const env){ struct S3JniEnv * row; struct S3JniEnv * pPrev = 0; - S3JniMutex_Env_assertLocked; + S3JniEnv_mutex_assertLocked; row = SJG.envCache.aHead; for( ; row; pPrev = row, row = row->pNext ){ if( row->env == env ){ @@ -1281,7 +1287,7 @@ static int S3JniEnv_uncache(JNIEnv * const env){ ** ** It is up to the caller to populate the other members of the ** returned object if needed, taking care to lock the modification -** with S3JniMutex_Nph_enter/leave. +** with S3JniNph_mutex_enter/leave. ** ** This simple cache catches >99% of searches in the current ** (2023-07-31) tests. @@ -1308,7 +1314,7 @@ static S3JniNphClass * S3JniGlobal__nph(JNIEnv * const env, S3JniNphRef const* p assert( pRef->index>=0 && (pRef->index < (sizeof(S3JniNphRefs) / sizeof(S3JniNphRef))) ); if( !pNC->pRef ){ - S3JniMutex_Nph_enter; + S3JniNph_mutex_enter; if( !pNC->pRef ){ jclass const klazz = (*env)->FindClass(env, pRef->zName); S3JniExceptionIsFatal("FindClass() unexpectedly threw"); @@ -1317,7 +1323,7 @@ static S3JniNphClass * S3JniGlobal__nph(JNIEnv * const env, S3JniNphRef const* p /* Must come last to avoid a race condition where pNC->klass can be NULL after this function returns. */; } - S3JniMutex_Nph_leave; + S3JniNph_mutex_leave; } assert( pNC->klazz ); return pNC; @@ -1341,14 +1347,14 @@ static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphRef const* pRef){ S3JniNphClass * const pNC = S3JniGlobal_nph(pRef); if( !pNC->fidValue ){ - S3JniMutex_Nph_enter; + S3JniNph_mutex_enter; if( !pNC->fidValue ){ pNC->fidValue = (*env)->GetFieldID(env, pNC->klazz, pRef->zMember, pRef->zTypeSig); S3JniExceptionIsFatal("Code maintenance required: missing " "required S3JniNphClass::fidValue."); } - S3JniMutex_Nph_leave; + S3JniNph_mutex_leave; } assert( pNC->fidValue ); return pNC->fidValue; @@ -1415,9 +1421,9 @@ static void * NativePointerHolder__get(JNIEnv * env, jobject pObj, */ static sqlite3* PtrGet__sqlite3_lock(JNIEnv * const env, jobject jObj){ sqlite3 *rv; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; rv = PtrGet_sqlite3(jObj); - if( !rv ){ S3JniMutex_S3JniDb_leave; } + if( !rv ){ S3JniDb_mutex_leave; } return rv; } #undef PtrGet_sqlite3 @@ -1431,14 +1437,16 @@ static sqlite3* PtrGet__sqlite3_lock(JNIEnv * const env, jobject jObj){ ** associated with jDb via NativePointerHolder_set(). */ static S3JniDb * S3JniDb_alloc(JNIEnv * const env, jobject jDb){ - S3JniDb * rv; - S3JniMutex_S3JniDb_enter; + S3JniDb * rv = 0; + S3JniDb_mutex_enter; if( SJG.perDb.aFree ){ rv = SJG.perDb.aFree; SJG.perDb.aFree = rv->pNext; rv->pNext = 0; s3jni_incr( &SJG.metrics.nPdbRecycled ); - }else{ + } + S3JniDb_mutex_leave; + if( 0==rv ){ rv = s3jni_malloc( sizeof(S3JniDb)); if( rv ){ s3jni_incr( &SJG.metrics.nPdbAlloc ); @@ -1448,16 +1456,9 @@ static S3JniDb * S3JniDb_alloc(JNIEnv * const env, jobject jDb){ memset(rv, 0, sizeof(S3JniDb)); rv->jDb = S3JniRefGlobal(jDb); } - S3JniMutex_S3JniDb_leave; return rv; } -#define S3JniDb_clientdata_key "S3JniDb" - -/* Short-lived code consolidator. */ -#define S3JniDb_search \ - s = pDb ? sqlite3_get_clientdata(pDb, S3JniDb_clientdata_key) : 0 - /* ** Returns the S3JniDb object for the given org.sqlite.jni.sqlite3 ** object, or NULL if jDb is NULL, no pointer can be extracted @@ -1468,24 +1469,20 @@ static S3JniDb * S3JniDb_alloc(JNIEnv * const env, jobject jDb){ static S3JniDb * S3JniDb__from_java(JNIEnv * const env, jobject jDb){ S3JniDb * s = 0; sqlite3 * pDb = 0; - - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; if( jDb ) pDb = PtrGet_sqlite3(jDb); - S3JniDb_search; - S3JniMutex_S3JniDb_leave; + s = S3JniDb_from_clientdata(pDb); + S3JniDb_mutex_leave; return s; } #define S3JniDb_from_java(jObject) S3JniDb__from_java(env,(jObject)) static S3JniDb * S3JniDb__from_java_unlocked(JNIEnv * const env, jobject jDb){ - S3JniDb * s = 0; sqlite3 * pDb = 0; - - S3JniMutex_S3JniDb_assertLocker; + S3JniDb_mutex_assertLocker; if( jDb ) pDb = PtrGet_sqlite3(jDb); - S3JniDb_search; - return s; + return S3JniDb_from_clientdata(pDb); } #define S3JniDb_from_java_unlocked(JDB) S3JniDb__from_java_unlocked(env, (JDB)) @@ -1493,29 +1490,18 @@ static S3JniDb * S3JniDb__from_java_unlocked(JNIEnv * const env, jobject jDb){ ** S3JniDb finalizer for use with sqlite3_set_clientdata(). */ static void S3JniDb_xDestroy(void *p){ - S3JniDb * ps = p; S3JniDeclLocal_env; - + S3JniDb * const ps = p; assert( !ps->pNext ); S3JniDb_set_aside(ps); } /* -** Returns the S3JniDb object for the sqlite3 object, or NULL if pDb -** is NULL, or no matching entry -** can be found. -** -** Requires locking the S3JniDb mutex. +** Evaluates to the S3JniDb object for the given sqlite3 object, or +** NULL if pDb is NULL or was not initialized via the JNI interfaces. */ -static S3JniDb * S3JniDb__from_c(JNIEnv * const env, sqlite3 *pDb){ - S3JniDb * s = 0; - - S3JniMutex_S3JniDb_enter; - S3JniDb_search; - S3JniMutex_S3JniDb_leave; - return s; -} -#define S3JniDb_from_c(sqlite3Ptr) S3JniDb__from_c(env,(sqlite3Ptr)) +#define S3JniDb_from_c(sqlite3Ptr) \ + ((sqlite3Ptr) ? S3JniDb_from_clientdata(sqlite3Ptr) : 0) /* ** Unref any Java-side state in (S3JniAutoExtension*) AX and zero out @@ -1534,7 +1520,7 @@ static int S3JniAutoExtension_init(JNIEnv *const env, jobject const jAutoExt){ jclass const klazz = (*env)->GetObjectClass(env, jAutoExt); - S3JniMutex_Ext_assertLocker; + S3JniAutoExt_mutex_assertLocker; *ax = S3JniHook_empty; ax->midCallback = (*env)->GetMethodID(env, klazz, "call", "(Lorg/sqlite/jni/sqlite3;)I"); @@ -1548,6 +1534,18 @@ static int S3JniAutoExtension_init(JNIEnv *const env, return 0; } +/* +** Sets the value property of the OutputPointer.Bool jOut object to +** v. +*/ +static void OutputPointer_set_Bool(JNIEnv * const env, jobject const jOut, + int v){ + (*env)->SetBooleanField(env, jOut, s3jni_nphop_field( + env, &S3JniNphRefs.OutputPointer_Bool + ), v ? JNI_TRUE : JNI_FALSE ); + S3JniExceptionIsFatal("Cannot set OutputPointer.Bool.value"); +} + /* ** Sets the value property of the OutputPointer.Int32 jOut object to ** v. @@ -1624,6 +1622,7 @@ static void OutputPointer_set_ByteArray(JNIEnv * const env, jobject const jOut, OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_ByteArray, jOut, v); } #endif +#endif /* SQLITE_ENABLE_FTS5 */ /* ** Sets the value property of the OutputPointer.String jOut object to @@ -1633,7 +1632,6 @@ static void OutputPointer_set_String(JNIEnv * const env, jobject const jOut, jstring const v){ OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_String, jOut, v); } -#endif /* SQLITE_ENABLE_FTS5 */ /* ** Returns true if eTextRep is a valid sqlite3 encoding constant, else @@ -1681,12 +1679,12 @@ static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef co jobject rv = 0; S3JniNphClass * const pNC = S3JniGlobal_nph(pRef); if( !pNC->midCtor ){ - S3JniMutex_Nph_enter; + S3JniNph_mutex_enter; if( !pNC->midCtor ){ pNC->midCtor = (*env)->GetMethodID(env, pNC->klazz, "", "()V"); S3JniExceptionIsFatal("Cannot find constructor for class."); } - S3JniMutex_Nph_leave; + S3JniNph_mutex_leave; } rv = (*env)->NewObject(env, pNC->klazz, pNC->midCtor); S3JniExceptionIsFatal("No-arg constructor threw."); @@ -1728,7 +1726,7 @@ typedef void (*udf_xFinal_f)(sqlite3_context*); static S3JniUdf * S3JniUdf_alloc(JNIEnv * const env, jobject jObj){ S3JniUdf * s = 0; - S3JniMutex_Global_enter; + S3JniGlobal_mutex_enter; s3jni_incr(&SJG.metrics.nMutexUdf); if( SJG.udf.aFree ){ s = SJG.udf.aFree; @@ -1736,7 +1734,7 @@ static S3JniUdf * S3JniUdf_alloc(JNIEnv * const env, jobject jObj){ s->pNext = 0; s3jni_incr(&SJG.metrics.nUdfRecycled); } - S3JniMutex_Global_leave; + S3JniGlobal_mutex_leave; if( !s ){ s = s3jni_malloc( sizeof(*s)); s3jni_incr(&SJG.metrics.nUdfAlloc); @@ -1790,10 +1788,10 @@ static void S3JniUdf_free(JNIEnv * const env, S3JniUdf * const s, memset(s, 0, sizeof(*s)); } if( cacheIt ){ - S3JniMutex_Global_enter; + S3JniGlobal_mutex_enter; s->pNext = S3JniGlobal.udf.aFree; S3JniGlobal.udf.aFree = s; - S3JniMutex_Global_leave; + S3JniGlobal_mutex_leave; }else{ sqlite3_free( s ); } @@ -2060,6 +2058,7 @@ WRAP_INT_DB(1preupdate_1blobwrite, sqlite3_preupdate_blobwrite) WRAP_INT_DB(1preupdate_1count, sqlite3_preupdate_count) WRAP_INT_DB(1preupdate_1depth, sqlite3_preupdate_depth) #endif +WRAP_INT_INT(1release_1memory, sqlite3_release_memory) WRAP_INT_INT(1sleep, sqlite3_sleep) WRAP_MUTF8_VOID(1sourceid, sqlite3_sourceid) WRAP_INT_VOID(1threadsafe, sqlite3_threadsafe) @@ -2124,7 +2123,8 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, return rc; } NativePointerHolder_set(&S3JniNphRefs.sqlite3, ps->jDb, pDb) - /* As of here, the Java/C connection is complete */; + /* As of here, the Java/C connection is complete except for the + (temporary) lack of finalizer for the ps object. */; ps->pDb = pDb; for( i = 0; go && 0==rc; ++i ){ S3JniAutoExtension ax = {0,0} @@ -2132,14 +2132,14 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, ** local reference to it, to avoid a race condition with another ** thread manipulating the list during the call and invaliding ** what ax points to. */; - S3JniMutex_Ext_enter; + S3JniAutoExt_mutex_enter; if( i >= SJG.autoExt.nExt ){ go = 0; }else{ ax.jObj = S3JniRefLocal(SJG.autoExt.aExt[i].jObj); ax.midCallback = SJG.autoExt.aExt[i].midCallback; } - S3JniMutex_Ext_leave; + S3JniAutoExt_mutex_leave; if( ax.jObj ){ rc = (*env)->CallIntMethod(env, ax.jObj, ax.midCallback, ps->jDb); S3JniUnrefLocal(ax.jObj); @@ -2166,13 +2166,13 @@ S3JniApi(sqlite3_auto_extension(),jint,1auto_1extension)( int rc = 0; if( !jAutoExt ) return SQLITE_MISUSE; - S3JniMutex_Ext_enter; + S3JniAutoExt_mutex_enter; for( i = 0; i < SJG.autoExt.nExt; ++i ){ /* Look for a match. */ ax = &SJG.autoExt.aExt[i]; if( ax->jObj && (*env)->IsSameObject(env, ax->jObj, jAutoExt) ){ /* same object, so this is a no-op. */ - S3JniMutex_Ext_leave; + S3JniAutoExt_mutex_leave; return 0; } } @@ -2215,7 +2215,7 @@ S3JniApi(sqlite3_auto_extension(),jint,1auto_1extension)( ++SJG.autoExt.nExt; } } - S3JniMutex_Ext_leave; + S3JniAutoExt_mutex_leave; return rc; } @@ -2359,7 +2359,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)( int rc = 0; if( !ps ) return (jint)SQLITE_MISUSE; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; if( jBusy ){ if( pHook->jObj && (*env)->IsSameObject(env, pHook->jObj, jBusy) ){ /* Same object - this is a no-op. */ @@ -2391,7 +2391,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)( } } S3JniHook_unref(&hook); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return rc; } @@ -2401,10 +2401,10 @@ S3JniApi(sqlite3_busy_timeout(),jint,1busy_1timeout)( S3JniDb * const ps = S3JniDb_from_java(jDb); int rc = SQLITE_MISUSE; if( ps ){ - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; S3JniHook_unref(&ps->hooks.busyHandler); rc = sqlite3_busy_timeout(ps->pDb, (int)ms); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } return rc; } @@ -2415,7 +2415,7 @@ S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)( S3JniAutoExtension * ax; jboolean rc = JNI_FALSE; int i; - S3JniMutex_Ext_enter; + S3JniAutoExt_mutex_enter; /* This algo mirrors the one in the core. */ for( i = SJG.autoExt.nExt-1; i >= 0; --i ){ ax = &SJG.autoExt.aExt[i]; @@ -2430,7 +2430,7 @@ S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)( break; } } - S3JniMutex_Ext_leave; + S3JniAutoExt_mutex_leave; return rc; } @@ -2513,10 +2513,10 @@ S3JniApi(sqlite3_collation_needed(),jint,1collation_1needed)( S3JniCollationNeeded * pHook; int rc = 0; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; ps = S3JniDb_from_java_unlocked(jDb); if( !ps ){ - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return SQLITE_MISUSE; } pHook = &ps->hooks.collationNeeded; @@ -2548,7 +2548,7 @@ S3JniApi(sqlite3_collation_needed(),jint,1collation_1needed)( } } } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return rc; } @@ -2655,11 +2655,11 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env, jobject pOld = 0; S3JniHook * pHook; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; ps = S3JniDb_from_java_unlocked(jDb); if( !ps ){ s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return 0; } pHook = isCommit ? &ps->hooks.commit : &ps->hooks.rollback; @@ -2699,7 +2699,7 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env, } } } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return pOld; } @@ -2791,7 +2791,7 @@ S3JniApi(sqlite3_config() /* for SQLLOG */, S3JniHook * const pHook = &SJG.hooks.sqllog; int rc = 0; - S3JniMutex_Global_enter; + S3JniGlobal_mutex_enter; if( !jLog ){ rc = sqlite3_config( SQLITE_CONFIG_SQLLOG, s3jni_config_sqllog, 0 ); if( 0==rc ){ @@ -2818,7 +2818,7 @@ S3JniApi(sqlite3_config() /* for SQLLOG */, rc = SQLITE_ERROR; } } - S3JniMutex_Global_leave; + S3JniGlobal_mutex_leave; return rc; #endif } @@ -2878,7 +2878,7 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(), int rc; S3JniDb * ps; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; ps = S3JniDb_from_java_unlocked(jDb); if( !ps ){ rc = SQLITE_MISUSE; @@ -2912,7 +2912,7 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(), sqlite3_free(zName); } } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return (jint)rc; } @@ -3009,7 +3009,7 @@ S3JniApi(sqlite3_db_config() /*for MAINDBNAME*/, switch( (ps && jStr) ? op : 0 ){ case SQLITE_DBCONFIG_MAINDBNAME: - S3JniMutex_S3JniDb_enter + S3JniDb_mutex_enter /* Protect against a race in modifying/freeing ps->zMainDbName. */; zStr = s3jni_jstring_to_utf8( jStr, 0); @@ -3024,7 +3024,7 @@ S3JniApi(sqlite3_db_config() /*for MAINDBNAME*/, }else{ rc = SQLITE_NOMEM; } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; break; default: rc = SQLITE_MISUSE; @@ -3089,6 +3089,12 @@ JniDecl(jint,1db_1config__Lorg_sqlite_jni_sqlite3_2IILorg_sqlite_jni_OutputPoint ); } +S3JniApi(sqlite3_db_release_memory(),int,1db_1release_1memory)( + JniArgsEnvClass, jobject jDb +){ + sqlite3 * const pDb = PtrGet_sqlite3(jDb); + return pDb ? sqlite3_db_release_memory(pDb) : SQLITE_MISUSE; +} S3JniApi(sqlite3_db_status(),jint,1db_1status)( JniArgsEnvClass, jobject jDb, jint op, jobject jOutCurrent, @@ -3197,9 +3203,9 @@ S3JniApi(sqlite3_is_interrupted(),jboolean,1is_1interrupted)( */ JniDecl(jboolean,1java_1uncache_1thread)(JniArgsEnvClass){ int rc; - S3JniMutex_Env_enter; + S3JniEnv_mutex_enter; rc = S3JniEnv_uncache(env); - S3JniMutex_Env_leave; + S3JniEnv_mutex_leave; return rc ? JNI_TRUE : JNI_FALSE; } @@ -3278,8 +3284,8 @@ static int s3jni_open_post(JNIEnv * const env, S3JniEnv * const jc, && "Set up via s3jni_run_java_auto_extensions()" ); } rc = sqlite3_set_clientdata(ps->pDb, S3JniDb_clientdata_key, - ps, S3JniDb_xDestroy); - /* As of here, the Java/C connection is complete */ + ps, S3JniDb_xDestroy) + /* As of here, the Java/C connection is complete */; }else{ S3JniDb_set_aside(ps); ps = 0; @@ -3507,7 +3513,7 @@ static jobject s3jni_updatepre_hook(JNIEnv * env, int isPre, jobject jDb, jobjec S3JniHook * pHook; if( !ps ) return 0; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; pHook = isPre ? #ifdef SQLITE_ENABLE_PREUPDATE_HOOK &ps->hooks.preUpdate @@ -3567,7 +3573,7 @@ static jobject s3jni_updatepre_hook(JNIEnv * env, int isPre, jobject jDb, jobjec } } end: - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return pOld; } @@ -3648,7 +3654,7 @@ S3JniApi(sqlite3_progress_handler(),void,1progress_1handler)( S3JniHook * const pHook = ps ? &ps->hooks.progress : 0; if( !ps ) return; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; if( n<1 || !jProgress ){ S3JniHook_unref(pHook); sqlite3_progress_handler(ps->pDb, 0, 0, 0); @@ -3668,7 +3674,7 @@ S3JniApi(sqlite3_progress_handler(),void,1progress_1handler)( sqlite3_progress_handler(ps->pDb, (int)n, s3jni_progress_handler_impl, ps); } } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } S3JniApi(sqlite3_reset(),jint,1reset)( @@ -3681,12 +3687,12 @@ S3JniApi(sqlite3_reset(),jint,1reset)( /* Clears all entries from S3JniGlobal.autoExt. */ static void s3jni_reset_auto_extension(JNIEnv *env){ int i; - S3JniMutex_Ext_enter; + S3JniAutoExt_mutex_enter; for( i = 0; i < SJG.autoExt.nExt; ++i ){ S3JniAutoExtension_clear( &SJG.autoExt.aExt[i] ); } SJG.autoExt.nExt = 0; - S3JniMutex_Ext_leave; + S3JniAutoExt_mutex_leave; } S3JniApi(sqlite3_reset_auto_extension(),void,1reset_1auto_1extension)( @@ -3948,7 +3954,7 @@ S3JniApi(sqlite3_set_authorizer(),jint,1set_1authorizer)( int rc = 0; if( !ps ) return SQLITE_MISUSE; - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; if( !jHook ){ S3JniHook_unref(pHook); rc = sqlite3_set_authorizer( ps->pDb, 0, 0 ); @@ -3957,7 +3963,7 @@ S3JniApi(sqlite3_set_authorizer(),jint,1set_1authorizer)( if( pHook->jObj ){ if( (*env)->IsSameObject(env, pHook->jObj, jHook) ){ /* Same object - this is a no-op. */ - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return 0; } S3JniHook_unref(pHook); @@ -3981,7 +3987,7 @@ S3JniApi(sqlite3_set_authorizer(),jint,1set_1authorizer)( } if( rc ) S3JniHook_unref(pHook); } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; return rc; } @@ -3998,15 +4004,15 @@ S3JniApi(sqlite3_shutdown(),jint,1shutdown)( ){ s3jni_reset_auto_extension(env); /* Free up S3JniDb recycling bin. */ - S3JniMutex_S3JniDb_enter; { + S3JniDb_mutex_enter; { while( S3JniGlobal.perDb.aFree ){ S3JniDb * const d = S3JniGlobal.perDb.aFree; S3JniGlobal.perDb.aFree = d->pNext; S3JniDb_clear(env, d); sqlite3_free(d); } - } S3JniMutex_S3JniDb_leave; - S3JniMutex_Global_enter; { + } S3JniDb_mutex_leave; + S3JniGlobal_mutex_enter; { /* Free up S3JniUdf recycling bin. */ while( S3JniGlobal.udf.aFree ){ S3JniUdf * const u = S3JniGlobal.udf.aFree; @@ -4024,13 +4030,13 @@ S3JniApi(sqlite3_shutdown(),jint,1shutdown)( assert( !u->jExtra ); sqlite3_free( u ); } - } S3JniMutex_Global_leave; + } S3JniGlobal_mutex_leave; /* Free up env cache. */ - S3JniMutex_Env_enter; { + S3JniEnv_mutex_enter; { while( SJG.envCache.aHead ){ S3JniEnv_uncache( SJG.envCache.aHead->env ); } - } S3JniMutex_Env_leave; + } S3JniEnv_mutex_leave; #if 0 /* ** Is automatically closing any still-open dbs a good idea? We will @@ -4038,11 +4044,11 @@ S3JniApi(sqlite3_shutdown(),jint,1shutdown)( ** state, at which point we won't have a central list of databases ** to close. */ - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; while( SJG.perDb.pHead ){ s3jni_close_db(env, SJG.perDb.pHead->jDb, 2); } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; #endif /* Do not clear S3JniGlobal.jvm: it's legal to restart the lib. */ return sqlite3_shutdown(); @@ -4128,6 +4134,53 @@ S3JniApi(sqlite3_step(),jint,1step)( return rc; } +S3JniApi(sqlite3_table_column_metadata(),int,1table_1column_1metadata)( + JniArgsEnvClass, jobject jDb, jstring jDbName, jstring jTableName, + jstring jColumnName, jobject jDataType, jobject jCollSeq, jobject jNotNull, + jobject jPrimaryKey, jobject jAutoinc +){ + sqlite3 * const db = PtrGet_sqlite3(jDb); + char * zDbName = 0, * zTableName = 0, * zColumnName = 0; + const char * pzCollSeq = 0; + const char * pzDataType = 0; + int pNotNull = 0, pPrimaryKey = 0, pAutoinc = 0; + int rc; + + if( !db || !jDbName || !jTableName || !jColumnName ) return SQLITE_MISUSE; + zDbName = s3jni_jstring_to_utf8(jDbName,0); + zTableName = zDbName ? s3jni_jstring_to_utf8(jTableName,0) : 0; + zColumnName = zTableName ? s3jni_jstring_to_utf8(jColumnName,0) : 0; + rc = zColumnName + ? sqlite3_table_column_metadata(db, zDbName, zTableName, + zColumnName, &pzDataType, &pzCollSeq, + &pNotNull, &pPrimaryKey, &pAutoinc) + : SQLITE_NOMEM; + if( 0==rc ){ + jstring jseq = jCollSeq + ? (pzCollSeq ? s3jni_utf8_to_jstring(pzCollSeq, -1) : 0) + : 0; + jstring jdtype = jDataType + ? (pzDataType ? s3jni_utf8_to_jstring(pzDataType, -1) : 0) + : 0; + if( (jCollSeq && pzCollSeq && !jseq) + || (jDataType && pzDataType && !jdtype) ){ + rc = SQLITE_NOMEM; + }else{ + if( jNotNull ) OutputPointer_set_Bool(env, jNotNull, pNotNull); + if( jPrimaryKey ) OutputPointer_set_Bool(env, jPrimaryKey, pPrimaryKey); + if( jAutoinc ) OutputPointer_set_Bool(env, jAutoinc, pAutoinc); + if( jCollSeq ) OutputPointer_set_String(env, jCollSeq, jseq); + if( jDataType ) OutputPointer_set_String(env, jDataType, jdtype); + } + S3JniUnrefLocal(jseq); + S3JniUnrefLocal(jdtype); + } + sqlite3_free(zDbName); + sqlite3_free(zTableName); + sqlite3_free(zColumnName); + return rc; +} + static int s3jni_trace_impl(unsigned traceflag, void *pC, void *pP, void *pX){ S3JniDb * const ps = (S3JniDb *)pC; S3JniDeclLocal_env; @@ -4195,10 +4248,10 @@ S3JniApi(sqlite3_trace_v2(),jint,1trace_1v2)( if( !ps ) return SQLITE_MISUSE; if( !traceMask || !jTracer ){ - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; rc = (jint)sqlite3_trace_v2(ps->pDb, 0, 0, 0); S3JniHook_unref(&ps->hooks.trace); - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; }else{ jclass const klazz = (*env)->GetObjectClass(env, jTracer); S3JniHook hook = S3JniHook_empty; @@ -4213,7 +4266,7 @@ S3JniApi(sqlite3_trace_v2(),jint,1trace_1v2)( "TracerCallback object."); }else{ hook.jObj = S3JniRefGlobal(jTracer); - S3JniMutex_S3JniDb_enter; + S3JniDb_mutex_enter; rc = sqlite3_trace_v2(ps->pDb, (unsigned)traceMask, s3jni_trace_impl, ps); if( 0==rc ){ S3JniHook_unref(&ps->hooks.trace); @@ -4221,7 +4274,7 @@ S3JniApi(sqlite3_trace_v2(),jint,1trace_1v2)( }else{ S3JniHook_unref(&hook); } - S3JniMutex_S3JniDb_leave; + S3JniDb_mutex_leave; } } return rc; @@ -4486,14 +4539,14 @@ static jobject s3jni_getFts5ExensionApi(JNIEnv * const env){ jobject pNPH = new_NativePointerHolder_object( env, &S3JniNphRefs.Fts5ExtensionApi, s3jni_ftsext() ); - S3JniMutex_Env_enter; + S3JniEnv_mutex_enter; if( pNPH ){ if( !SJG.fts5.jFtsExt ){ SJG.fts5.jFtsExt = S3JniRefGlobal(pNPH); } S3JniUnrefLocal(pNPH); } - S3JniMutex_Env_leave; + S3JniEnv_mutex_leave; } return SJG.fts5.jFtsExt; } diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 40dd449901..a5454d54c7 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1187,6 +1187,14 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1filename JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1handle (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_db_release_memory + * Signature: (Lorg/sqlite/jni/sqlite3;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1release_1memory + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_db_status @@ -1403,6 +1411,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1preupdate_1old JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1progress_1handler (JNIEnv *, jclass, jobject, jint, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_release_memory + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1release_1memory + (JNIEnv *, jclass, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_reset @@ -1643,6 +1659,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strglob JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strlike (JNIEnv *, jclass, jbyteArray, jbyteArray, jint); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_table_column_metadata + * Signature: (Lorg/sqlite/jni/sqlite3;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/sqlite/jni/OutputPointer/String;Lorg/sqlite/jni/OutputPointer/String;Lorg/sqlite/jni/OutputPointer/Bool;Lorg/sqlite/jni/OutputPointer/Bool;Lorg/sqlite/jni/OutputPointer/Bool;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1table_1column_1metadata + (JNIEnv *, jclass, jobject, jstring, jstring, jstring, jobject, jobject, jobject, jobject, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_threadsafe diff --git a/ext/jni/src/org/sqlite/jni/OutputPointer.java b/ext/jni/src/org/sqlite/jni/OutputPointer.java index 8a59de574b..f27d977744 100644 --- a/ext/jni/src/org/sqlite/jni/OutputPointer.java +++ b/ext/jni/src/org/sqlite/jni/OutputPointer.java @@ -108,6 +108,26 @@ public final class OutputPointer { } } + /** + Output pointer for use with native routines which return booleans + via integer output pointers. + */ + public static final class Bool { + /** + This is public for ease of use. Accessors are provided for + consistency with the higher-level types. + */ + public boolean value; + /** Initializes with the value 0. */ + public Bool(){this(false);} + /** Initializes with the value v. */ + public Bool(boolean v){value = v;} + /** Returns the current value. */ + public final boolean get(){return value;} + /** Sets the current value to v. */ + public final void set(boolean v){value = v;} + } + /** Output pointer for use with native routines which return integers via output pointers. diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index d32320b26f..2c6ed2d799 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -612,6 +612,9 @@ public final class SQLite3Jni { @Canonical public static native sqlite3 sqlite3_db_handle( @NotNull sqlite3_stmt stmt ); + @Canonical + public static native int sqlite3_db_release_memory(sqlite3 db); + @Canonical public static native int sqlite3_db_status( @NotNull sqlite3 db, int op, @NotNull OutputPointer.Int32 pCurrent, @@ -972,6 +975,9 @@ public final class SQLite3Jni { @NotNull sqlite3 db, int n, @Nullable ProgressHandlerCallback h ); + @Canonical + public static native int sqlite3_release_memory(int n); + @Canonical public static native int sqlite3_reset(@NotNull sqlite3_stmt stmt); @@ -1304,7 +1310,6 @@ public final class SQLite3Jni { @Canonical public static native String sqlite3_sql(@NotNull sqlite3_stmt stmt); - @Canonical public static native int sqlite3_status( int op, @NotNull OutputPointer.Int32 pCurrent, @@ -1357,6 +1362,17 @@ public final class SQLite3Jni { ); } + @Canonical + public static native int sqlite3_table_column_metadata( + @NotNull sqlite3 db, @NotNull String zDbName, + @NotNull String zTableName, @NotNull String zColumnName, + @Nullable OutputPointer.String pzDataType, + @Nullable OutputPointer.String pzCollSeq, + @Nullable OutputPointer.Bool pNotNull, + @Nullable OutputPointer.Bool pPrimaryKey, + @Nullable OutputPointer.Bool pAutoinc + ); + @Canonical public static native int sqlite3_threadsafe(); diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index e418de6096..bbd61dfbd3 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -731,6 +731,7 @@ public class Tester1 implements Runnable { } sqlite3_finalize(stmt); affirm( 1 == n ); + affirm( 0==sqlite3_db_release_memory(db) ); sqlite3_close_v2(db); } @@ -1359,6 +1360,30 @@ public class Tester1 implements Runnable { affirm( 8 == val.value ); } + + private void testColumnMetadata(){ + sqlite3 db = createNewDb(); + execSql(db, new String[] { + "CREATE TABLE t(a duck primary key not null collate noCase); ", + "INSERT INTO t(a) VALUES(1),(2),(3);" + }); + OutputPointer.Bool bNotNull = new OutputPointer.Bool(); + OutputPointer.Bool bPrimaryKey = new OutputPointer.Bool(); + OutputPointer.Bool bAutoinc = new OutputPointer.Bool(); + OutputPointer.String zCollSeq = new OutputPointer.String(); + OutputPointer.String zDataType = new OutputPointer.String(); + int rc = sqlite3_table_column_metadata( + db, "main", "t", "a", zDataType, zCollSeq, + bNotNull, bPrimaryKey, bAutoinc); + affirm( 0==rc ); + affirm( bPrimaryKey.value ); + affirm( !bAutoinc.value ); + affirm( bNotNull.value ); + affirm( "noCase".equals(zCollSeq.value) ); + affirm( "duck".equals(zDataType.value) ); + sqlite3_close_v2(db); + } + @ManualTest /* we really only want to run this test manually. */ private void testSleep(){ out("Sleeping briefly... "); @@ -1618,6 +1643,7 @@ public class Tester1 implements Runnable { if( doSomethingForDev ){ sqlite3_jni_internal_details(); } + affirm( 0==sqlite3_release_memory(1) ); sqlite3_shutdown(); int nMethods = 0; int nNatives = 0; diff --git a/manifest b/manifest index 0b380a8a0e..4eefbd21f5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\smutexes\sto\smake\ssqlite3_set_clientdata()\sand\ssqlite3_get_clientdata()\nthreadsafe. -D 2023-08-30T18:51:26.770 +C Export\ssqlite3_(db_)free_memory()\sand\ssqlite3_table_column_metadata()\sto\sJNI.\sFurther\sinternals\srenaming\sfor\sconsistency\sand\slegibility. +D 2023-08-31T14:57:01.532 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 374873bf6d2cd6ceafb458e28b59140dbb074f01f7adddf7e15a3ee3daf44551 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c aaec2851258a7d9c9907d8e864a17e055676ec0adb64f335d979fa19674a0cab -F ext/jni/src/c/sqlite3-jni.h 12e1a5ef5ee1795dc22577c285b4518dfd8aa4af45757f6cb81a555d967bf201 +F ext/jni/src/c/sqlite3-jni.c 2364ccb4445c5f45a4d4b80d28455fe0c547f5529e5bd8610b4ba3811c82cc78 +F ext/jni/src/c/sqlite3-jni.h d9ea1662cefe7d8a2737cdbc55799a7e407cbc2239769f486d8eb33b68b9f133 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java d00a2409ab76cae168927e2ca6a7ffbd0621a42547cce88768b4eeebc13827e0 @@ -255,16 +255,16 @@ F ext/jni/src/org/sqlite/jni/Fts5Function.java 65cde7151e441fee012250a5e03277de7 F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d -F ext/jni/src/org/sqlite/jni/OutputPointer.java 4ae06135decef35eb04498daa2868939d91a294e948747c580ef9ce31563a6b3 +F ext/jni/src/org/sqlite/jni/OutputPointer.java 1f2319976fff206f5056eafc8a4f48d43abe09d5d1b5287ba9145a95d847cbb7 F ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java 500c968b3893edbddf67e8eb773852c3a8ae58097a77bd22320ada6b1af06db1 F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 0da841810319f5a9dc372d0f2348930d54fac1a4b53e4298884f44c720d67830 F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 440d64e8c4cff53bd3c0cc676381212489198302d7f1aaa535712c2d7163cc69 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 548ab462e161118b50a614a8bbc2fc2abd507f9b0632267fc78bdd8926ad0807 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c -F ext/jni/src/org/sqlite/jni/Tester1.java 21d78aa59bfc5ce5ff242d4bb6f6d2255d162fba8be5859ab87c9201d61433f0 +F ext/jni/src/org/sqlite/jni/Tester1.java 05750f0ea53057de146fce8d06b7314009732de06f1e4843c87aa28ba940d6f7 F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d @@ -2115,8 +2115,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e7c11d34ee2eebdca4d9db1496bbb4152e4c62745c083ad5e0337733e8d1254e -R 3f04e2f3da46f99baea85816871f54e6 -U drh -Z 4a72dec53887e83eac398e1a9fd59cf2 +P 443ea20ddb0f3bf5d77ef59cd4678f0e32d7da328002bb44d6fc080a53a37e29 +R d454ebcc01c88272e67e43cac0f5ee2a +T *branch * jni-client-data +T *sym-jni-client-data * +T -sym-db-client-data * Cancelled\sby\sbranch. +U stephan +Z c9e44a2d4b476765181f0fdc6d845bb0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 14a82559d3..016324c8ae 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -443ea20ddb0f3bf5d77ef59cd4678f0e32d7da328002bb44d6fc080a53a37e29 \ No newline at end of file +7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2 \ No newline at end of file From 062bafb85162b8f967b79c55170b1f6071451933 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 31 Aug 2023 15:24:46 +0000 Subject: [PATCH 02/36] Add convenience overloads of JNI sqlite3_table_column_metadata() to simplify usage. FossilOrigin-Name: faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b --- ext/jni/GNUmakefile | 1 + ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 28 +++++++++++++++ .../org/sqlite/jni/TableColumnMetadata.java | 35 +++++++++++++++++++ ext/jni/src/org/sqlite/jni/Tester1.java | 12 +++++++ manifest | 20 +++++------ manifest.uuid | 2 +- 6 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 ext/jni/src/org/sqlite/jni/TableColumnMetadata.java diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 44a0d74011..fe53f36a03 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -81,6 +81,7 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\ ScalarFunction.java \ SQLFunction.java \ SQLite3Jni.java \ + TableColumnMetadata.java \ Tester1.java \ TraceV2Callback.java \ UpdateHookCallback.java \ diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 2c6ed2d799..8a4a359aaf 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1373,6 +1373,34 @@ public final class SQLite3Jni { @Nullable OutputPointer.Bool pAutoinc ); + /** + Convenience overload which returns its results via a single + output object. If this function returns non-0 (error), the the + contents of the output object are not modified. + */ + public static int sqlite3_table_column_metadata( + @NotNull sqlite3 db, @NotNull String zDbName, + @NotNull String zTableName, @NotNull String zColumnName, + @NotNull TableColumnMetadata out){ + return sqlite3_table_column_metadata( + db, zDbName, zTableName, zColumnName, + out.pzDataType, out.pzCollSeq, out.pNotNull, + out.pPrimaryKey, out.pAutoinc); + } + + /** + Convenience overload which returns the column metadata object on + success and null on error. + */ + public static TableColumnMetadata sqlite3_table_column_metadata( + @NotNull sqlite3 db, @NotNull String zDbName, + @NotNull String zTableName, @NotNull String zColumnName){ + final TableColumnMetadata out = new TableColumnMetadata(); + return 0==sqlite3_table_column_metadata( + db, zDbName, zTableName, zColumnName, out + ) ? out : null; + } + @Canonical public static native int sqlite3_threadsafe(); diff --git a/ext/jni/src/org/sqlite/jni/TableColumnMetadata.java b/ext/jni/src/org/sqlite/jni/TableColumnMetadata.java new file mode 100644 index 0000000000..70b7c90ec8 --- /dev/null +++ b/ext/jni/src/org/sqlite/jni/TableColumnMetadata.java @@ -0,0 +1,35 @@ +/* +** 2023-07-21 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file is part of the JNI bindings for the sqlite3 C API. +*/ +package org.sqlite.jni; + +/** + A wrapper object for use with sqlite3_table_column_metadata(). + They are populated only via that interface. +*/ +public final class TableColumnMetadata { + OutputPointer.Bool pNotNull = new OutputPointer.Bool(); + OutputPointer.Bool pPrimaryKey = new OutputPointer.Bool(); + OutputPointer.Bool pAutoinc = new OutputPointer.Bool(); + OutputPointer.String pzCollSeq = new OutputPointer.String(); + OutputPointer.String pzDataType = new OutputPointer.String(); + + public TableColumnMetadata(){ + } + + public String getDataType(){ return pzDataType.value; } + public String getCollation(){ return pzCollSeq.value; } + public boolean isNotNull(){ return pNotNull.value; } + public boolean isPrimaryKey(){ return pPrimaryKey.value; } + public boolean isAutoincrement(){ return pAutoinc.value; } +} diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index bbd61dfbd3..a99cc1f9d5 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1381,6 +1381,18 @@ public class Tester1 implements Runnable { affirm( bNotNull.value ); affirm( "noCase".equals(zCollSeq.value) ); affirm( "duck".equals(zDataType.value) ); + + final TableColumnMetadata m = + sqlite3_table_column_metadata(db, "main", "t", "a"); + affirm( null != m ); + affirm( bPrimaryKey.value == m.isPrimaryKey() ); + affirm( bAutoinc.value == m.isAutoincrement() ); + affirm( bNotNull.value == m.isNotNull() ); + affirm( zCollSeq.value.equals(m.getCollation()) ); + affirm( zDataType.value.equals(m.getDataType()) ); + + affirm( null == sqlite3_table_column_metadata(db, "nope", "t", "a") ); + sqlite3_close_v2(db); } diff --git a/manifest b/manifest index 4eefbd21f5..2e4701bf4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Export\ssqlite3_(db_)free_memory()\sand\ssqlite3_table_column_metadata()\sto\sJNI.\sFurther\sinternals\srenaming\sfor\sconsistency\sand\slegibility. -D 2023-08-31T14:57:01.532 +C Add\sconvenience\soverloads\sof\sJNI\ssqlite3_table_column_metadata()\sto\ssimplify\susage. +D 2023-08-31T15:24:46.471 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,7 +234,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 374873bf6d2cd6ceafb458e28b59140dbb074f01f7adddf7e15a3ee3daf44551 +F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa F ext/jni/src/c/sqlite3-jni.c 2364ccb4445c5f45a4d4b80d28455fe0c547f5529e5bd8610b4ba3811c82cc78 @@ -262,9 +262,10 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 548ab462e161118b50a614a8bbc2fc2abd507f9b0632267fc78bdd8926ad0807 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5ac577b1f2290b3ef6e974e5d1530c380c09708ffedb42797dcfc2b8d016904d F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c -F ext/jni/src/org/sqlite/jni/Tester1.java 05750f0ea53057de146fce8d06b7314009732de06f1e4843c87aa28ba940d6f7 +F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab +F ext/jni/src/org/sqlite/jni/Tester1.java 96fefa219302e3e82f720baf082533fed98e6d31fe8887db5e14c150f1d2b3c1 F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d @@ -2115,11 +2116,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 443ea20ddb0f3bf5d77ef59cd4678f0e32d7da328002bb44d6fc080a53a37e29 -R d454ebcc01c88272e67e43cac0f5ee2a -T *branch * jni-client-data -T *sym-jni-client-data * -T -sym-db-client-data * Cancelled\sby\sbranch. +P 7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2 +R b592252ce8c67a9da162168a99edb15f U stephan -Z c9e44a2d4b476765181f0fdc6d845bb0 +Z b8513dbd5fd3543a1785ad43823c91b6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 016324c8ae..9126a286a0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2 \ No newline at end of file +faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b \ No newline at end of file From 63e7ed3b449aa7a76b0e6543e970bd445f862193 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 31 Aug 2023 18:34:43 +0000 Subject: [PATCH 03/36] Minor JNI cleanups. FossilOrigin-Name: 2e2bb841ef8b53266ec48d8c3408d6396f29f17922e858eac1b4f12f4adeb05e --- ext/jni/src/c/sqlite3-jni.c | 11 +++++------ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 2 +- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 4fe788a007..e63c86a1a4 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2127,22 +2127,21 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, (temporary) lack of finalizer for the ps object. */; ps->pDb = pDb; for( i = 0; go && 0==rc; ++i ){ - S3JniAutoExtension ax = {0,0} + S3JniAutoExtension ax = S3JniHook_empty /* We need a copy of the auto-extension object, with our own ** local reference to it, to avoid a race condition with another ** thread manipulating the list during the call and invaliding - ** what ax points to. */; + ** what ax references. */; S3JniAutoExt_mutex_enter; if( i >= SJG.autoExt.nExt ){ go = 0; }else{ - ax.jObj = S3JniRefLocal(SJG.autoExt.aExt[i].jObj); - ax.midCallback = SJG.autoExt.aExt[i].midCallback; + S3JniHook_localdup(&SJG.autoExt.aExt[i], &ax); } S3JniAutoExt_mutex_leave; if( ax.jObj ){ rc = (*env)->CallIntMethod(env, ax.jObj, ax.midCallback, ps->jDb); - S3JniUnrefLocal(ax.jObj); + S3JniHook_localundup(ax); S3JniIfThrew { jthrowable const ex = (*env)->ExceptionOccurred(env); char * zMsg; @@ -2151,7 +2150,7 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, S3JniUnrefLocal(ex); *pzErr = sqlite3_mprintf("auto-extension threw: %s", zMsg); sqlite3_free(zMsg); - if( !rc ) rc = SQLITE_ERROR; + rc = SQLITE_ERROR; } } } diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 8a4a359aaf..c45f50b002 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1426,7 +1426,7 @@ public final class SQLite3Jni { @Canonical public static native UpdateHookCallback sqlite3_update_hook( - sqlite3 db, UpdateHookCallback hook + @NotNull sqlite3 db, @Nullable UpdateHookCallback hook ); @Canonical diff --git a/manifest b/manifest index 2e4701bf4a..ef1d301e64 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sconvenience\soverloads\sof\sJNI\ssqlite3_table_column_metadata()\sto\ssimplify\susage. -D 2023-08-31T15:24:46.471 +C Minor\sJNI\scleanups. +D 2023-08-31T18:34:43.613 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 2364ccb4445c5f45a4d4b80d28455fe0c547f5529e5bd8610b4ba3811c82cc78 +F ext/jni/src/c/sqlite3-jni.c 07b1b48cbc192b4316adf9581412fb280634e87eaf55302f529611b3f49e1c6c F ext/jni/src/c/sqlite3-jni.h d9ea1662cefe7d8a2737cdbc55799a7e407cbc2239769f486d8eb33b68b9f133 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -262,7 +262,7 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5ac577b1f2290b3ef6e974e5d1530c380c09708ffedb42797dcfc2b8d016904d +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java ffabb0a0ed7f35cfdea41502888b1c616b7e9b262afd9f2cace527b7a7ec0631 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab F ext/jni/src/org/sqlite/jni/Tester1.java 96fefa219302e3e82f720baf082533fed98e6d31fe8887db5e14c150f1d2b3c1 @@ -2116,8 +2116,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 7c86aa3400ed591d38c1828f366f4b5de97954c2b301919d3f06d9c2d3d7d1f2 -R b592252ce8c67a9da162168a99edb15f +P faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b +R 67c1ebfb718bb21974f4c19c81901b59 U stephan -Z b8513dbd5fd3543a1785ad43823c91b6 +Z 4fedefd0e23421552f6c24692e21e3ca # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9126a286a0..d71724e89d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b \ No newline at end of file +2e2bb841ef8b53266ec48d8c3408d6396f29f17922e858eac1b4f12f4adeb05e \ No newline at end of file From 0d3f0a9c11de32a74fc33392d47c07108c3e2f25 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 31 Aug 2023 19:35:59 +0000 Subject: [PATCH 04/36] Export sqlite3_txn_state() to JNI. FossilOrigin-Name: d732f71d0a292dbb493f79f7c6ecd8a4effbfbc91453b1c54bdd9becf2d75bdb --- ext/jni/src/c/sqlite3-jni.c | 19 +++++++++++++++++++ ext/jni/src/c/sqlite3-jni.h | 8 ++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 5 +++++ ext/jni/src/org/sqlite/jni/Tester1.java | 14 ++++++++++++++ manifest | 18 +++++++++--------- manifest.uuid | 2 +- 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index e63c86a1a4..74a518c6e6 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -4279,6 +4279,25 @@ S3JniApi(sqlite3_trace_v2(),jint,1trace_1v2)( return rc; } +S3JniApi(sqlite3_txn_state(),jint,1txn_1state)( + JniArgsEnvClass,jobject jDb, jstring jSchema +){ + sqlite3 * const pDb = PtrGet_sqlite3(jDb); + int rc = SQLITE_MISUSE; + if( pDb ){ + char * zSchema = jSchema + ? s3jni_jstring_to_utf8(jSchema, 0) + : 0; + if( !jSchema || (zSchema && jSchema) ){ + rc = sqlite3_txn_state(pDb, zSchema); + sqlite3_free(zSchema); + }else{ + rc = SQLITE_NOMEM; + } + } + return rc; +} + S3JniApi(sqlite3_update_hook(),jobject,1update_1hook)( JniArgsEnvClass, jobject jDb, jobject jHook ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index a5454d54c7..90dc9ea260 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1699,6 +1699,14 @@ JNIEXPORT jlong JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1total_1changes64 JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1trace_1v2 (JNIEnv *, jclass, jobject, jint, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_txn_state + * Signature: (Lorg/sqlite/jni/sqlite3;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1txn_1state + (JNIEnv *, jclass, jobject, jstring); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_update_hook diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index c45f50b002..30078f9085 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1424,6 +1424,11 @@ public final class SQLite3Jni { @NotNull sqlite3 db, int traceMask, @Nullable TraceV2Callback tracer ); + @Canonical + public static native int sqlite3_txn_state( + @NotNull sqlite3 db, @Nullable String zSchema + ); + @Canonical public static native UpdateHookCallback sqlite3_update_hook( @NotNull sqlite3 db, @Nullable UpdateHookCallback hook diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index a99cc1f9d5..a9672acca5 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1396,6 +1396,20 @@ public class Tester1 implements Runnable { sqlite3_close_v2(db); } + private void testTxnState(){ + sqlite3 db = createNewDb(); + affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); + execSql(db, "BEGIN;"); + affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); + execSql(db, "SELECT * FROM sqlite_schema;"); + affirm( SQLITE_TXN_READ == sqlite3_txn_state(db, "main") ); + execSql(db, "CREATE TABLE t(a);"); + affirm( SQLITE_TXN_WRITE == sqlite3_txn_state(db, null) ); + execSql(db, "ROLLBACK;"); + affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); + sqlite3_close_v2(db); + } + @ManualTest /* we really only want to run this test manually. */ private void testSleep(){ out("Sleeping briefly... "); diff --git a/manifest b/manifest index ef1d301e64..816796d1e6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sJNI\scleanups. -D 2023-08-31T18:34:43.613 +C Export\ssqlite3_txn_state()\sto\sJNI. +D 2023-08-31T19:35:59.499 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 07b1b48cbc192b4316adf9581412fb280634e87eaf55302f529611b3f49e1c6c -F ext/jni/src/c/sqlite3-jni.h d9ea1662cefe7d8a2737cdbc55799a7e407cbc2239769f486d8eb33b68b9f133 +F ext/jni/src/c/sqlite3-jni.c 6f66f0855f4adc908151d1d4072dd51423f70311b308e7040ca30ecd6d26224b +F ext/jni/src/c/sqlite3-jni.h d82c8b503d19a539bdc5ad6d495e8aaf0d04d3e330ab75a7a402734194908590 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java d00a2409ab76cae168927e2ca6a7ffbd0621a42547cce88768b4eeebc13827e0 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java ffabb0a0ed7f35cfdea41502888b1c616b7e9b262afd9f2cace527b7a7ec0631 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 04163ebc06213bef77ac9c1cdb66d10e6f1fdcc1fc7a8628629529e1ee2c5940 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 96fefa219302e3e82f720baf082533fed98e6d31fe8887db5e14c150f1d2b3c1 +F ext/jni/src/org/sqlite/jni/Tester1.java ca145b97e0cd5c39d5745dfa5ab7cf595a89b4b1f40dfb1928f4f6e79d3c0851 F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d @@ -2116,8 +2116,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 faf4e6d398f444d970be8b1364c984c67ccbc5f8a27f3aa93f05b8a8de7bec9b -R 67c1ebfb718bb21974f4c19c81901b59 +P 2e2bb841ef8b53266ec48d8c3408d6396f29f17922e858eac1b4f12f4adeb05e +R 46c546f77881736213c45575c57e77e9 U stephan -Z 4fedefd0e23421552f6c24692e21e3ca +Z f333ee5f1318a9468223872999f97afe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d71724e89d..c7c212234d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e2bb841ef8b53266ec48d8c3408d6396f29f17922e858eac1b4f12f4adeb05e \ No newline at end of file +d732f71d0a292dbb493f79f7c6ecd8a4effbfbc91453b1c54bdd9becf2d75bdb \ No newline at end of file From a4b47b034cdb604544278312b35eacf6ec0ed294 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 06:50:17 +0000 Subject: [PATCH 05/36] Expose sqlite3_stmt_explain(), sqlite3_stmt_isexplain(), and sqlite3_stmt_readonly() to JNI. FossilOrigin-Name: 208b786afe16eafaf0ce791f319a5e05f733a7b71ce1c542e1b83481b013ec38 --- ext/jni/src/c/sqlite3-jni.c | 48 ++++++++---------- ext/jni/src/c/sqlite3-jni.h | 24 +++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 11 +++++ ext/jni/src/org/sqlite/jni/Tester1.java | 36 ++++++++++++-- ext/jni/src/org/sqlite/jni/package-info.java | 51 +++++++++++++++++--- manifest | 20 ++++---- manifest.uuid | 2 +- 7 files changed, 143 insertions(+), 49 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 74a518c6e6..bc15212251 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -113,14 +113,6 @@ # define SQLITE_THREADSAFE 1 #endif -/* -** 2023-08-25: initial attempts at running with SQLITE_THREADSAFE=0 -** lead to as-yet-uninvestigated bad reference errors from JNI. -*/ -#if 0 && SQLITE_THREADSAFE==0 -# error "This code currently requires SQLITE_THREADSAFE!=0." -#endif - /**********************************************************************/ /* SQLITE_USE_... */ #ifndef SQLITE_USE_URI @@ -132,9 +124,11 @@ ** Which sqlite3.c we're using needs to be configurable to enable ** building against a custom copy, e.g. the SEE variant. We have to ** include sqlite3.c, as opposed to sqlite3.h, in order to get access -** to SQLITE_MAX_... and friends. This increases the rebuild time -** considerably but we need this in order to keep the exported values -** of SQLITE_MAX_... and SQLITE_LIMIT_... in sync with the C build. +** to some interal details like SQLITE_MAX_... and friends. This +** increases the rebuild time considerably but we need this in order +** to access some internal functionality and keep the to-Java-exported +** values of SQLITE_MAX_... and SQLITE_LIMIT_... in sync with the C +** build. */ #ifndef SQLITE_C # define SQLITE_C sqlite3.c @@ -452,7 +446,8 @@ struct S3JniDb { #endif S3JniDb * pNext /* Next entry in SJG.perDb.aFree */; }; -#define S3JniDb_clientdata_key "S3JniDb" + +static const char * const S3JniDb_clientdata_key = "S3JniDb"; #define S3JniDb_from_clientdata(pDb) \ (pDb ? sqlite3_get_clientdata(pDb, S3JniDb_clientdata_key) : 0) @@ -1463,36 +1458,23 @@ static S3JniDb * S3JniDb_alloc(JNIEnv * const env, jobject jDb){ ** Returns the S3JniDb object for the given org.sqlite.jni.sqlite3 ** object, or NULL if jDb is NULL, no pointer can be extracted ** from it, or no matching entry can be found. -** -** Requires locking the S3JniDb mutex. */ static S3JniDb * S3JniDb__from_java(JNIEnv * const env, jobject jDb){ S3JniDb * s = 0; sqlite3 * pDb = 0; - S3JniDb_mutex_enter; if( jDb ) pDb = PtrGet_sqlite3(jDb); s = S3JniDb_from_clientdata(pDb); - S3JniDb_mutex_leave; return s; } #define S3JniDb_from_java(jObject) S3JniDb__from_java(env,(jObject)) - -static S3JniDb * S3JniDb__from_java_unlocked(JNIEnv * const env, jobject jDb){ - sqlite3 * pDb = 0; - S3JniDb_mutex_assertLocker; - if( jDb ) pDb = PtrGet_sqlite3(jDb); - return S3JniDb_from_clientdata(pDb); -} -#define S3JniDb_from_java_unlocked(JDB) S3JniDb__from_java_unlocked(env, (JDB)) - /* ** S3JniDb finalizer for use with sqlite3_set_clientdata(). */ static void S3JniDb_xDestroy(void *p){ S3JniDeclLocal_env; S3JniDb * const ps = p; - assert( !ps->pNext ); + assert( !ps->pNext && "Else ps is already in the free-list."); S3JniDb_set_aside(ps); } @@ -2012,6 +1994,11 @@ static void udf_xInverse(sqlite3_context* cx, int argc, JniDecl(jint,JniNameSuffix)(JniArgsEnvClass, jobject pStmt, jint n){ \ return (jint)CName(PtrGet_sqlite3_stmt(pStmt), (int)n); \ } +/** Create a trivial JNI wrapper for (boolish-int CName(sqlite3_stmt*)). */ +#define WRAP_BOOL_STMT(JniNameSuffix,CName) \ + JniDecl(jboolean,JniNameSuffix)(JniArgsEnvClass, jobject pStmt){ \ + return CName(PtrGet_sqlite3_stmt(pStmt)) ? JNI_TRUE : JNI_FALSE; \ + } /** Create a trivial JNI wrapper for (jstring CName(sqlite3_stmt*,int)). */ #define WRAP_STR_STMT_INT(JniNameSuffix,CName) \ JniDecl(jstring,JniNameSuffix)(JniArgsEnvClass, jobject pStmt, jint ndx){ \ @@ -2061,6 +2048,9 @@ WRAP_INT_DB(1preupdate_1depth, sqlite3_preupdate_depth) WRAP_INT_INT(1release_1memory, sqlite3_release_memory) WRAP_INT_INT(1sleep, sqlite3_sleep) WRAP_MUTF8_VOID(1sourceid, sqlite3_sourceid) +WRAP_INT_STMT_INT(1stmt_1explain, sqlite3_stmt_explain) +WRAP_INT_STMT(1stmt_1isexplain, sqlite3_stmt_isexplain) +WRAP_BOOL_STMT(1stmt_1readonly, sqlite3_stmt_readonly) WRAP_INT_VOID(1threadsafe, sqlite3_threadsafe) WRAP_INT_DB(1total_1changes, sqlite3_total_changes) WRAP_INT64_DB(1total_1changes64, sqlite3_total_changes64) @@ -2513,7 +2503,7 @@ S3JniApi(sqlite3_collation_needed(),jint,1collation_1needed)( int rc = 0; S3JniDb_mutex_enter; - ps = S3JniDb_from_java_unlocked(jDb); + ps = S3JniDb_from_java(jDb); if( !ps ){ S3JniDb_mutex_leave; return SQLITE_MISUSE; @@ -2655,7 +2645,7 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env, S3JniHook * pHook; S3JniDb_mutex_enter; - ps = S3JniDb_from_java_unlocked(jDb); + ps = S3JniDb_from_java(jDb); if( !ps ){ s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0); S3JniDb_mutex_leave; @@ -2878,7 +2868,7 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(), S3JniDb * ps; S3JniDb_mutex_enter; - ps = S3JniDb_from_java_unlocked(jDb); + ps = S3JniDb_from_java(jDb); if( !ps ){ rc = SQLITE_MISUSE; }else{ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 90dc9ea260..f987d1b52b 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1643,6 +1643,30 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1status64 JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1step (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_stmt_explain + * Signature: (Lorg/sqlite/jni/sqlite3_stmt;I)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1explain + (JNIEnv *, jclass, jobject, jint); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_stmt_isexplain + * Signature: (Lorg/sqlite/jni/sqlite3_stmt;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1isexplain + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_stmt_readonly + * Signature: (Lorg/sqlite/jni/sqlite3_stmt;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1readonly + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_strglob diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 30078f9085..54ed4f35e0 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1325,6 +1325,17 @@ public final class SQLite3Jni { @Canonical public static native int sqlite3_step(@NotNull sqlite3_stmt stmt); + @Canonical + public static native int sqlite3_stmt_explain( + @NotNull sqlite3_stmt stmt, int op + ); + + @Canonical + public static native int sqlite3_stmt_isexplain(@NotNull sqlite3_stmt stmt); + + @Canonical + public static native boolean sqlite3_stmt_readonly(@NotNull sqlite3_stmt stmt); + /** Internal impl of the public sqlite3_strglob() method. Neither argument may be NULL and both MUST be NUL-terminated UTF-8. diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index a9672acca5..4bd7e42ed6 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -192,7 +192,7 @@ public class Tester1 implements Runnable { static sqlite3_stmt prepare(sqlite3 db, boolean throwOnError, String sql){ final OutputPointer.sqlite3_stmt outStmt = new OutputPointer.sqlite3_stmt(); - int rc = sqlite3_prepare(db, sql, outStmt); + int rc = sqlite3_prepare_v2(db, sql, outStmt); if( throwOnError ){ affirm( 0 == rc ); } @@ -203,9 +203,11 @@ public class Tester1 implements Runnable { } return rv; } + static sqlite3_stmt prepare(sqlite3 db, String sql){ return prepare(db, true, sql); } + private void showCompileOption(){ int i = 0; String optName; @@ -260,6 +262,7 @@ public class Tester1 implements Runnable { affirm(0 == rc); sqlite3_stmt stmt = outStmt.take(); affirm(0 != stmt.getNativePointer()); + affirm( !sqlite3_stmt_readonly(stmt) ); affirm( db == sqlite3_db_handle(stmt) ); rc = sqlite3_step(stmt); if( SQLITE_DONE != rc ){ @@ -360,6 +363,7 @@ public class Tester1 implements Runnable { affirm(sqlite3_changes64(db) > changes64); affirm(sqlite3_total_changes64(db) > changesT64); stmt = prepare(db, "SELECT a FROM t ORDER BY a DESC;"); + affirm( sqlite3_stmt_readonly(stmt) ); int total2 = 0; while( SQLITE_ROW == sqlite3_step(stmt) ){ total2 += sqlite3_column_int(stmt, 0); @@ -1362,7 +1366,7 @@ public class Tester1 implements Runnable { private void testColumnMetadata(){ - sqlite3 db = createNewDb(); + final sqlite3 db = createNewDb(); execSql(db, new String[] { "CREATE TABLE t(a duck primary key not null collate noCase); ", "INSERT INTO t(a) VALUES(1),(2),(3);" @@ -1397,7 +1401,7 @@ public class Tester1 implements Runnable { } private void testTxnState(){ - sqlite3 db = createNewDb(); + final sqlite3 db = createNewDb(); affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); execSql(db, "BEGIN;"); affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); @@ -1410,6 +1414,32 @@ public class Tester1 implements Runnable { sqlite3_close_v2(db); } + + private void testExplain(){ + final sqlite3 db = createNewDb(); + sqlite3_stmt stmt = prepare(db,"SELECT 1"); + + affirm( 0 == sqlite3_stmt_isexplain(stmt) ); + int rc = sqlite3_stmt_explain(stmt, 1); + affirm( 1 == sqlite3_stmt_isexplain(stmt) ); + rc = sqlite3_stmt_explain(stmt, 2); + affirm( 2 == sqlite3_stmt_isexplain(stmt) ); + sqlite3_finalize(stmt); + + + sqlite3_close_v2(db); + } + + /* Copy/paste/rename this to add new tests. */ + private void _testTemplate(){ + final sqlite3 db = createNewDb(); + sqlite3_stmt stmt = prepare(db,"SELECT 1"); + + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + } + + @ManualTest /* we really only want to run this test manually. */ private void testSleep(){ out("Sleeping briefly... "); diff --git a/ext/jni/src/org/sqlite/jni/package-info.java b/ext/jni/src/org/sqlite/jni/package-info.java index 2ca997955a..21fdef27d7 100644 --- a/ext/jni/src/org/sqlite/jni/package-info.java +++ b/ext/jni/src/org/sqlite/jni/package-info.java @@ -1,19 +1,58 @@ /** This package houses a JNI binding to the SQLite3 C API. -

The docs are in progress. +

The primary interfaces are in {@link + org.sqlite.jni.SQLite3Jni}.

-

The primary interfaces are in {@link org.sqlite.jni.SQLite3Jni}. +

API Goals and Requirements

+ +
    + +
  • A 1-to-1(-ish) mapping of the C API to Java via JNI, insofar + as cross-language semantics allow for. A closely-related goal is + that the C + documentation should be usable as-is, insofar as possible, + for most of the JNI binding. As a rule, undocumented symbols + behave as documented for their C API counterpart, and only + semantic differences are documented here.
  • + +
  • Support Java as far back as version 8 (2014).
  • + +
  • Environment-independent. Should work everywhere both Java and + SQLite3 do.
  • + +
  • No 3rd-party dependencies beyond the JDK. That includes no + build-level dependencies for specific IDEs and toolchains. We + welcome the addition of build files for arbitrary environments + insofar as they neither interfere with each other nor become a + maintenance burden for the sqlite developers.
  • + +
+ +

Non-Goals

+ +
    + +
  • Creation of high-level OO wrapper APIs. Clients are free to + create them off of the C-style API.
  • + +
  • Support for mixed-mode operation, where client code accesses + SQLite both via the Java-side API and the C API via their own + native code. In such cases, proxy functionalities (primarily + callback handler wrappers of all sorts) may fail because the + C-side use of the SQLite APIs will bypass those proxies.
  • + +

State of this API

As of version 3.43, this software is in "tech preview" form. We - tentatively plan to stamp it as stable with the 3.44 release. + tentatively plan to stamp it as stable with the 3.44 release.

Threading Considerations

This API is, if built with SQLITE_THREADSAFE set to 1 or 2, - thread-safe, insofar as the C API guarantees, with some addenda: + thread-safe, insofar as the C API guarantees, with some addenda:

    @@ -39,11 +78,11 @@

    Any number of threads may, of course, create and use any number of database handles they wish. Care only needs to be taken when - those handles or their associated resources cross threads, or... + those handles or their associated resources cross threads, or...

    When built with SQLITE_THREADSAFE=0 then no threading guarantees are provided and multi-threaded use of the library will provoke - undefined behavior. + undefined behavior.

    */ package org.sqlite.jni; diff --git a/manifest b/manifest index 816796d1e6..b92bb1d075 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Export\ssqlite3_txn_state()\sto\sJNI. -D 2023-08-31T19:35:59.499 +C Expose\ssqlite3_stmt_explain(),\ssqlite3_stmt_isexplain(),\sand\ssqlite3_stmt_readonly()\sto\sJNI. +D 2023-09-01T06:50:17.074 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 6f66f0855f4adc908151d1d4072dd51423f70311b308e7040ca30ecd6d26224b -F ext/jni/src/c/sqlite3-jni.h d82c8b503d19a539bdc5ad6d495e8aaf0d04d3e330ab75a7a402734194908590 +F ext/jni/src/c/sqlite3-jni.c 6342a09eb10c46835b4b3ea84f1cfaeb9e7e720c0c15c7405fb18bfc62f9cc0f +F ext/jni/src/c/sqlite3-jni.h 3546b35d31fe3c13697edf3a3c35871941283de1d4f189154456ca61fd1282f6 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java d00a2409ab76cae168927e2ca6a7ffbd0621a42547cce88768b4eeebc13827e0 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7c F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 04163ebc06213bef77ac9c1cdb66d10e6f1fdcc1fc7a8628629529e1ee2c5940 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java af43be2c0795e22ca489d9237697cf743a9338860ba937ea689cd1810bf737ee F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java ca145b97e0cd5c39d5745dfa5ab7cf595a89b4b1f40dfb1928f4f6e79d3c0851 +F ext/jni/src/org/sqlite/jni/Tester1.java 891255bbaac87893fafe3b0109f6dbc9329c2accfd5b5c7a0b2bd9d874810ede F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d @@ -279,7 +279,7 @@ F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed F ext/jni/src/org/sqlite/jni/fts5_api.java ee47f1837d32968f7bb62278c7504c0fb572a68ec107371b714578312e9f734b F ext/jni/src/org/sqlite/jni/fts5_extension_function.java ac825035d7d83fc7fd960347abfa6803e1614334a21533302041823ad5fc894c F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 -F ext/jni/src/org/sqlite/jni/package-info.java 73f7821c240e4d116f164e87b613c5836b8a33ce2666967a29d9acb1ced7ca92 +F ext/jni/src/org/sqlite/jni/package-info.java 016cda6582ffb7af976455360f0730bf075a0ef4ef9d561f7646790c951e1504 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_context.java 66ca95ce904044263a4aff684abe262d56f73e6b06bca6cf650761d79d7779ad F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc @@ -2116,8 +2116,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 2e2bb841ef8b53266ec48d8c3408d6396f29f17922e858eac1b4f12f4adeb05e -R 46c546f77881736213c45575c57e77e9 +P d732f71d0a292dbb493f79f7c6ecd8a4effbfbc91453b1c54bdd9becf2d75bdb +R d6cbdc791e6b94495eeb2607a5aa6bb1 U stephan -Z f333ee5f1318a9468223872999f97afe +Z d7105d8e3faee08846ef7fd47243b17f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c7c212234d..e873e09de2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d732f71d0a292dbb493f79f7c6ecd8a4effbfbc91453b1c54bdd9becf2d75bdb \ No newline at end of file +208b786afe16eafaf0ce791f319a5e05f733a7b71ce1c542e1b83481b013ec38 \ No newline at end of file From 55171a75ef01eb4dcaebb14e9eb8facecc284327 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 09:43:56 +0000 Subject: [PATCH 06/36] JNI build improvements. Rename a Java class. Get the jar target working again. FossilOrigin-Name: d086b7844cace5c997261c97565aeef62aaeeef727ccc7e83f17c54d6217b779 --- ext/jni/GNUmakefile | 101 +++++++++++------- ext/jni/src/c/sqlite3-jni.c | 22 ++-- .../org/sqlite/jni/AuthorizerCallback.java | 2 +- .../org/sqlite/jni/AutoExtensionCallback.java | 2 +- .../org/sqlite/jni/BusyHandlerCallback.java | 2 +- ...3CallbackProxy.java => CallbackProxy.java} | 2 +- .../src/org/sqlite/jni/CollationCallback.java | 2 +- .../sqlite/jni/CollationNeededCallback.java | 2 +- .../org/sqlite/jni/CommitHookCallback.java | 2 +- .../org/sqlite/jni/PreupdateHookCallback.java | 2 +- .../sqlite/jni/ProgressHandlerCallback.java | 2 +- .../org/sqlite/jni/RollbackHookCallback.java | 2 +- ext/jni/src/org/sqlite/jni/Tester1.java | 28 +++-- .../src/org/sqlite/jni/TraceV2Callback.java | 2 +- .../org/sqlite/jni/UpdateHookCallback.java | 2 +- ext/jni/src/org/sqlite/jni/package-info.java | 7 +- manifest | 42 ++++---- manifest.uuid | 2 +- 18 files changed, 136 insertions(+), 90 deletions(-) rename ext/jni/src/org/sqlite/jni/{SQLite3CallbackProxy.java => CallbackProxy.java} (97%) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index fe53f36a03..02998569a2 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -31,6 +31,13 @@ mkdir := mkdir -p $(dir.bld.c): $(mkdir) $@ +javac.flags ?= -Xlint:unchecked -Xlint:deprecation +java.flags ?= +jnicheck ?= 1 +ifeq (1,$(jnicheck)) + java.flags += -Xcheck:jni +endif + classpath := $(dir.src) CLEAN_FILES := $(package.jar) DISTCLEAN_FILES := $(dir.jni)/*~ $(dir.src.c)/*~ $(dir.src.jni)/*~ @@ -47,7 +54,7 @@ SQLTester.class := $(SQLTester.java:.java=.class) # It would be a real doozy to bind to JNI. enable.fts5 ?= 1 # If enable.tester is 0, the org/sqlite/jni/tester/* bits are elided. -enable.tester ?= 1 +enable.tester ?= $(if $(wildcard $(dir.src.jni.tester)/SQLTester.java),1,0) # bin.version-info = binary to output various sqlite3 version info # building the distribution zip file. @@ -62,7 +69,6 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\ annotation/Canonical.java \ annotation/NotNull.java \ annotation/Nullable.java \ - annotation/package-info.java \ AbstractCollationCallback.java \ AggregateFunction.java \ AuthorizerCallback.java \ @@ -80,20 +86,22 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\ RollbackHookCallback.java \ ScalarFunction.java \ SQLFunction.java \ + CallbackProxy.java \ SQLite3Jni.java \ TableColumnMetadata.java \ - Tester1.java \ TraceV2Callback.java \ UpdateHookCallback.java \ ValueHolder.java \ WindowFunction.java \ XDestroyCallback.java \ - package-info.java \ sqlite3.java \ sqlite3_context.java \ sqlite3_stmt.java \ sqlite3_value.java \ ) +JAVA_FILES.unittest := $(patsubst %,$(dir.src.jni)/%,\ + Tester1.java \ +) ifeq (1,$(enable.fts5)) JAVA_FILES.main += $(patsubst %,$(dir.src.jni)/%,\ fts5_api.java \ @@ -109,32 +117,30 @@ ifeq (1,$(enable.fts5)) ) endif JAVA_FILES.tester := $(dir.src.jni.tester)/SQLTester.java +JAVA_FILES.package.info := \ + $(dir.src.jni)/package-info.java \ + $(dir.src.jni)/annotation/package-info.java CLASS_FILES.main := $(JAVA_FILES.main:.java=.class) +CLASS_FILES.unittest := $(JAVA_FILES.unittest:.java=.class) CLASS_FILES.tester := $(JAVA_FILES.tester:.java=.class) -JAVA_FILES += $(JAVA_FILES.main) +JAVA_FILES += $(JAVA_FILES.main) $(JAVA_FILES.unittest) ifeq (1,$(enable.tester)) JAVA_FILES += $(JAVA_FILES.tester) endif CLASS_FILES := -define DOTCLASS_DEPS -$(1).class: $(1).java $(MAKEFILE) +define CLASSFILE_DEPS all: $(1).class CLASS_FILES += $(1).class endef -$(foreach B,$(basename $(JAVA_FILES)),$(eval $(call DOTCLASS_DEPS,$(B)))) -$(CLASS_FILES.tester): $(CLASS_FILES.main) -javac.flags ?= -Xlint:unchecked -Xlint:deprecation -java.flags ?= -jnicheck ?= 1 -ifeq (1,$(jnicheck)) - java.flags += -Xcheck:jni -endif -$(SQLite3Jni.class): $(JAVA_FILES) +$(foreach B,$(basename \ + $(JAVA_FILES.main) $(JAVA_FILES.unittest) $(JAVA_FILES.tester)),\ + $(eval $(call CLASSFILE_DEPS,$(B)))) +$(CLASS_FILES): $(JAVA_FILES) $(MAKEFILE) $(bin.javac) $(javac.flags) -h $(dir.bld.c) -cp $(classpath) $(JAVA_FILES) -all: $(SQLite3Jni.class) + #.PHONY: classfiles ######################################################################## @@ -199,13 +205,18 @@ endif sqlite3-jni.c := $(dir.src.c)/sqlite3-jni.c sqlite3-jni.o := $(dir.bld.c)/sqlite3-jni.o sqlite3-jni.h := $(dir.src.c)/sqlite3-jni.h -sqlite3-jni.dll := $(dir.bld.c)/libsqlite3-jni.so +package.dll := $(dir.bld.c)/libsqlite3-jni.so # All javac-generated .h files must be listed in $(sqlite3-jni.h.in): sqlite3-jni.h.in := +# $(java.with.jni) lists all Java files which contain JNI decls: +java.with.jni := define ADD_JNI_H sqlite3-jni.h.in += $$(dir.bld.c)/org_sqlite_jni_$(1).h +java.with.jni += $$(dir.src.jni)/$(1).java $$(dir.bld.c)/org_sqlite_jni_$(1).h: $$(dir.src.jni)/$(1).java endef +# Invoke ADD_JNI_H once for each Java file which includes JNI +# declarations: $(eval $(call ADD_JNI_H,SQLite3Jni)) ifeq (1,$(enable.fts5)) $(eval $(call ADD_JNI_H,Fts5ExtensionApi)) @@ -216,8 +227,10 @@ ifeq (1,$(enable.tester)) sqlite3-jni.h.in += $(dir.bld.c)/org_sqlite_jni_tester_SQLTester.h $(dir.bld.c)/org_sqlite_jni_tester_SQLTester.h: $(dir.src.jni.tester)/SQLTester.java endif -#sqlite3-jni.dll.cfiles := $(dir.src.c) -sqlite3-jni.dll.cflags = \ +$(sqlite3-jni.h.in): $(dir.bld.c) + +#package.dll.cfiles := +package.dll.cflags = \ -fPIC \ -I. \ -I$(dir $(sqlite3.h)) \ @@ -234,22 +247,30 @@ sqlite3-jni.dll.cflags = \ # include path for client-level code. ######################################################################## ifeq (1,$(enable.tester)) - sqlite3-jni.dll.cflags += -DSQLITE_JNI_ENABLE_SQLTester + package.dll.cflags += -DSQLITE_JNI_ENABLE_SQLTester endif $(sqlite3-jni.h): $(sqlite3-jni.h.in) $(MAKEFILE) - cat $(sqlite3-jni.h.in) > $@ -$(sqlite3-jni.dll): $(sqlite3-jni.h) $(sqlite3.c) $(sqlite3.h) -$(sqlite3-jni.dll): $(dir.bld.c) $(sqlite3-jni.c) $(SQLite3Jni.java) $(MAKEFILE) - $(CC) $(sqlite3-jni.dll.cflags) $(SQLITE_OPT) \ + @cat $(sqlite3-jni.h.in) > $@.tmp + @if cmp $@ $@.tmp; then \ + rm -f $@.tmp; \ + echo "$@ not modified"; \ + else \ + mv $@.tmp $@; \ + echo "Updated $@"; \ + fi + +$(package.dll): $(sqlite3-jni.h) $(sqlite3.c) $(sqlite3.h) +$(package.dll): $(sqlite3-jni.c) $(MAKEFILE) + $(CC) $(package.dll.cflags) $(SQLITE_OPT) \ $(sqlite3-jni.c) -shared -o $@ -all: $(sqlite3-jni.dll) +all: $(package.dll) .PHONY: test test-one test.flags ?= test.main.flags = -ea -Djava.library.path=$(dir.bld.c) \ $(java.flags) -cp $(classpath) \ org.sqlite.jni.Tester1 -test.deps := $(SQLite3Jni.class) $(sqlite3-jni.dll) +test.deps := $(CLASS_FILES) $(package.dll) test-one: $(test.deps) $(bin.java) $(test.main.flags) $(test.flags) test-sqllog: $(test.deps) @@ -257,7 +278,7 @@ test-sqllog: $(test.deps) $(bin.java) $(test.main.flags) -sqllog test-mt: $(test.deps) @echo "Testing in multi-threaded mode:"; - $(bin.java) $(test.main.flags) -t 11 -r 50 -shuffle $(test.flags) + $(bin.java) $(test.main.flags) -t 7 -r 50 -shuffle $(test.flags) test: test-one test-mt tests: test test-sqllog @@ -266,7 +287,7 @@ tester.scripts := $(sort $(wildcard $(dir.src)/tests/*.test)) tester.flags ?= # --verbose .PHONY: tester tester-local tester-ext ifeq (1,$(enable.tester)) -tester-local: $(CLASS_FILES.tester) $(sqlite3-jni.dll) +tester-local: $(CLASS_FILES.tester) $(package.dll) $(bin.java) -ea -Djava.library.path=$(dir.bld.c) \ $(java.flags) -cp $(classpath) \ org.sqlite.jni.tester.SQLTester $(tester.flags) $(tester.scripts) @@ -313,16 +334,24 @@ multitest: clean # jar bundle... package.jar.in := $(abspath $(dir.src)/jar.in) CLEAN_FILES += $(package.jar.in) -$(package.jar.in): $(MAKEFILE) $(CLASS_FILES.main) - cd $(dir.src); ls -1 org/sqlite/jni/*.java org/sqlite/jni/*.class > $@ - @echo "To use this jar you will need the -Djava.library.path=DIR/CONTAINING/libsqlite3-jni.so flag." - @echo "e.g. java -jar $@ -Djava.library.path=bld" +JAVA_FILES.jar := $(JAVA_FILES.main) $(JAVA_FILES.unittest) $(JAVA_FILES.package.info) +CLASS_FILES.jar := $(filter-out %/package-info.class,$(JAVA_FILES.jar:.java=.class)) +$(package.jar.in): $(package.dll) $(MAKEFILE) + ls -1 \ + $(dir.src.jni)/*.java $(dir.src.jni)/*.class \ + $(dir.src.jni)/annotation/*.java $(dir.src.jni)/annotation/*.class \ + | sed -e 's,^$(dir.src)/,,' | sort > $@ -$(package.jar): $(CLASS_FILES) $(MAKEFILE) $(package.jar.in) - rm -f $(dir.src)/c/*~ $(dir.src.jni)/*~ +$(package.jar): $(CLASS_FILES.jar) $(MAKEFILE) $(package.jar.in) + @rm -f $(dir.src)/c/*~ $(dir.src.jni)/*~ cd $(dir.src); $(bin.jar) -cfe ../$@ org.sqlite.jni.Tester1 @$(package.jar.in) + @ls -la $@ + @echo "To use this jar you will need the -Djava.library.path=DIR/CONTAINING/libsqlite3-jni.so flag." + @echo "e.g. java -Djava.library.path=bld -jar $@" jar: $(package.jar) +run-jar: $(package.jar) $(package.dll) + $(bin.java) -Djava.library.path=$(dir.bld) -jar $(package.jar) $(run-jar.flags) ######################################################################## # javadoc... @@ -349,7 +378,7 @@ docserve: $(doc.index) CLEAN_FILES += $(dir.bld.c)/* \ $(dir.src.jni)/*.class \ $(dir.src.jni.tester)/*.class \ - $(sqlite3-jni.dll) \ + $(package.dll) \ hs_err_pid*.log .PHONY: clean distclean diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index bc15212251..8e654a1b28 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -266,6 +266,7 @@ static void * s3jni_realloc_or_die(JNIEnv * const env, void * p, size_t n){ #else #define s3jni_oom_check(EXPR) #endif +//#define S3JniDb_oom(pDb,EXPR) ((EXPR) ? sqlite3OomFault(pDb) : 0) /* Helpers for Java value reference management. */ static jobject s3jni_ref_global(JNIEnv * const env, jobject const v){ @@ -317,8 +318,8 @@ static const struct { const S3JniNphRef OutputPointer_sqlite3; const S3JniNphRef OutputPointer_sqlite3_stmt; const S3JniNphRef OutputPointer_sqlite3_value; -#ifdef SQLITE_ENABLE_FTS5 const S3JniNphRef OutputPointer_String; +#ifdef SQLITE_ENABLE_FTS5 const S3JniNphRef OutputPointer_ByteArray; const S3JniNphRef Fts5Context; const S3JniNphRef Fts5ExtensionApi; @@ -346,8 +347,8 @@ static const struct { "Lorg/sqlite/jni/sqlite3_stmt;"), RefO(9, "OutputPointer$sqlite3_value", "Lorg/sqlite/jni/sqlite3_value;"), -#ifdef SQLITE_ENABLE_FTS5 RefO(10, "OutputPointer$String", "Ljava/lang/String;"), +#ifdef SQLITE_ENABLE_FTS5 RefO(11, "OutputPointer$ByteArray", "[B"), RefN(12, "Fts5Context"), RefN(13, "Fts5ExtensionApi"), @@ -413,6 +414,10 @@ static const S3JniHook S3JniHook_empty = {0,0,0,0,0}; ** Per-(sqlite3*) state for various JNI bindings. This state is ** allocated as needed, cleaned up in sqlite3_close(_v2)(), and ** recycled when possible. +** +** Trivia: vars and parameters of this type are often named "ps" +** because this class used to have a name for which that abbreviation +** made sense. */ typedef struct S3JniDb S3JniDb; struct S3JniDb { @@ -453,6 +458,10 @@ static const char * const S3JniDb_clientdata_key = "S3JniDb"; /* ** Cache for per-JNIEnv (i.e. per-thread) data. +** +** Trivia: vars and parameters of this type are often named "jc" +** because this class used to have a name for which that abbreviation +** made sense. */ typedef struct S3JniEnv S3JniEnv; struct S3JniEnv { @@ -1460,11 +1469,8 @@ static S3JniDb * S3JniDb_alloc(JNIEnv * const env, jobject jDb){ ** from it, or no matching entry can be found. */ static S3JniDb * S3JniDb__from_java(JNIEnv * const env, jobject jDb){ - S3JniDb * s = 0; - sqlite3 * pDb = 0; - if( jDb ) pDb = PtrGet_sqlite3(jDb); - s = S3JniDb_from_clientdata(pDb); - return s; + sqlite3 * const pDb = jDb ? PtrGet_sqlite3(jDb) : 0; + return pDb ? S3JniDb_from_clientdata(pDb) : 0; } #define S3JniDb_from_java(jObject) S3JniDb__from_java(env,(jObject)) @@ -4259,7 +4265,7 @@ S3JniApi(sqlite3_trace_v2(),jint,1trace_1v2)( rc = sqlite3_trace_v2(ps->pDb, (unsigned)traceMask, s3jni_trace_impl, ps); if( 0==rc ){ S3JniHook_unref(&ps->hooks.trace); - ps->hooks.trace = hook; + ps->hooks.trace = hook /* transfer ownership of reference */; }else{ S3JniHook_unref(&hook); } diff --git a/ext/jni/src/org/sqlite/jni/AuthorizerCallback.java b/ext/jni/src/org/sqlite/jni/AuthorizerCallback.java index a9f15fc6c2..6dbd9cb77b 100644 --- a/ext/jni/src/org/sqlite/jni/AuthorizerCallback.java +++ b/ext/jni/src/org/sqlite/jni/AuthorizerCallback.java @@ -17,7 +17,7 @@ import org.sqlite.jni.annotation.*; /** Callback for use with {@link SQLite3Jni#sqlite3_set_authorizer}. */ -public interface AuthorizerCallback extends SQLite3CallbackProxy { +public interface AuthorizerCallback extends CallbackProxy { /** Must function as described for the C-level sqlite3_set_authorizer() callback. diff --git a/ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java b/ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java index 1f8ace2fb8..4a36941306 100644 --- a/ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java +++ b/ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java @@ -17,7 +17,7 @@ package org.sqlite.jni; Callback for use with the {@link SQLite3Jni#sqlite3_auto_extension} family of APIs. */ -public interface AutoExtensionCallback extends SQLite3CallbackProxy { +public interface AutoExtensionCallback extends CallbackProxy { /** Must function as described for a C-level sqlite3_auto_extension() callback. diff --git a/ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java b/ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java index db9295bb61..30a5edc037 100644 --- a/ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java +++ b/ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_busy_handler}. */ -public interface BusyHandlerCallback extends SQLite3CallbackProxy { +public interface BusyHandlerCallback extends CallbackProxy { /** Must function as documented for the C-level sqlite3_busy_handler() callback argument, minus the (void*) diff --git a/ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java b/ext/jni/src/org/sqlite/jni/CallbackProxy.java similarity index 97% rename from ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java rename to ext/jni/src/org/sqlite/jni/CallbackProxy.java index 5052664937..086c2f8e5d 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java +++ b/ext/jni/src/org/sqlite/jni/CallbackProxy.java @@ -41,4 +41,4 @@ package org.sqlite.jni;

    2) They all have a {@code call()} method but its signature is callback-specific. */ -public interface SQLite3CallbackProxy {} +public interface CallbackProxy {} diff --git a/ext/jni/src/org/sqlite/jni/CollationCallback.java b/ext/jni/src/org/sqlite/jni/CollationCallback.java index 481c6cd956..7f0e79a3fa 100644 --- a/ext/jni/src/org/sqlite/jni/CollationCallback.java +++ b/ext/jni/src/org/sqlite/jni/CollationCallback.java @@ -20,7 +20,7 @@ import org.sqlite.jni.annotation.NotNull; @see AbstractCollationCallback */ public interface CollationCallback - extends SQLite3CallbackProxy, XDestroyCallback { + extends CallbackProxy, XDestroyCallback { /** Must compare the given byte arrays and return the result using {@code memcmp()} semantics. diff --git a/ext/jni/src/org/sqlite/jni/CollationNeededCallback.java b/ext/jni/src/org/sqlite/jni/CollationNeededCallback.java index e6c917a2c2..b72cf1ba53 100644 --- a/ext/jni/src/org/sqlite/jni/CollationNeededCallback.java +++ b/ext/jni/src/org/sqlite/jni/CollationNeededCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_collation_needed}. */ -public interface CollationNeededCallback extends SQLite3CallbackProxy { +public interface CollationNeededCallback extends CallbackProxy { /** Has the same semantics as the C-level sqlite3_create_collation() callback. diff --git a/ext/jni/src/org/sqlite/jni/CommitHookCallback.java b/ext/jni/src/org/sqlite/jni/CommitHookCallback.java index 253d0b8cfa..2e9a68d25d 100644 --- a/ext/jni/src/org/sqlite/jni/CommitHookCallback.java +++ b/ext/jni/src/org/sqlite/jni/CommitHookCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_commit_hook}. */ -public interface CommitHookCallback extends SQLite3CallbackProxy { +public interface CommitHookCallback extends CallbackProxy { /** Works as documented for the C-level sqlite3_commit_hook() callback. Must not throw. diff --git a/ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java b/ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java index b68dd4b6d4..a606139328 100644 --- a/ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java +++ b/ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_preupdate_hook}. */ -public interface PreupdateHookCallback extends SQLite3CallbackProxy { +public interface PreupdateHookCallback extends CallbackProxy { /** Must function as described for the C-level sqlite3_preupdate_hook() callback. diff --git a/ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java b/ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java index d15bf31a11..bc15377037 100644 --- a/ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java +++ b/ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_progress_handler}. */ -public interface ProgressHandlerCallback extends SQLite3CallbackProxy { +public interface ProgressHandlerCallback extends CallbackProxy { /** Works as documented for the C-level sqlite3_progress_handler() callback. diff --git a/ext/jni/src/org/sqlite/jni/RollbackHookCallback.java b/ext/jni/src/org/sqlite/jni/RollbackHookCallback.java index 3bf9f79a1a..21600c8057 100644 --- a/ext/jni/src/org/sqlite/jni/RollbackHookCallback.java +++ b/ext/jni/src/org/sqlite/jni/RollbackHookCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_rollback_hook}. */ -public interface RollbackHookCallback extends SQLite3CallbackProxy { +public interface RollbackHookCallback extends CallbackProxy { /** Works as documented for the C-level sqlite3_rollback_hook() callback. diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 4bd7e42ed6..f47b5944a4 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -74,9 +74,15 @@ public class Tester1 implements Runnable { } } - public synchronized static void outln(Object val){ + public synchronized static void outPrefix(){ if( !quietMode ){ System.out.print(Thread.currentThread().getName()+": "); + } + } + + public synchronized static void outln(Object val){ + if( !quietMode ){ + outPrefix(); System.out.println(val); } } @@ -90,7 +96,7 @@ public class Tester1 implements Runnable { @SuppressWarnings("unchecked") public synchronized static void out(Object... vals){ if( !quietMode ){ - System.out.print(Thread.currentThread().getName()+": "); + outPrefix(); for(Object v : vals) out(v); } } @@ -429,7 +435,7 @@ public class Tester1 implements Runnable { sqlite3 db = createNewDb(); execSql(db, "CREATE TABLE t(a)"); sqlite3_stmt stmt = prepare(db, "INSERT INTO t(a) VALUES(?);"); - String[] list1 = { "hell🤩", "w😃rld", "!" }; + String[] list1 = { "hell🤩", "w😃rld", "!🤩" }; int rc; int n = 0; for( String e : list1 ){ @@ -450,14 +456,16 @@ public class Tester1 implements Runnable { final String txt = sqlite3_column_text16(stmt, 0); sbuf.append( txt ); affirm( txt.equals(sqlite3_column_text(stmt, 0)) ); + affirm( txt.length() < sqlite3_value_bytes(sv) ); affirm( txt.equals(sqlite3_value_text(sv)) ); + affirm( txt.length() == sqlite3_value_bytes16(sv)/2 ); affirm( txt.equals(sqlite3_value_text16(sv)) ); sqlite3_value_free(sv); ++n; } sqlite3_finalize(stmt); affirm(3 == n); - affirm("w😃rldhell🤩!".equals(sbuf.toString())); + affirm("w😃rldhell🤩!🤩".equals(sbuf.toString())); sqlite3_close_v2(db); } @@ -1655,18 +1663,20 @@ public class Tester1 implements Runnable { sqlite3_libversion_number(),"\n", sqlite3_libversion(),"\n",SQLITE_SOURCE_ID,"\n", "SQLITE_THREADSAFE=",SQLITE_THREADSAFE); - outln("Running ",nRepeat," loop(s) with ",nThread," thread(s) each."); + final boolean showLoopCount = (nRepeat>1 && nThread>1); + if( showLoopCount ){ + outln("Running ",nRepeat," loop(s) with ",nThread," thread(s) each."); + } if( takeNaps ) outln("Napping between tests is enabled."); for( int n = 0; n < nRepeat; ++n ){ ++nLoop; - out((1==nLoop ? "" : " ")+nLoop); + if( showLoopCount ) out((1==nLoop ? "" : " ")+nLoop); if( nThread<=1 ){ new Tester1(0).runTests(false); continue; } Tester1.mtMode = true; final ExecutorService ex = Executors.newFixedThreadPool( nThread ); - //final List> futures = new ArrayList<>(); for( int i = 0; i < nThread; ++i ){ ex.submit( new Tester1(i), i ); } @@ -1689,7 +1699,7 @@ public class Tester1 implements Runnable { if( null!=err ) throw err; } } - outln(); + if( showLoopCount ) outln(); quietMode = false; final long timeEnd = System.currentTimeMillis(); @@ -1706,7 +1716,7 @@ public class Tester1 implements Runnable { final java.lang.reflect.Method[] declaredMethods = SQLite3Jni.class.getDeclaredMethods(); for(java.lang.reflect.Method m : declaredMethods){ - int mod = m.getModifiers(); + final int mod = m.getModifiers(); if( 0!=(mod & java.lang.reflect.Modifier.STATIC) ){ final String name = m.getName(); if(name.startsWith("sqlite3_")){ diff --git a/ext/jni/src/org/sqlite/jni/TraceV2Callback.java b/ext/jni/src/org/sqlite/jni/TraceV2Callback.java index 897aeefa9f..4e69bd8756 100644 --- a/ext/jni/src/org/sqlite/jni/TraceV2Callback.java +++ b/ext/jni/src/org/sqlite/jni/TraceV2Callback.java @@ -17,7 +17,7 @@ import org.sqlite.jni.annotation.Nullable; /** Callback for use with {@link SQLite3Jni#sqlite3_trace_v2}. */ -public interface TraceV2Callback extends SQLite3CallbackProxy { +public interface TraceV2Callback extends CallbackProxy { /** Called by sqlite3 for various tracing operations, as per sqlite3_trace_v2(). Note that this interface elides the 2nd diff --git a/ext/jni/src/org/sqlite/jni/UpdateHookCallback.java b/ext/jni/src/org/sqlite/jni/UpdateHookCallback.java index 4fd0a63240..4d6afb887f 100644 --- a/ext/jni/src/org/sqlite/jni/UpdateHookCallback.java +++ b/ext/jni/src/org/sqlite/jni/UpdateHookCallback.java @@ -16,7 +16,7 @@ package org.sqlite.jni; /** Callback for use with {@link SQLite3Jni#sqlite3_update_hook}. */ -public interface UpdateHookCallback extends SQLite3CallbackProxy { +public interface UpdateHookCallback extends CallbackProxy { /** Must function as described for the C-level sqlite3_update_hook() callback. diff --git a/ext/jni/src/org/sqlite/jni/package-info.java b/ext/jni/src/org/sqlite/jni/package-info.java index 21fdef27d7..853d76fd73 100644 --- a/ext/jni/src/org/sqlite/jni/package-info.java +++ b/ext/jni/src/org/sqlite/jni/package-info.java @@ -12,9 +12,10 @@ as cross-language semantics allow for. A closely-related goal is that the C documentation should be usable as-is, insofar as possible, - for most of the JNI binding. As a rule, undocumented symbols - behave as documented for their C API counterpart, and only - semantic differences are documented here. + for most of the JNI binding. As a rule, undocumented symbols in + the Java interface behave as documented for their C API + counterpart. Only semantic differences and Java-specific features + are documented here.

  • Support Java as far back as version 8 (2014).
  • diff --git a/manifest b/manifest index b92bb1d075..146b8b4def 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_stmt_explain(),\ssqlite3_stmt_isexplain(),\sand\ssqlite3_stmt_readonly()\sto\sJNI. -D 2023-09-01T06:50:17.074 +C JNI\sbuild\simprovements.\sRename\sa\sJava\sclass.\sGet\sthe\sjar\starget\sworking\sagain. +D 2023-09-01T09:43:56.871 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,19 +234,20 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile b6ae6d04cc33f2300ab7177bd5db1ecfbc8627f76fee6aec441f980e57594291 +F ext/jni/GNUmakefile c6100f8855f9f533466d75e031a458875003c5b5cc01fe9a34581d55f0048119 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 6342a09eb10c46835b4b3ea84f1cfaeb9e7e720c0c15c7405fb18bfc62f9cc0f +F ext/jni/src/c/sqlite3-jni.c 94092d07a8a5df2cb66f4ac04a28d150ed29361a7aec82776bfdd3f1a3b947e8 F ext/jni/src/c/sqlite3-jni.h 3546b35d31fe3c13697edf3a3c35871941283de1d4f189154456ca61fd1282f6 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 -F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java d00a2409ab76cae168927e2ca6a7ffbd0621a42547cce88768b4eeebc13827e0 -F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java 1470e14d09f10729d35568506c6e61318edfb17aa322802e386764fa6d582f14 -F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java cd12c26dafd3e6c097fc73f80d328aebac0f58b985f66a96ee567ddf8d195f30 -F ext/jni/src/org/sqlite/jni/CollationCallback.java 7d5b246f1a7c9d6b8e974d970bbbb2d05c6264e65448d7be6a85edbf703c823d -F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 1707b50146c6b805b79e84f89a57c8dbb0134e431799f041f0bec403eca5f841 -F ext/jni/src/org/sqlite/jni/CommitHookCallback.java e4de82c97560982e996e358958268e1e4e307b6115cd9aac0ff4f947d4380d90 +F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 +F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java 5e4a75611c026730289d776469d6122cb2699d6970af5f53fe85e74d49930476 +F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java d316373b12b3bf1a421f1f7eed08128fa8dd52bb98617ba28c161aaabd71d1ee +F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153 w ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java +F ext/jni/src/org/sqlite/jni/CollationCallback.java df327348e1a34ee65210208d694d690e5ee0bfe901410122e07caf6c98b2b7c8 +F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b81154295258037f662e7c372735c2899c76e81cb3abd9fd3b39 +F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 F ext/jni/src/org/sqlite/jni/Fts5.java 3ebfbd5b95fdb9d7bc40306f2e682abd12e247d9224e92510b8dd103b4f96fe8 F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 @@ -256,19 +257,18 @@ F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d F ext/jni/src/org/sqlite/jni/OutputPointer.java 1f2319976fff206f5056eafc8a4f48d43abe09d5d1b5287ba9145a95d847cbb7 -F ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java 500c968b3893edbddf67e8eb773852c3a8ae58097a77bd22320ada6b1af06db1 -F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 0da841810319f5a9dc372d0f2348930d54fac1a4b53e4298884f44c720d67830 +F ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java eccaed8dc9c6289f07ef3fc109891c6be1e7cc6c88723d90174b68706fc21cda +F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c57eeedcd8447e9e3b6e5d0f5e5d3eb0f0c5037d48d F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 -F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java 16042be9d072a26dbb2f1b1b63e7639989b747bb80d2bd667ba4f7555f56a825 +F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java c2748ab52856075b053a55b317988d95dc7fb4d3d42520f8c33573effe1cd185 F ext/jni/src/org/sqlite/jni/SQLite3Jni.java af43be2c0795e22ca489d9237697cf743a9338860ba937ea689cd1810bf737ee F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 891255bbaac87893fafe3b0109f6dbc9329c2accfd5b5c7a0b2bd9d874810ede +F ext/jni/src/org/sqlite/jni/Tester1.java 3de9259606b40576e8a87dd28b228bbd077cccb518afec101246a14acd258c5f F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 -F ext/jni/src/org/sqlite/jni/TraceV2Callback.java 641926b05a772c2c05c842a81aa839053ba4a13b78ef04b402f5705d060c6246 -F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java be2bc96ff4f56b3c1fd18ae7dba9b207b25b6c123b8a5fd2f7aaf3cc208d8b7d +F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 +F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 @@ -279,7 +279,7 @@ F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed F ext/jni/src/org/sqlite/jni/fts5_api.java ee47f1837d32968f7bb62278c7504c0fb572a68ec107371b714578312e9f734b F ext/jni/src/org/sqlite/jni/fts5_extension_function.java ac825035d7d83fc7fd960347abfa6803e1614334a21533302041823ad5fc894c F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 -F ext/jni/src/org/sqlite/jni/package-info.java 016cda6582ffb7af976455360f0730bf075a0ef4ef9d561f7646790c951e1504 +F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_context.java 66ca95ce904044263a4aff684abe262d56f73e6b06bca6cf650761d79d7779ad F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc @@ -2116,8 +2116,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 d732f71d0a292dbb493f79f7c6ecd8a4effbfbc91453b1c54bdd9becf2d75bdb -R d6cbdc791e6b94495eeb2607a5aa6bb1 +P 208b786afe16eafaf0ce791f319a5e05f733a7b71ce1c542e1b83481b013ec38 +R 2b0398aeaa0204ef877d7a162bfccfd2 U stephan -Z d7105d8e3faee08846ef7fd47243b17f +Z 4d9595c68497abda167c9e1929e109f6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e873e09de2..3679ee2ff0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -208b786afe16eafaf0ce791f319a5e05f733a7b71ce1c542e1b83481b013ec38 \ No newline at end of file +d086b7844cace5c997261c97565aeef62aaeeef727ccc7e83f17c54d6217b779 \ No newline at end of file From 03ca59afb909f9fdeb251fc069e28ac8cdb0e031 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 10:32:31 +0000 Subject: [PATCH 07/36] Expose sqlite3_limit() to JNI and remove the all SQLITE_ macros from the Java interface which are not directly exposed to client-level C code (SQLITE_MAX_... and SQLITE_THREADSAFE_...). FossilOrigin-Name: 5fe5b0a585dbfa06cfca1fea40aea5ea3ccfe8295f41306ad2d5b851ace27203 --- ext/jni/src/c/sqlite3-jni.c | 84 ++++++++----------- ext/jni/src/c/sqlite3-jni.h | 32 +++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 50 ++++------- ext/jni/src/org/sqlite/jni/Tester1.java | 27 ++++-- .../org/sqlite/jni/annotation/Canonical.java | 4 +- manifest | 22 ++--- manifest.uuid | 2 +- 7 files changed, 117 insertions(+), 104 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 8e654a1b28..4151551a5a 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -291,7 +291,7 @@ static inline void s3jni_unref_local(JNIEnv * const env, jobject const v){ #define S3JniUnrefLocal(VAR) s3jni_unref_local(env, (VAR)) /* -** Key type for use with S3JniGlobal_nph(). +** Lookup key type for use with s3jni_nph(). */ typedef struct S3JniNphRef S3JniNphRef; struct S3JniNphRef { @@ -304,7 +304,7 @@ struct S3JniNphRef { /* ** Cache keys for each concrete NativePointerHolder subclass and ** OutputPointer.T type. The members are to be used with -** S3JniGlobal_nph() and friends, and each one's member->index +** s3jni_nph() and friends, and each one's member->index ** corresponds to its index in the S3JniGlobal.nph[] array. */ static const struct { @@ -375,7 +375,7 @@ enum { /* ** Cache entry for NativePointerHolder subclasses and OutputPointer ** types. The pRef and klazz fields are set up the first time the -** entry is fetched using S3JniGlobal_nph(). The other fields are +** entry is fetched using s3jni_nph(). The other fields are ** populated as needed by the routines which use them. */ typedef struct S3JniNphClass S3JniNphClass; @@ -1282,12 +1282,11 @@ static int S3JniEnv_uncache(JNIEnv * const env){ } /* -** Searches the NativePointerHolder cache for the given combination of -** args. It returns a cache entry with its klazz member set. This is -** an O(1) operation except on the first call for a given pRef, during -** which pRef->klazz and pRef->pRef are initialized thread-safely. In -** the latter case it's still effectively O(1), but with a much longer -** 1. +** Fetches the given nph-ref from cache the cache and returns the +** object with its klazz member set. This is an O(1) operation except +** on the first call for a given pRef, during which pRef->klazz and +** pRef->pRef are initialized thread-safely. In the latter case it's +** still effectively O(1), but with a much longer 1. ** ** It is up to the caller to populate the other members of the ** returned object if needed, taking care to lock the modification @@ -1296,7 +1295,7 @@ static int S3JniEnv_uncache(JNIEnv * const env){ ** This simple cache catches >99% of searches in the current ** (2023-07-31) tests. */ -static S3JniNphClass * S3JniGlobal__nph(JNIEnv * const env, S3JniNphRef const* pRef){ +static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ /** According to: @@ -1333,7 +1332,7 @@ static S3JniNphClass * S3JniGlobal__nph(JNIEnv * const env, S3JniNphRef const* p return pNC; } -#define S3JniGlobal_nph(PREF) S3JniGlobal__nph(env, PREF) +#define s3jni_nph(PRef) s3jni__nph(env, PRef) /* ** Common code for accessor functions for NativePointerHolder and @@ -1348,7 +1347,7 @@ static S3JniNphClass * S3JniGlobal__nph(JNIEnv * const env, S3JniNphRef const* p ** Property lookups are cached on a per-pRef basis. */ static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphRef const* pRef){ - S3JniNphClass * const pNC = S3JniGlobal_nph(pRef); + S3JniNphClass * const pNC = s3jni_nph(pRef); if( !pNC->fidValue ){ S3JniNph_mutex_enter; @@ -1665,7 +1664,7 @@ static void ResultJavaValue_finalizer(void *v){ static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef const * pRef, const void * pNative){ jobject rv = 0; - S3JniNphClass * const pNC = S3JniGlobal_nph(pRef); + S3JniNphClass * const pNC = s3jni_nph(pRef); if( !pNC->midCtor ){ S3JniNph_mutex_enter; if( !pNC->midCtor ){ @@ -1816,7 +1815,7 @@ static int udf_args(JNIEnv *env, *jArgv = 0; if( !jcx ) goto error_oom; ja = (*env)->NewObjectArray( - env, argc, S3JniGlobal_nph(&S3JniNphRefs.sqlite3_value)->klazz, + env, argc, s3jni_nph(&S3JniNphRefs.sqlite3_value)->klazz, NULL); s3jni_oom_check( ja ); if( !ja ) goto error_oom; @@ -3216,6 +3215,17 @@ S3JniApi(sqlite3_last_insert_rowid(),jlong,1last_1insert_1rowid)( return rc; } +S3JniApi(sqlite3_limit(),jint,1limit)( + JniArgsEnvClass, jobject jpDb, jint id, jint newVal +){ + jint rc = 0; + sqlite3 * const pDb = PtrGet_sqlite3(jpDb); + if( pDb ){ + rc = sqlite3_limit( pDb, (int)id, (int)newVal ); + } + return rc; +} + /* Pre-open() code common to sqlite3_open[_v2](). */ static int s3jni_open_pre(JNIEnv * const env, S3JniEnv **jc, jstring jDbName, char **zDbName, @@ -4400,7 +4410,7 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ SO(S3JniHook); SO(S3JniDb); SO(S3JniNphRefs); - printf("\t(^^^ %u NativePointerHolder subclasses)\n", + printf("\t(^^^ %u NativePointerHolder/OutputPointer.T types)\n", (unsigned)S3Jni_NphCache_size); SO(S3JniGlobal); SO(S3JniAutoExtension); @@ -5270,39 +5280,13 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ const char *zName; enum JType jtype; int value; - } ConfigFlagEntry; - const ConfigFlagEntry aLimits[] = { - {"SQLITE_MAX_ALLOCATION_SIZE", JTYPE_INT, SQLITE_MAX_ALLOCATION_SIZE}, - {"SQLITE_LIMIT_LENGTH", JTYPE_INT, SQLITE_LIMIT_LENGTH}, - {"SQLITE_MAX_LENGTH", JTYPE_INT, SQLITE_MAX_LENGTH}, - {"SQLITE_LIMIT_SQL_LENGTH", JTYPE_INT, SQLITE_LIMIT_SQL_LENGTH}, - {"SQLITE_MAX_SQL_LENGTH", JTYPE_INT, SQLITE_MAX_SQL_LENGTH}, - {"SQLITE_LIMIT_COLUMN", JTYPE_INT, SQLITE_LIMIT_COLUMN}, - {"SQLITE_MAX_COLUMN", JTYPE_INT, SQLITE_MAX_COLUMN}, - {"SQLITE_LIMIT_EXPR_DEPTH", JTYPE_INT, SQLITE_LIMIT_EXPR_DEPTH}, - {"SQLITE_MAX_EXPR_DEPTH", JTYPE_INT, SQLITE_MAX_EXPR_DEPTH}, - {"SQLITE_LIMIT_COMPOUND_SELECT", JTYPE_INT, SQLITE_LIMIT_COMPOUND_SELECT}, - {"SQLITE_MAX_COMPOUND_SELECT", JTYPE_INT, SQLITE_MAX_COMPOUND_SELECT}, - {"SQLITE_LIMIT_VDBE_OP", JTYPE_INT, SQLITE_LIMIT_VDBE_OP}, - {"SQLITE_MAX_VDBE_OP", JTYPE_INT, SQLITE_MAX_VDBE_OP}, - {"SQLITE_LIMIT_FUNCTION_ARG", JTYPE_INT, SQLITE_LIMIT_FUNCTION_ARG}, - {"SQLITE_MAX_FUNCTION_ARG", JTYPE_INT, SQLITE_MAX_FUNCTION_ARG}, - {"SQLITE_LIMIT_ATTACHED", JTYPE_INT, SQLITE_LIMIT_ATTACHED}, - {"SQLITE_MAX_ATTACHED", JTYPE_INT, SQLITE_MAX_ATTACHED}, - {"SQLITE_LIMIT_LIKE_PATTERN_LENGTH", JTYPE_INT, SQLITE_LIMIT_LIKE_PATTERN_LENGTH}, - {"SQLITE_MAX_LIKE_PATTERN_LENGTH", JTYPE_INT, SQLITE_MAX_LIKE_PATTERN_LENGTH}, - {"SQLITE_LIMIT_VARIABLE_NUMBER", JTYPE_INT, SQLITE_LIMIT_VARIABLE_NUMBER}, - {"SQLITE_MAX_VARIABLE_NUMBER", JTYPE_INT, SQLITE_MAX_VARIABLE_NUMBER}, - {"SQLITE_LIMIT_TRIGGER_DEPTH", JTYPE_INT, SQLITE_LIMIT_TRIGGER_DEPTH}, - {"SQLITE_MAX_TRIGGER_DEPTH", JTYPE_INT, SQLITE_MAX_TRIGGER_DEPTH}, - {"SQLITE_LIMIT_WORKER_THREADS", JTYPE_INT, SQLITE_LIMIT_WORKER_THREADS}, - {"SQLITE_MAX_WORKER_THREADS", JTYPE_INT, SQLITE_MAX_WORKER_THREADS}, - {"SQLITE_THREADSAFE", JTYPE_INT, SQLITE_THREADSAFE}, + } DefineEntry; + const DefineEntry aLimits[] = { {0,0} }; jfieldID fieldId; jclass klazz; - const ConfigFlagEntry * pConfFlag; + const DefineEntry * pDef; #if 0 if( 0==sqlite3_threadsafe() ){ @@ -5376,18 +5360,18 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ ** sqlite3_config(), if it's ever implemented. */; /* Set up static "consts" of the SQLite3Jni class. */ - for( pConfFlag = &aLimits[0]; pConfFlag->zName; ++pConfFlag ){ - char const * zSig = (JTYPE_BOOL == pConfFlag->jtype) ? "Z" : "I"; - fieldId = (*env)->GetStaticFieldID(env, jKlazz, pConfFlag->zName, zSig); + for( pDef = &aLimits[0]; pDef->zName; ++pDef ){ + char const * zSig = (JTYPE_BOOL == pDef->jtype) ? "Z" : "I"; + fieldId = (*env)->GetStaticFieldID(env, jKlazz, pDef->zName, zSig); S3JniExceptionIsFatal("Missing an expected static member of the SQLite3Jni class."); assert(fieldId); - switch( pConfFlag->jtype ){ + switch( pDef->jtype ){ case JTYPE_INT: - (*env)->SetStaticIntField(env, jKlazz, fieldId, (jint)pConfFlag->value); + (*env)->SetStaticIntField(env, jKlazz, fieldId, (jint)pDef->value); break; case JTYPE_BOOL: (*env)->SetStaticBooleanField(env, jKlazz, fieldId, - pConfFlag->value ? JNI_TRUE : JNI_FALSE); + pDef->value ? JNI_TRUE : JNI_FALSE); break; } S3JniExceptionIsFatal("Seting a static member of the SQLite3Jni class failed."); diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index f987d1b52b..1c9e4a641c 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -379,6 +379,30 @@ extern "C" { #define org_sqlite_jni_SQLite3Jni_SQLITE_IOCAP_IMMUTABLE 8192L #undef org_sqlite_jni_SQLite3Jni_SQLITE_IOCAP_BATCH_ATOMIC #define org_sqlite_jni_SQLite3Jni_SQLITE_IOCAP_BATCH_ATOMIC 16384L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_LENGTH +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_LENGTH 0L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_SQL_LENGTH +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_SQL_LENGTH 1L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_COLUMN +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_COLUMN 2L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_EXPR_DEPTH +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_EXPR_DEPTH 3L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_COMPOUND_SELECT +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_COMPOUND_SELECT 4L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_VDBE_OP +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_VDBE_OP 5L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_FUNCTION_ARG +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_FUNCTION_ARG 6L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_ATTACHED +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_ATTACHED 7L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_LIKE_PATTERN_LENGTH +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_VARIABLE_NUMBER +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_VARIABLE_NUMBER 9L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_TRIGGER_DEPTH +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_TRIGGER_DEPTH 10L +#undef org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_WORKER_THREADS +#define org_sqlite_jni_SQLite3Jni_SQLITE_LIMIT_WORKER_THREADS 11L #undef org_sqlite_jni_SQLite3Jni_SQLITE_OPEN_READONLY #define org_sqlite_jni_SQLite3Jni_SQLITE_OPEN_READONLY 1L #undef org_sqlite_jni_SQLite3Jni_SQLITE_OPEN_READWRITE @@ -1315,6 +1339,14 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1libversion JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1libversion_1number (JNIEnv *, jclass); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_limit + * Signature: (Lorg/sqlite/jni/sqlite3;II)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1limit + (JNIEnv *, jclass, jobject, jint, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_open diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 54ed4f35e0..e6eafa0bef 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -669,6 +669,9 @@ public final class SQLite3Jni { @Canonical public static native int sqlite3_libversion_number(); + @Canonical + public static native int sqlite3_limit(@NotNull sqlite3 db, int id, int newVal); + /** Works like its C counterpart and makes the native pointer of the underling (sqlite3*) object available via @@ -1557,10 +1560,6 @@ public final class SQLite3Jni { public static final String SQLITE_VERSION = sqlite3_libversion(); public static final String SQLITE_SOURCE_ID = sqlite3_sourceid(); - // Initialized at static init time to the build-time value of - // SQLITE_THREADSAFE. - public static int SQLITE_THREADSAFE = -1; - // access public static final int SQLITE_ACCESS_EXISTS = 0; public static final int SQLITE_ACCESS_READWRITE = 1; @@ -1773,36 +1772,19 @@ public final class SQLite3Jni { public static final int SQLITE_IOCAP_IMMUTABLE = 8192; public static final int SQLITE_IOCAP_BATCH_ATOMIC = 16384; - // limits. These get injected at init-time so that they stay in sync - // with the compile-time options. This unfortunately means they are - // not final, but keeping them in sync with their C values seems - // more important than protecting users from assigning to these - // (with unpredictable results). - public static int SQLITE_MAX_ALLOCATION_SIZE = -1; - public static int SQLITE_LIMIT_LENGTH = -1; - public static int SQLITE_MAX_LENGTH = -1; - public static int SQLITE_LIMIT_SQL_LENGTH = -1; - public static int SQLITE_MAX_SQL_LENGTH = -1; - public static int SQLITE_LIMIT_COLUMN = -1; - public static int SQLITE_MAX_COLUMN = -1; - public static int SQLITE_LIMIT_EXPR_DEPTH = -1; - public static int SQLITE_MAX_EXPR_DEPTH = -1; - public static int SQLITE_LIMIT_COMPOUND_SELECT = -1; - public static int SQLITE_MAX_COMPOUND_SELECT = -1; - public static int SQLITE_LIMIT_VDBE_OP = -1; - public static int SQLITE_MAX_VDBE_OP = -1; - public static int SQLITE_LIMIT_FUNCTION_ARG = -1; - public static int SQLITE_MAX_FUNCTION_ARG = -1; - public static int SQLITE_LIMIT_ATTACHED = -1; - public static int SQLITE_MAX_ATTACHED = -1; - public static int SQLITE_LIMIT_LIKE_PATTERN_LENGTH = -1; - public static int SQLITE_MAX_LIKE_PATTERN_LENGTH = -1; - public static int SQLITE_LIMIT_VARIABLE_NUMBER = -1; - public static int SQLITE_MAX_VARIABLE_NUMBER = -1; - public static int SQLITE_LIMIT_TRIGGER_DEPTH = -1; - public static int SQLITE_MAX_TRIGGER_DEPTH = -1; - public static int SQLITE_LIMIT_WORKER_THREADS = -1; - public static int SQLITE_MAX_WORKER_THREADS = -1; + // limits + public static final int SQLITE_LIMIT_LENGTH = 0; + public static final int SQLITE_LIMIT_SQL_LENGTH = 1; + public static final int SQLITE_LIMIT_COLUMN = 2; + public static final int SQLITE_LIMIT_EXPR_DEPTH = 3; + public static final int SQLITE_LIMIT_COMPOUND_SELECT = 4; + public static final int SQLITE_LIMIT_VDBE_OP = 5; + public static final int SQLITE_LIMIT_FUNCTION_ARG = 6; + public static final int SQLITE_LIMIT_ATTACHED = 7; + public static final int SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8; + public static final int SQLITE_LIMIT_VARIABLE_NUMBER = 9; + public static final int SQLITE_LIMIT_TRIGGER_DEPTH = 10; + public static final int SQLITE_LIMIT_WORKER_THREADS = 11; // open flags public static final int SQLITE_OPEN_READONLY = 1; diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index f47b5944a4..5d3623f677 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -125,8 +125,6 @@ public class Tester1 implements Runnable { @ManualTest /* because testing this for threading is pointless */ private void test1(){ affirm(sqlite3_libversion_number() == SQLITE_VERSION_NUMBER); - affirm(SQLITE_MAX_LENGTH > 0); - affirm(SQLITE_MAX_TRIGGER_DEPTH>0); } static sqlite3 createNewDb(){ @@ -1438,6 +1436,17 @@ public class Tester1 implements Runnable { sqlite3_close_v2(db); } + private void testLimit(){ + final sqlite3 db = createNewDb(); + + int v1, v2; + v1 = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1); + affirm( v1 > 0 ); + affirm( v1 == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, v1-1) ); + affirm( v1-1 == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1) ); + sqlite3_close_v2(db); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); @@ -1636,7 +1645,7 @@ public class Tester1 implements Runnable { final long timeStart = System.currentTimeMillis(); int nLoop = 0; - switch( SQLITE_THREADSAFE ){ /* Sanity checking */ + switch( sqlite3_threadsafe() ){ /* Sanity checking */ case 0: affirm( SQLITE_ERROR==sqlite3_config( SQLITE_CONFIG_SINGLETHREAD ), "Could not switch to single-thread mode." ); @@ -1662,7 +1671,7 @@ public class Tester1 implements Runnable { outln("libversion_number: ", sqlite3_libversion_number(),"\n", sqlite3_libversion(),"\n",SQLITE_SOURCE_ID,"\n", - "SQLITE_THREADSAFE=",SQLITE_THREADSAFE); + "SQLITE_THREADSAFE=",sqlite3_threadsafe()); final boolean showLoopCount = (nRepeat>1 && nThread>1); if( showLoopCount ){ outln("Running ",nRepeat," loop(s) with ",nThread," thread(s) each."); @@ -1713,6 +1722,7 @@ public class Tester1 implements Runnable { sqlite3_shutdown(); int nMethods = 0; int nNatives = 0; + int nCanonical = 0; final java.lang.reflect.Method[] declaredMethods = SQLite3Jni.class.getDeclaredMethods(); for(java.lang.reflect.Method m : declaredMethods){ @@ -1721,6 +1731,9 @@ public class Tester1 implements Runnable { final String name = m.getName(); if(name.startsWith("sqlite3_")){ ++nMethods; + if( m.isAnnotationPresent( org.sqlite.jni.annotation.Canonical.class ) ){ + ++nCanonical; + } if( 0!=(mod & java.lang.reflect.Modifier.NATIVE) ){ ++nNatives; } @@ -1728,8 +1741,10 @@ public class Tester1 implements Runnable { } } outln("\tSQLite3Jni.sqlite3_*() methods: "+ - nNatives+" native methods and "+ - (nMethods - nNatives)+" Java impls"); + nNatives+" native methods, "+ + (nMethods - nNatives)+" Java impls. ", + nCanonical," methods flagged as canonical" + ); outln("\tTotal test time = " +(timeEnd - timeStart)+"ms"); } diff --git a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java index f329aee137..80164a4dda 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java +++ b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java @@ -20,14 +20,14 @@ package org.sqlite.jni.annotation; different name than its C counterpart. For such cases, (cname=the-C-side-name) is passed to this annotation and a Java-side implementation with a slightly different signature is - added to with the canonical name. As of this writing, that applies + added with the canonical name. As of this writing, that applies only to {@link org.sqlite.jni.SQLite3Jni#sqlite3_value_text_utf8} and {@link org.sqlite.jni.SQLite3Jni#sqlite3_column_text_utf8}.

    The comment property can be used to add a comment. */ @java.lang.annotation.Documented -@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) +@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface Canonical{ /** diff --git a/manifest b/manifest index 146b8b4def..141062e8f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C JNI\sbuild\simprovements.\sRename\sa\sJava\sclass.\sGet\sthe\sjar\starget\sworking\sagain. -D 2023-09-01T09:43:56.871 +C Expose\ssqlite3_limit()\sto\sJNI\sand\sremove\sthe\sall\sSQLITE_\smacros\sfrom\sthe\sJava\sinterface\swhich\sare\snot\sdirectly\sexposed\sto\sclient-level\sC\scode\s(SQLITE_MAX_...\sand\sSQLITE_THREADSAFE_...). +D 2023-09-01T10:32:31.300 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,14 +237,14 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile c6100f8855f9f533466d75e031a458875003c5b5cc01fe9a34581d55f0048119 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 94092d07a8a5df2cb66f4ac04a28d150ed29361a7aec82776bfdd3f1a3b947e8 -F ext/jni/src/c/sqlite3-jni.h 3546b35d31fe3c13697edf3a3c35871941283de1d4f189154456ca61fd1282f6 +F ext/jni/src/c/sqlite3-jni.c 3bcb7998a5a9bf109e7da6b151a4dbe612791fe9c6792ef4b95bbfe8a0144854 +F ext/jni/src/c/sqlite3-jni.h 383a357c8920e05ea2b6ca7f9548ee04a263319f018ef3daeeaa719727be8b72 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java 5e4a75611c026730289d776469d6122cb2699d6970af5f53fe85e74d49930476 F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java d316373b12b3bf1a421f1f7eed08128fa8dd52bb98617ba28c161aaabd71d1ee -F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153 w ext/jni/src/org/sqlite/jni/SQLite3CallbackProxy.java +F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153 F ext/jni/src/org/sqlite/jni/CollationCallback.java df327348e1a34ee65210208d694d690e5ee0bfe901410122e07caf6c98b2b7c8 F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b81154295258037f662e7c372735c2899c76e81cb3abd9fd3b39 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 @@ -262,17 +262,17 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java af43be2c0795e22ca489d9237697cf743a9338860ba937ea689cd1810bf737ee +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5a05c67b994d3f431d61203ab1de842d49491714e78cf99ccd5aa5257b66e9ff F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 3de9259606b40576e8a87dd28b228bbd077cccb518afec101246a14acd258c5f +F ext/jni/src/org/sqlite/jni/Tester1.java 95fd3d3c0068cd7ebf2e89bb7db16fba541e6cf872f64f08c1e1350f6585682b F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 -F ext/jni/src/org/sqlite/jni/annotation/Canonical.java e55b82c8259b617ff754ac493fd8b79602631d659b87a858b987540e4c4fdf56 +F ext/jni/src/org/sqlite/jni/annotation/Canonical.java ff9fc59004303d8ef89c516ede9ef5f51c881e9c9ba982f0ebb1bdd9a18550bc F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 @@ -2116,8 +2116,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 208b786afe16eafaf0ce791f319a5e05f733a7b71ce1c542e1b83481b013ec38 -R 2b0398aeaa0204ef877d7a162bfccfd2 +P d086b7844cace5c997261c97565aeef62aaeeef727ccc7e83f17c54d6217b779 +R d90a7f8c26c47365fc18117debd88806 U stephan -Z 4d9595c68497abda167c9e1929e109f6 +Z f88fe35f4fec8f41c283d1006f7f6aa6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3679ee2ff0..037d478b74 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d086b7844cace5c997261c97565aeef62aaeeef727ccc7e83f17c54d6217b779 \ No newline at end of file +5fe5b0a585dbfa06cfca1fea40aea5ea3ccfe8295f41306ad2d5b851ace27203 \ No newline at end of file From 7862e19468d9dc414585816f86a92bf97c936661 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 10:37:15 +0000 Subject: [PATCH 08/36] Remove some newly-dead code. FossilOrigin-Name: dc0fa76b395c5e352116dc33cc1b455e5e9c9f01c285af52ccba4d37e4453b87 --- ext/jni/GNUmakefile | 4 ++-- ext/jni/src/c/sqlite3-jni.c | 40 +------------------------------------ manifest | 14 ++++++------- manifest.uuid | 2 +- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 02998569a2..3e4d54fb05 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -175,7 +175,7 @@ $(sqlite3.h): $(sqlite3.c): $(sqlite3.h) opt.threadsafe ?= 1 -opt.oom ?= 0 +opt.fatal-oom ?= 1 SQLITE_OPT = \ -DSQLITE_ENABLE_RTREE \ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ @@ -193,7 +193,7 @@ SQLITE_OPT = \ -DSQLITE_TEMP_STORE=2 \ -DSQLITE_USE_URI=1 \ -DSQLITE_C=$(sqlite3.c) \ - -DSQLITE_JNI_FATAL_OOM=$(opt.oom) \ + -DSQLITE_JNI_FATAL_OOM=$(opt.fatal-oom) \ -DSQLITE_DEBUG SQLITE_OPT += -g -DDEBUG -UNDEBUG diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 4151551a5a..553886df6b 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -5272,28 +5272,8 @@ Java_org_sqlite_jni_tester_SQLTester_installCustomExtensions(JniArgsEnvClass){ */ JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ - enum JType { - JTYPE_INT, - JTYPE_BOOL - }; - typedef struct { - const char *zName; - enum JType jtype; - int value; - } DefineEntry; - const DefineEntry aLimits[] = { - {0,0} - }; - jfieldID fieldId; jclass klazz; - const DefineEntry * pDef; -#if 0 - if( 0==sqlite3_threadsafe() ){ - (*env)->FatalError(env, "sqlite3 currently requires SQLITE_THREADSAFE!=0."); - return; - } -#endif memset(&S3JniGlobal, 0, sizeof(S3JniGlobal)); if( (*env)->GetJavaVM(env, &SJG.jvm) ){ (*env)->FatalError(env, "GetJavaVM() failure shouldn't be possible."); @@ -5318,7 +5298,7 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ "getBytes", "(Ljava/nio/charset/Charset;)[B"); S3JniExceptionIsFatal("Error getting reference to String.getBytes(Charset)."); - { /* StandardCharsets.UTF_8 */ + { /* java.nio.charset.StandardCharsets.UTF_8 */ jfieldID fUtf8; klazz = (*env)->FindClass(env,"java/nio/charset/StandardCharsets"); S3JniExceptionIsFatal("Error getting reference to StandardCharsets class."); @@ -5358,22 +5338,4 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ sqlite3_shutdown() /* So that it becomes legal for Java-level code to call ** sqlite3_config(), if it's ever implemented. */; - - /* Set up static "consts" of the SQLite3Jni class. */ - for( pDef = &aLimits[0]; pDef->zName; ++pDef ){ - char const * zSig = (JTYPE_BOOL == pDef->jtype) ? "Z" : "I"; - fieldId = (*env)->GetStaticFieldID(env, jKlazz, pDef->zName, zSig); - S3JniExceptionIsFatal("Missing an expected static member of the SQLite3Jni class."); - assert(fieldId); - switch( pDef->jtype ){ - case JTYPE_INT: - (*env)->SetStaticIntField(env, jKlazz, fieldId, (jint)pDef->value); - break; - case JTYPE_BOOL: - (*env)->SetStaticBooleanField(env, jKlazz, fieldId, - pDef->value ? JNI_TRUE : JNI_FALSE); - break; - } - S3JniExceptionIsFatal("Seting a static member of the SQLite3Jni class failed."); - } } diff --git a/manifest b/manifest index 141062e8f8..85245e43d1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_limit()\sto\sJNI\sand\sremove\sthe\sall\sSQLITE_\smacros\sfrom\sthe\sJava\sinterface\swhich\sare\snot\sdirectly\sexposed\sto\sclient-level\sC\scode\s(SQLITE_MAX_...\sand\sSQLITE_THREADSAFE_...). -D 2023-09-01T10:32:31.300 +C Remove\ssome\snewly-dead\scode. +D 2023-09-01T10:37:15.903 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,10 +234,10 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile c6100f8855f9f533466d75e031a458875003c5b5cc01fe9a34581d55f0048119 +F ext/jni/GNUmakefile 591d05030e7fa787615d88fb5b7e8377e1e777612fce4d4eed9b595843f1d014 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 3bcb7998a5a9bf109e7da6b151a4dbe612791fe9c6792ef4b95bbfe8a0144854 +F ext/jni/src/c/sqlite3-jni.c 69a78f7f7b94b58e272184d005813322bad24ed78ea392563b657faa3cc56218 F ext/jni/src/c/sqlite3-jni.h 383a357c8920e05ea2b6ca7f9548ee04a263319f018ef3daeeaa719727be8b72 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -2116,8 +2116,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 d086b7844cace5c997261c97565aeef62aaeeef727ccc7e83f17c54d6217b779 -R d90a7f8c26c47365fc18117debd88806 +P 5fe5b0a585dbfa06cfca1fea40aea5ea3ccfe8295f41306ad2d5b851ace27203 +R e68a872b68a0b0146fb6e1b06b988d94 U stephan -Z f88fe35f4fec8f41c283d1006f7f6aa6 +Z 2904ef85d8a184bf73f88a40f15d384b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 037d478b74..1740a09513 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5fe5b0a585dbfa06cfca1fea40aea5ea3ccfe8295f41306ad2d5b851ace27203 \ No newline at end of file +dc0fa76b395c5e352116dc33cc1b455e5e9c9f01c285af52ccba4d37e4453b87 \ No newline at end of file From d086065644de5b90c40693d6823ad3cc518c5c76 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 13:27:59 +0000 Subject: [PATCH 09/36] Make JNI interfaces of sqlite3_column/value_text() match the C ones better. Internal JNI cleanups and simplifications. FossilOrigin-Name: eb24f97253d9c8e7c728c2ac67a0824b10ca67362ac4f8abb94d5d3c54c58c5b --- ext/jni/GNUmakefile | 29 ++- ext/jni/src/c/sqlite3-jni.c | 181 +++++++++--------- ext/jni/src/c/sqlite3-jni.h | 24 +-- ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 81 ++++---- ext/jni/src/org/sqlite/jni/Tester1.java | 23 ++- ext/jni/src/org/sqlite/jni/TesterFts5.java | 2 +- .../org/sqlite/jni/annotation/Canonical.java | 25 +-- manifest | 24 +-- manifest.uuid | 2 +- 9 files changed, 196 insertions(+), 195 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 3e4d54fb05..ae0c53f902 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -176,6 +176,7 @@ $(sqlite3.c): $(sqlite3.h) opt.threadsafe ?= 1 opt.fatal-oom ?= 1 +opt.debug ?= 1 SQLITE_OPT = \ -DSQLITE_ENABLE_RTREE \ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ @@ -193,10 +194,13 @@ SQLITE_OPT = \ -DSQLITE_TEMP_STORE=2 \ -DSQLITE_USE_URI=1 \ -DSQLITE_C=$(sqlite3.c) \ - -DSQLITE_JNI_FATAL_OOM=$(opt.fatal-oom) \ - -DSQLITE_DEBUG + -DSQLITE_JNI_FATAL_OOM=$(opt.fatal-oom) -SQLITE_OPT += -g -DDEBUG -UNDEBUG +ifeq (1,$(opt.debug)) + SQLITE_OPT += -DSQLITE_DEBUG -g -DDEBUG -UNDEBUG +else + SQLITE_OPT += -O2 +endif ifeq (1,$(enable.fts5)) SQLITE_OPT += -DSQLITE_ENABLE_FTS5 @@ -318,16 +322,21 @@ endif tester-ext: tester-local tester: tester-ext tests: tester - ######################################################################## # Build each SQLITE_THREADMODE variant and run all tests against them. multitest: clean - $(MAKE) opt.threadsafe=0 opt.oom=1 tests clean - $(MAKE) opt.threadsafe=0 opt.oom=0 tests clean - $(MAKE) opt.threadsafe=1 opt.oom=1 tests clean - $(MAKE) opt.threadsafe=1 opt.oom=0 tests clean - $(MAKE) opt.threadsafe=2 opt.oom=1 tests clean - $(MAKE) opt.threadsafe=2 opt.oom=0 tests clean +define MULTIOPT +multitest: multitest-$(1) +multitest-$(1): + $$(MAKE) opt.debug=$$(opt.debug) $(patsubst %,opt.%,$(2)) tests clean +endef + +$(eval $(call MULTIOPT,01,threadsafe=0 oom=1)) +$(eval $(call MULTIOPT,00,threadsafe=0 oom=0)) +$(eval $(call MULTIOPT,11,threadsafe=1 oom=1)) +$(eval $(call MULTIOPT,10,threadsafe=1 oom=0)) +$(eval $(call MULTIOPT,21,threadsafe=2 oom=1)) +$(eval $(call MULTIOPT,20,threadsafe=2 oom=0)) ######################################################################## diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 553886df6b..831a4d8001 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -170,7 +170,8 @@ ** S3JniApi's intent is that CFunc be the C API func(s) the ** being-declared JNI function is wrapping, making it easier to find ** that function's JNI-side entry point. The other args are for JniDecl. - */ +** See the many examples in this file. +*/ #define S3JniApi(CFunc,ReturnType,Suffix) JniDecl(ReturnType,Suffix) /* @@ -302,10 +303,10 @@ struct S3JniNphRef { }; /* -** Cache keys for each concrete NativePointerHolder subclass and -** OutputPointer.T type. The members are to be used with -** s3jni_nph() and friends, and each one's member->index -** corresponds to its index in the S3JniGlobal.nph[] array. +** Cache keys for each concrete NativePointerHolder subclasses and +** OutputPointer.T types. The members are to be used with s3jni_nph() +** and friends, and each one's member->index corresponds to its index +** in the S3JniGlobal.nph[] array. */ static const struct { const S3JniNphRef sqlite3; @@ -361,6 +362,8 @@ static const struct { #undef RefO }; +#define S3JniNph(T) &S3JniNphRefs.T + enum { /* ** Size of the NativePointerHolder cache. Need enough space for @@ -380,10 +383,24 @@ enum { */ typedef struct S3JniNphClass S3JniNphClass; struct S3JniNphClass { - volatile const S3JniNphRef * pRef /* Entry from S3JniNphRefs. */; - jclass klazz /* global ref to the concrete - ** NativePointerHolder subclass - ** represented by zClassName */; + volatile const S3JniNphRef * pRef /* Entry from S3JniNphRefs */; + /* + ** klazz is a global ref to the class represented by pRef. + ** + ** According to: + ** + ** https://developer.ibm.com/articles/j-jni/ + ** + ** > ... the IDs returned for a given class don't change for the + ** lifetime of the JVM process. But the call to get the field or + ** method can require significant work in the JVM, because fields + ** and methods might have been inherited from superclasses, making + ** the JVM walk up the class hierarchy to find them. Because the + ** IDs are the same for a given class, you should look them up + ** once and then reuse them. Similarly, looking up class objects + ** can be expensive, so they should be cached as well. + */ + jclass klazz; volatile jmethodID midCtor /* klazz's no-arg constructor. Used by ** new_NativePointerHolder_object(). */; volatile jfieldID fidValue /* NativePointerHolder.nativePointer or @@ -465,7 +482,7 @@ static const char * const S3JniDb_clientdata_key = "S3JniDb"; */ typedef struct S3JniEnv S3JniEnv; struct S3JniEnv { - JNIEnv *env /* env in which this cache entry was created */; + JNIEnv *env /* JNIEnv in which this cache entry was created */; /* ** pdbOpening is used to coordinate the Java/DB connection of a ** being-open()'d db in the face of auto-extensions. @@ -561,7 +578,6 @@ struct S3JniGlobalType { ** threads. Caching a copy of the JavaVM object enables any thread ** with access to the cached object to get access to its own ** JNIEnv when necessary. - ** */ JavaVM * jvm; /* Global mutex. */ @@ -577,9 +593,8 @@ struct S3JniGlobalType { struct { S3JniEnv * aHead /* Linked list of in-use instances */; S3JniEnv * aFree /* Linked list of free instances */; - sqlite3_mutex * mutex /* mutex for aHead and aFree, first-time - inits of nph[] entries, and - NativePointerHolder_get/set(). */; + sqlite3_mutex * mutex /* mutex for aHead and aFree, and first-time + inits of nph[] entries. */; void const * locker /* env mutex is held on this object's behalf. Used only for sanity checking. */; } envCache; @@ -1040,7 +1055,7 @@ static char * s3jni_exception_error_msg(JNIEnv * const env, jthrowable jx){ ** Returns errCode unless it is 0, in which case SQLITE_ERROR is ** returned. */ -static int s3jni__db_exception(JNIEnv * const env, S3JniDb * const ps, +static int s3jni__db_exception(JNIEnv * const env, sqlite3 * const pDb, int errCode, const char *zDfltMsg){ jthrowable const ex = (*env)->ExceptionOccurred(env); @@ -1048,17 +1063,17 @@ static int s3jni__db_exception(JNIEnv * const env, S3JniDb * const ps, if( ex ){ char * zMsg; S3JniExceptionClear; - S3JniDb_mutex_enter; zMsg = s3jni_exception_error_msg(env, ex); - s3jni_db_error(ps->pDb, errCode, zMsg ? zMsg : zDfltMsg); + s3jni_db_error(pDb, errCode, zMsg ? zMsg : zDfltMsg); sqlite3_free(zMsg); S3JniUnrefLocal(ex); - S3JniDb_mutex_leave; + }else if( zDfltMsg ){ + s3jni_db_error(pDb, errCode, zDfltMsg); } return errCode; } -#define s3jni_db_exception(JniDb,ERRCODE,DFLTMSG) \ - s3jni__db_exception(env, (JniDb), (ERRCODE), (DFLTMSG) ) +#define s3jni_db_exception(pDb,ERRCODE,DFLTMSG) \ + s3jni__db_exception(env, (pDb), (ERRCODE), (DFLTMSG) ) /* ** Extracts the (void xDestroy()) method from jObj and applies it to @@ -1140,8 +1155,7 @@ static void S3JniHook__unref(JNIEnv * const env, S3JniHook * const s){ } *s = S3JniHook_empty; } -#define S3JniHook_unref(hook) \ - S3JniHook__unref(env, (hook)) +#define S3JniHook_unref(hook) S3JniHook__unref(env, (hook)) /* ** Allocates one blank S3JniHook object from the recycling bin, if @@ -1260,6 +1274,7 @@ static void S3JniDb__set_aside(JNIEnv * const env, S3JniDb * const s){ static int S3JniEnv_uncache(JNIEnv * const env){ struct S3JniEnv * row; struct S3JniEnv * pPrev = 0; + S3JniEnv_mutex_assertLocked; row = SJG.envCache.aHead; for( ; row; pPrev = row, row = row->pNext ){ @@ -1296,26 +1311,13 @@ static int S3JniEnv_uncache(JNIEnv * const env){ ** (2023-07-31) tests. */ static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ - /** - According to: - - https://developer.ibm.com/articles/j-jni/ - - > ... the IDs returned for a given class don't change for the - lifetime of the JVM process. But the call to get the field or - method can require significant work in the JVM, because - fields and methods might have been inherited from - superclasses, making the JVM walk up the class hierarchy to - find them. Because the IDs are the same for a given class, - you should look them up once and then reuse them. Similarly, - looking up class objects can be expensive, so they should be - cached as well. - */ S3JniNphClass * const pNC = &SJG.nph[pRef->index]; + assert( (void*)pRef>=(void*)&S3JniNphRefs && (void*)pRef<(void*)(&S3JniNphRefs + 1) - && "pRef is out of range." ); + && "pRef is out of range" ); assert( pRef->index>=0 - && (pRef->index < (sizeof(S3JniNphRefs) / sizeof(S3JniNphRef))) ); + && (pRef->index < (sizeof(S3JniNphRefs) / sizeof(S3JniNphRef))) + && "pRef->index is out of range" ); if( !pNC->pRef ){ S3JniNph_mutex_enter; if( !pNC->pRef ){ @@ -1410,7 +1412,7 @@ static void * NativePointerHolder__get(JNIEnv * env, jobject pObj, ** argument is a Java sqlite3 object, as this operation only has void ** pointers to work with. */ -#define PtrGet_T(T,OBJ) NativePointerHolder_get(OBJ, &S3JniNphRefs.T) +#define PtrGet_T(T,OBJ) NativePointerHolder_get(OBJ, S3JniNph(T)) #define PtrGet_sqlite3(OBJ) PtrGet_T(sqlite3, OBJ) #define PtrGet_sqlite3_stmt(OBJ) PtrGet_T(sqlite3_stmt, OBJ) #define PtrGet_sqlite3_value(OBJ) PtrGet_T(sqlite3_value, OBJ) @@ -1528,7 +1530,7 @@ static int S3JniAutoExtension_init(JNIEnv *const env, static void OutputPointer_set_Bool(JNIEnv * const env, jobject const jOut, int v){ (*env)->SetBooleanField(env, jOut, s3jni_nphop_field( - env, &S3JniNphRefs.OutputPointer_Bool + env, S3JniNph(OutputPointer_Bool) ), v ? JNI_TRUE : JNI_FALSE ); S3JniExceptionIsFatal("Cannot set OutputPointer.Bool.value"); } @@ -1540,7 +1542,7 @@ static void OutputPointer_set_Bool(JNIEnv * const env, jobject const jOut, static void OutputPointer_set_Int32(JNIEnv * const env, jobject const jOut, int v){ (*env)->SetIntField(env, jOut, s3jni_nphop_field( - env, &S3JniNphRefs.OutputPointer_Int32 + env, S3JniNph(OutputPointer_Int32) ), (jint)v); S3JniExceptionIsFatal("Cannot set OutputPointer.Int32.value"); } @@ -1552,7 +1554,7 @@ static void OutputPointer_set_Int32(JNIEnv * const env, jobject const jOut, static void OutputPointer_set_Int64(JNIEnv * const env, jobject const jOut, jlong v){ (*env)->SetLongField(env, jOut, s3jni_nphop_field( - env, &S3JniNphRefs.OutputPointer_Int64 + env, S3JniNph(OutputPointer_Int64) ), v); S3JniExceptionIsFatal("Cannot set OutputPointer.Int64.value"); } @@ -1575,7 +1577,7 @@ static void OutputPointer_set_obj(JNIEnv * const env, */ static void OutputPointer_set_sqlite3(JNIEnv * const env, jobject const jOut, jobject jDb){ - OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_sqlite3, jOut, jDb); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3), jOut, jDb); } /* @@ -1584,7 +1586,7 @@ static void OutputPointer_set_sqlite3(JNIEnv * const env, jobject const jOut, */ static void OutputPointer_set_sqlite3_stmt(JNIEnv * const env, jobject const jOut, jobject jStmt){ - OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_sqlite3_stmt, jOut, jStmt); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_stmt), jOut, jStmt); } #ifdef SQLITE_ENABLE_PREUPDATE_HOOK @@ -1594,7 +1596,7 @@ static void OutputPointer_set_sqlite3_stmt(JNIEnv * const env, jobject const jOu */ static void OutputPointer_set_sqlite3_value(JNIEnv * const env, jobject const jOut, jobject jValue){ - OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_sqlite3_value, jOut, jValue); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), jOut, jValue); } #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ @@ -1606,7 +1608,7 @@ static void OutputPointer_set_sqlite3_value(JNIEnv * const env, jobject const jO */ static void OutputPointer_set_ByteArray(JNIEnv * const env, jobject const jOut, jbyteArray const v){ - OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_ByteArray, jOut, v); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_ByteArray), jOut, v); } #endif #endif /* SQLITE_ENABLE_FTS5 */ @@ -1617,7 +1619,7 @@ static void OutputPointer_set_ByteArray(JNIEnv * const env, jobject const jOut, */ static void OutputPointer_set_String(JNIEnv * const env, jobject const jOut, jstring const v){ - OutputPointer_set_obj(env, &S3JniNphRefs.OutputPointer_String, jOut, v); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_String), jOut, v); } /* @@ -1651,15 +1653,15 @@ static void ResultJavaValue_finalizer(void *v){ /* -** Returns a new Java instance of the class named by zClassName, which +** Returns a new Java instance of the class referred to by pRef, which ** MUST be interface-compatible with NativePointerHolder and MUST have ** a no-arg constructor. The NativePointerHolder_set() method is ** passed the new Java object and pNative. Hypothetically returns NULL ** if Java fails to allocate, but the JNI docs are not entirely clear ** on that detail. ** -** Always use a static pointer from the S3JniNphRefs struct for the 2nd -** argument so that we can use pRef->index as an O(1) cache key. +** Always use a static pointer from the S3JniNphRefs struct for the +** 2nd argument. */ static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef const * pRef, const void * pNative){ @@ -1681,16 +1683,16 @@ static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef co } static inline jobject new_sqlite3_wrapper(JNIEnv * const env, sqlite3 *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.sqlite3, sv); + return new_NativePointerHolder_object(env, S3JniNph(sqlite3), sv); } static inline jobject new_sqlite3_context_wrapper(JNIEnv * const env, sqlite3_context *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.sqlite3_context, sv); + return new_NativePointerHolder_object(env, S3JniNph(sqlite3_context), sv); } static inline jobject new_sqlite3_stmt_wrapper(JNIEnv * const env, sqlite3_stmt *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.sqlite3_stmt, sv); + return new_NativePointerHolder_object(env, S3JniNph(sqlite3_stmt), sv); } static inline jobject new_sqlite3_value_wrapper(JNIEnv * const env, sqlite3_value *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.sqlite3_value, sv); + return new_NativePointerHolder_object(env, S3JniNph(sqlite3_value), sv); } /* Helper typedefs for UDF callback types. */ @@ -1815,7 +1817,7 @@ static int udf_args(JNIEnv *env, *jArgv = 0; if( !jcx ) goto error_oom; ja = (*env)->NewObjectArray( - env, argc, s3jni_nph(&S3JniNphRefs.sqlite3_value)->klazz, + env, argc, s3jni_nph(S3JniNph(sqlite3_value))->klazz, NULL); s3jni_oom_check( ja ); if( !ja ) goto error_oom; @@ -2117,7 +2119,7 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, if( rc ){ return rc; } - NativePointerHolder_set(&S3JniNphRefs.sqlite3, ps->jDb, pDb) + NativePointerHolder_set(S3JniNph(sqlite3), ps->jDb, pDb) /* As of here, the Java/C connection is complete except for the (temporary) lack of finalizer for the ps object. */; ps->pDb = pDb; @@ -2156,7 +2158,7 @@ S3JniApi(sqlite3_auto_extension(),jint,1auto_1extension)( JniArgsEnvClass, jobject jAutoExt ){ int i; - S3JniAutoExtension * ax; + S3JniAutoExtension * ax = 0; int rc = 0; if( !jAutoExt ) return SQLITE_MISUSE; @@ -2336,7 +2338,7 @@ static int s3jni_busy_handler(void* pState, int n){ hook.midCallback, (jint)n); S3JniIfThrew{ S3JniExceptionWarnCallbackThrew("sqlite3_busy_handler() callback"); - rc = s3jni_db_exception(ps, SQLITE_ERROR, + rc = s3jni_db_exception(ps->pDb, SQLITE_ERROR, "sqlite3_busy_handler() callback threw."); } S3JniHook_localundup(hook); @@ -2440,7 +2442,7 @@ static jint s3jni_close_db(JNIEnv * const env, jobject jDb, int version){ ? (jint)sqlite3_close(ps->pDb) : (jint)sqlite3_close_v2(ps->pDb); if( 0==rc ){ - NativePointerHolder_set(&S3JniNphRefs.sqlite3, jDb, 0); + NativePointerHolder_set(S3JniNph(sqlite3), jDb, 0); } } return (jint)rc; @@ -2529,7 +2531,7 @@ S3JniApi(sqlite3_collation_needed(),jint,1collation_1needed)( ); S3JniUnrefLocal(klazz); S3JniIfThrew { - rc = s3jni_db_exception(ps, SQLITE_MISUSE, + rc = s3jni_db_exception(ps->pDb, SQLITE_MISUSE, "Cannot not find matching call() in " "CollationNeededCallback object."); }else{ @@ -2574,7 +2576,7 @@ S3JniApi(sqlite3_column_int64(),jlong,1column_1int64)( return (jlong)sqlite3_column_int64(PtrGet_sqlite3_stmt(jpStmt), (int)ndx); } -S3JniApi(sqlite3_column_text(),jbyteArray,1column_1text_1utf8)( +S3JniApi(sqlite3_column_text(),jbyteArray,1column_1text)( JniArgsEnvClass, jobject jpStmt, jint ndx ){ sqlite3_stmt * const stmt = PtrGet_sqlite3_stmt(jpStmt); @@ -2583,6 +2585,9 @@ S3JniApi(sqlite3_column_text(),jbyteArray,1column_1text_1utf8)( return p ? s3jni_new_jbyteArray(p, n) : NULL; } +#if 0 +// this impl might prove useful, but we'd need to publish the +// bytearray-returning impl with a different name. S3JniApi(sqlite3_column_text(),jstring,1column_1text)( JniArgsEnvClass, jobject jpStmt, jint ndx ){ @@ -2591,6 +2596,7 @@ S3JniApi(sqlite3_column_text(),jstring,1column_1text)( const unsigned char * const p = sqlite3_column_text(stmt, (int)ndx); return p ? s3jni_utf8_to_jstring( (const char *)p, n) : 0; } +#endif S3JniApi(sqlite3_column_text16(),jstring,1column_1text16)( JniArgsEnvClass, jobject jpStmt, jint ndx @@ -2610,7 +2616,7 @@ S3JniApi(sqlite3_column_value(),jobject,1column_1value)( } /* -** Impl for both commit hooks (if isCommit is true) or rollback hooks. +** Impl for commit hooks (if isCommit is true) or rollback hooks. */ static int s3jni_commit_rollback_hook_impl(int isCommit, S3JniDb * const ps){ S3JniDeclLocal_env; @@ -2625,8 +2631,7 @@ static int s3jni_commit_rollback_hook_impl(int isCommit, S3JniDb * const ps){ ? (int)(*env)->CallIntMethod(env, hook.jObj, hook.midCallback) : (int)((*env)->CallVoidMethod(env, hook.jObj, hook.midCallback), 0); S3JniIfThrew{ - S3JniExceptionClear; - rc = s3jni_db_error(ps->pDb, SQLITE_ERROR, "hook callback threw."); + rc = s3jni_db_exception(ps->pDb, SQLITE_ERROR, "hook callback threw"); } S3JniHook_localundup(hook); } @@ -3159,7 +3164,7 @@ S3JniApi(sqlite3_finalize(),jint,1finalize)( sqlite3_stmt * const pStmt = PtrGet_sqlite3_stmt(jpStmt); if( pStmt ){ rc = sqlite3_finalize(pStmt); - NativePointerHolder_set(&S3JniNphRefs.sqlite3_stmt, jpStmt, 0); + NativePointerHolder_set(S3JniNph(sqlite3_stmt), jpStmt, 0); } return rc; } @@ -3283,7 +3288,7 @@ static int s3jni_open_post(JNIEnv * const env, S3JniEnv * const jc, assert(ps->jDb); if( 0==ps->pDb ){ ps->pDb = *ppDb; - NativePointerHolder_set(&S3JniNphRefs.sqlite3, ps->jDb, *ppDb); + NativePointerHolder_set(S3JniNph(sqlite3), ps->jDb, *ppDb); }else{ assert( ps->pDb==*ppDb && "Set up via s3jni_run_java_auto_extensions()" ); @@ -3390,7 +3395,7 @@ end: OutputPointer_set_Int32(env, outTail, (int)(zTail ? (zTail - (const char *)pBuf) : 0)); } if( pStmt ){ - NativePointerHolder_set(&S3JniNphRefs.sqlite3_stmt, jStmt, pStmt); + NativePointerHolder_set(S3JniNph(sqlite3_stmt), jStmt, pStmt); }else{ /* Happens for comments and whitespace. */ S3JniUnrefLocal(jStmt); @@ -3473,7 +3478,7 @@ static void s3jni_updatepre_hook_impl(void * pState, sqlite3 *pDb, int opId, (jint)opId, jDbName, jTable, (jlong)iKey1); S3JniIfThrew{ S3JniExceptionWarnCallbackThrew("sqlite3_(pre)update_hook() callback"); - s3jni_db_exception(ps, 0, + s3jni_db_exception(ps->pDb, 0, "sqlite3_(pre)update_hook() callback threw"); } } @@ -3644,7 +3649,7 @@ static int s3jni_progress_handler_impl(void *pP){ if( hook.jObj ){ rc = (int)(*env)->CallIntMethod(env, hook.jObj, hook.midCallback); S3JniIfThrew{ - rc = s3jni_db_exception(ps, rc, + rc = s3jni_db_exception(ps->pDb, rc, "sqlite3_progress_handler() callback threw"); } S3JniHook_localundup(hook); @@ -3940,7 +3945,7 @@ int s3jni_xAuth(void* pState, int op,const char*z0, const char*z1, rc = (*env)->CallIntMethod(env, hook.jObj, hook.midCallback, (jint)op, s0, s1, s3, s3); S3JniIfThrew{ - rc = s3jni_db_exception(ps, rc, "sqlite3_set_authorizer() callback"); + rc = s3jni_db_exception(ps->pDb, rc, "sqlite3_set_authorizer() callback"); } S3JniUnrefLocal(s0); S3JniUnrefLocal(s1); @@ -4215,7 +4220,7 @@ static int s3jni_trace_impl(unsigned traceflag, void *pC, void *pP, void *pX){ case SQLITE_TRACE_ROW: break; case SQLITE_TRACE_CLOSE: - jP = ps->jDb; + jP = jPUnref = S3JniRefLocal(ps->jDb); break; default: assert(!"cannot happen - unkown trace flag"); @@ -4234,7 +4239,7 @@ static int s3jni_trace_impl(unsigned traceflag, void *pC, void *pP, void *pX){ rc = (int)(*env)->CallIntMethod(env, hook.jObj, hook.midCallback, (jint)traceflag, jP, jX); S3JniIfThrew{ - rc = s3jni_db_exception(ps, SQLITE_ERROR, + rc = s3jni_db_exception(ps->pDb, SQLITE_ERROR, "sqlite3_trace_v2() callback threw."); } } @@ -4364,7 +4369,7 @@ S3JniApi(sqlite3_value_java_object(),jobject,1value_1java_1object)( ResultJavaValuePtrStr); } -S3JniApi(sqlite3_value_text_utf8(),jbyteArray,1value_1text_1utf8)( +S3JniApi(sqlite3_value_text(),jbyteArray,1value_1text)( JniArgsEnvClass, jobject jpSVal ){ sqlite3_value * const sv = PtrGet_sqlite3_value(jpSVal); @@ -4373,6 +4378,9 @@ S3JniApi(sqlite3_value_text_utf8(),jbyteArray,1value_1text_1utf8)( return p ? s3jni_new_jbyteArray(p, n) : 0; } +#if 0 +// this impl might prove useful, but we'd need to publish the +// bytearray-returning impl with a different name. S3JniApi(sqlite3_value_text(),jstring,1value_1text)( JniArgsEnvClass, jobject jpSVal ){ @@ -4381,6 +4389,7 @@ S3JniApi(sqlite3_value_text(),jstring,1value_1text)( const unsigned char * const p = sqlite3_value_text(sv); return p ? s3jni_utf8_to_jstring( (const char *)p, n) : 0; } +#endif S3JniApi(sqlite3_value_text16(),jstring,1value_1text16)( JniArgsEnvClass, jobject jpSVal @@ -4483,10 +4492,10 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ JNIEXPORT ReturnType JNICALL \ JniFuncNameFtsTok(Suffix) -#define PtrGet_fts5_api(OBJ) NativePointerHolder_get(OBJ,&S3JniNphRefs.fts5_api) -#define PtrGet_fts5_tokenizer(OBJ) NativePointerHolder_get(OBJ,&S3JniNphRefs.fts5_tokenizer) -#define PtrGet_Fts5Context(OBJ) NativePointerHolder_get(OBJ,&S3JniNphRefs.Fts5Context) -#define PtrGet_Fts5Tokenizer(OBJ) NativePointerHolder_get(OBJ,&S3JniNphRefs.Fts5Tokenizer) +#define PtrGet_fts5_api(OBJ) NativePointerHolder_get(OBJ,S3JniNph(fts5_api)) +#define PtrGet_fts5_tokenizer(OBJ) NativePointerHolder_get(OBJ,S3JniNph(fts5_tokenizer)) +#define PtrGet_Fts5Context(OBJ) NativePointerHolder_get(OBJ,S3JniNph(Fts5Context)) +#define PtrGet_Fts5Tokenizer(OBJ) NativePointerHolder_get(OBJ,S3JniNph(Fts5Tokenizer)) #define Fts5ExtDecl Fts5ExtensionApi const * const fext = s3jni_ftsext() /** @@ -4548,10 +4557,10 @@ static inline Fts5ExtensionApi const * s3jni_ftsext(void){ } static inline jobject new_Fts5Context_wrapper(JNIEnv * const env, Fts5Context *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.Fts5Context, sv); + return new_NativePointerHolder_object(env, S3JniNph(Fts5Context), sv); } static inline jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){ - return new_NativePointerHolder_object(env, &S3JniNphRefs.fts5_api, sv); + return new_NativePointerHolder_object(env, S3JniNph(fts5_api), sv); } /* @@ -4561,7 +4570,7 @@ static inline jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){ static jobject s3jni_getFts5ExensionApi(JNIEnv * const env){ if( !SJG.fts5.jFtsExt ){ jobject pNPH = new_NativePointerHolder_object( - env, &S3JniNphRefs.Fts5ExtensionApi, s3jni_ftsext() + env, S3JniNph(Fts5ExtensionApi), s3jni_ftsext() ); S3JniEnv_mutex_enter; if( pNPH ){ @@ -5016,11 +5025,11 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphRef const *pRef, s.tok.jba = S3JniRefLocal(jbaText); s.tok.zPrev = (const char *)pText; s.tok.nPrev = (int)nText; - if( pRef == &S3JniNphRefs.Fts5ExtensionApi ){ + if( pRef == S3JniNph(Fts5ExtensionApi) ){ rc = fext->xTokenize(PtrGet_Fts5Context(jFcx), (const char *)pText, (int)nText, &s, s3jni_xTokenize_xToken); - }else if( pRef == &S3JniNphRefs.fts5_tokenizer ){ + }else if( pRef == S3JniNph(fts5_tokenizer) ){ fts5_tokenizer * const pTok = PtrGet_fts5_tokenizer(jSelf); rc = pTok->xTokenize(PtrGet_Fts5Tokenizer(jFcx), &s, tokFlags, (const char *)pText, (int)nText, @@ -5038,13 +5047,13 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphRef const *pRef, JniDeclFtsXA(jint,xTokenize)(JniArgsEnvObj,jobject jFcx, jbyteArray jbaText, jobject jCallback){ - return s3jni_fts5_xTokenize(env, jSelf, &S3JniNphRefs.Fts5ExtensionApi, + return s3jni_fts5_xTokenize(env, jSelf, S3JniNph(Fts5ExtensionApi), 0, jFcx, jbaText, jCallback); } JniDeclFtsTok(jint,xTokenize)(JniArgsEnvObj,jobject jFcx, jint tokFlags, jbyteArray jbaText, jobject jCallback){ - return s3jni_fts5_xTokenize(env, jSelf, &S3JniNphRefs.Fts5Tokenizer, + return s3jni_fts5_xTokenize(env, jSelf, S3JniNph(Fts5Tokenizer), tokFlags, jFcx, jbaText, jCallback); } @@ -5337,5 +5346,5 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ sqlite3_shutdown() /* So that it becomes legal for Java-level code to call - ** sqlite3_config(), if it's ever implemented. */; + ** sqlite3_config(). */; } diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 1c9e4a641c..754d57063f 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1061,18 +1061,10 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1column_1table_ /* * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_column_text_utf8 + * Method: sqlite3_column_text * Signature: (Lorg/sqlite/jni/sqlite3_stmt;I)[B */ -JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1column_1text_1utf8 - (JNIEnv *, jclass, jobject, jint); - -/* - * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_column_text - * Signature: (Lorg/sqlite/jni/sqlite3_stmt;I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1column_1text +JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1column_1text (JNIEnv *, jclass, jobject, jint); /* @@ -1853,18 +1845,10 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1java_1o /* * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_value_text_utf8 + * Method: sqlite3_value_text * Signature: (Lorg/sqlite/jni/sqlite3_value;)[B */ -JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text_1utf8 - (JNIEnv *, jclass, jobject); - -/* - * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_value_text - * Signature: (Lorg/sqlite/jni/sqlite3_value;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text +JNIEXPORT jbyteArray JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1value_1text (JNIEnv *, jclass, jobject); /* diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index e6eafa0bef..9225e48281 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -416,24 +416,13 @@ public final class SQLite3Jni { ); /** - Returns the given column's contents as UTF-8-encoded (not MUTF-8) - text. Returns null if the C-level sqlite3_column_text() returns - NULL. - - @see #sqlite3_column_text + Functions identially to the C API, and this note is just to + stress that the returned bytes are encoded as UTF-8. It returns + null if the underlying C-level sqlite3_column_text() returns NULL + or on allocation error. */ - @Canonical(cname="sqlite3_column_text") - public static native byte[] sqlite3_column_text_utf8( - @NotNull sqlite3_stmt stmt, int ndx - ); - - /** - Provides the same feature as the same-named C API but returns the - text in Java-native encoding rather than the C API's UTF-8. - - @see #sqlite3_column_text16 - */ - public static native String sqlite3_column_text( + @Canonical + public static native byte[] sqlite3_column_text( @NotNull sqlite3_stmt stmt, int ndx ); @@ -471,7 +460,7 @@ public final class SQLite3Jni { // } // case SQLITE_FLOAT: rv = new Double(sqlite3_value_double(v)); break; // case SQLITE_BLOB: rv = sqlite3_value_blob(v); break; - // case SQLITE_TEXT: rv = sqlite3_value_text(v); break; + // case SQLITE_TEXT: rv = sqlite3_value_text16(v); break; // default: break; // } // } @@ -1172,6 +1161,10 @@ public final class SQLite3Jni { @NotNull sqlite3_context cx, long n ); + /** + This overload is private because its final parameter is arguably + unnecessary in Java. + */ @Canonical private static native void sqlite3_result_blob( @NotNull sqlite3_context cx, @Nullable byte[] blob, int maxLen @@ -1195,8 +1188,11 @@ public final class SQLite3Jni {

- If @param maxLen is larger than blob.length, it is truncated to - that value. If it is negative, results are undefined. +

If @param maxLen is larger than blob.length, it is truncated + to that value. If it is negative, results are undefined.

+ +

This overload is private because its final parameter is + arguably unnecessary in Java.

*/ @Canonical private static native void sqlite3_result_blob64( @@ -1209,6 +1205,10 @@ public final class SQLite3Jni { sqlite3_result_blob64(cx, blob, (long)(null==blob ? 0 : blob.length)); } + /** + This overload is private because its final parameter is + arguably unnecessary in Java. + */ @Canonical private static native void sqlite3_result_text( @NotNull sqlite3_context cx, @Nullable byte[] utf8, int maxLen @@ -1249,6 +1249,9 @@ public final class SQLite3Jni { text.length, it is silently truncated to text.length. If it is negative, results are undefined. If text is null, the subsequent arguments are ignored. + + This overload is private because its maxLength parameter is + arguably unnecessary in Java. */ @Canonical private static native void sqlite3_result_text64( @@ -1342,6 +1345,13 @@ public final class SQLite3Jni { /** Internal impl of the public sqlite3_strglob() method. Neither argument may be NULL and both MUST be NUL-terminated UTF-8. + + This overload is private because: (A) to keep users from + inadvertently passing non-NUL-terminated byte arrays (an easy + thing to do). (B) it is cheaper to NUL-terminate the + String-to-byte-array conversion in the Java implementation + (sqlite3_strglob(String,String)) than to do that in C, so that + signature is the public-facing one. */ @Canonical private static native int sqlite3_strglob( @@ -1358,8 +1368,7 @@ public final class SQLite3Jni { } /** - Internal impl of the public sqlite3_strlike() method. Neither - argument may be NULL and both MUST be NUL-terminated UTF-8. + The LIKE counterpart of the private sqlite3_strglob() method. */ @Canonical private static native int sqlite3_strlike( @@ -1502,30 +1511,14 @@ public final class SQLite3Jni { } /** - Returns the given value as UTF-8-encoded bytes, or null if the - underlying C-level sqlite3_value_text() returns NULL. + Functions identially to the C API, and this note is just to + stress that the returned bytes are encoded as UTF-8. It returns + null if the underlying C-level sqlite3_value_text() returns NULL + or on allocation error. */ - @Canonical(cname="sqlite3_value_text", - comment="Renamed because its String-returning overload would "+ - "otherwise be ambiguous.") - public static native byte[] sqlite3_value_text_utf8(@NotNull sqlite3_value v); + @Canonical + public static native byte[] sqlite3_value_text(@NotNull sqlite3_value v); - /** - Provides the same feature as the same-named C API but returns the - text in Java-native encoding rather than the C API's UTF-8. - - @see #sqlite3_value_text16 - */ - public static native String sqlite3_value_text(@NotNull sqlite3_value v); - - /** - In the Java layer, sqlite3_value_text() and - sqlite3_value_text16() are functionally equivalent, the - difference being only where the encoding to UTF-16 (if necessary) - takes place. This function does it via SQLite and - sqlite3_value_text() fetches UTF-8 (SQLite's default encoding) - and converts it to UTF-16 in Java. - */ @Canonical public static native String sqlite3_value_text16(@NotNull sqlite3_value v); diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 5d3623f677..ce8eb6bd23 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -453,9 +453,14 @@ public class Tester1 implements Runnable { 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(new String( + sqlite3_column_text(stmt, 0), + StandardCharsets.UTF_8 + )) ); affirm( txt.length() < sqlite3_value_bytes(sv) ); - affirm( txt.equals(sqlite3_value_text(sv)) ); + affirm( txt.equals(new String( + sqlite3_value_text(sv), + StandardCharsets.UTF_8)) ); affirm( txt.length() == sqlite3_value_bytes16(sv)/2 ); affirm( txt.equals(sqlite3_value_text16(sv)) ); sqlite3_value_free(sv); @@ -464,6 +469,20 @@ public class Tester1 implements Runnable { sqlite3_finalize(stmt); affirm(3 == n); affirm("w😃rldhell🤩!🤩".equals(sbuf.toString())); + + stmt = prepare(db, "SELECT ?, ?"); + rc = sqlite3_bind_text(stmt, 1, ""); + affirm( 0==rc ); + rc = sqlite3_bind_text(stmt, 2, (String)null); + affirm( 0==rc ); + rc = sqlite3_step(stmt); + affirm( SQLITE_ROW==rc ); + byte[] colBa = sqlite3_column_text(stmt, 0); + affirm( 0==colBa.length ); + colBa = sqlite3_column_text(stmt, 1); + affirm( null==colBa ); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); } diff --git a/ext/jni/src/org/sqlite/jni/TesterFts5.java b/ext/jni/src/org/sqlite/jni/TesterFts5.java index feb6d6303d..70c8e255d2 100644 --- a/ext/jni/src/org/sqlite/jni/TesterFts5.java +++ b/ext/jni/src/org/sqlite/jni/TesterFts5.java @@ -50,7 +50,7 @@ public class TesterFts5 { int rc = ext.xColumnText(fCx, i, op); affirm( 0 == rc ); final String val = op.value; - affirm( val.equals(sqlite3_value_text(argv[i])) ); + affirm( val.equals(sqlite3_value_text16(argv[i])) ); //outln("xFunction col "+i+": "+val); } } diff --git a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java index 80164a4dda..24b0f82d4c 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java +++ b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java @@ -7,35 +7,22 @@ package org.sqlite.jni.annotation; the Java API.

Canonical functions, unless specifically documented, have the - same semantics as their counterparts in - the C API documentation, - despite their signatures perhaps differing. The Java API adds a - number of overloads to simplify use, as well as a few Java-specific - functions, and those are never flagged as @Canonical. + same semantics as their counterparts in the C API + documentation, despite their signatures perhaps differing + slightly. The Java API adds a number of overloads to simplify use, + as well as a few Java-specific functions, and those are never + flagged as @Canonical.

In some cases, the canonical version of a function is private and exposed to Java via public overloads. -

In rare cases, the Java interface for a canonical function has a - different name than its C counterpart. For such cases, - (cname=the-C-side-name) is passed to this annotation and a - Java-side implementation with a slightly different signature is - added with the canonical name. As of this writing, that applies - only to {@link org.sqlite.jni.SQLite3Jni#sqlite3_value_text_utf8} - and {@link org.sqlite.jni.SQLite3Jni#sqlite3_column_text_utf8}. -

The comment property can be used to add a comment. */ @java.lang.annotation.Documented @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface Canonical{ - /** - Java functions which directly map to a canonical function but - change its name for some reason should not the original name - in this property. - */ - String cname() default ""/*doesn't allow null*/; /** Brief comments about the binding, e.g. noting any major semantic differences. diff --git a/manifest b/manifest index 85245e43d1..e8040dc975 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssome\snewly-dead\scode. -D 2023-09-01T10:37:15.903 +C Make\sJNI\sinterfaces\sof\ssqlite3_column/value_text()\smatch\sthe\sC\sones\sbetter.\sInternal\sJNI\scleanups\sand\ssimplifications. +D 2023-09-01T13:27:59.308 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,11 +234,11 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 591d05030e7fa787615d88fb5b7e8377e1e777612fce4d4eed9b595843f1d014 +F ext/jni/GNUmakefile bcf386da9510e45034d90b2f7b91ab51adcd2db9e080f3900a1e63caf5999659 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 69a78f7f7b94b58e272184d005813322bad24ed78ea392563b657faa3cc56218 -F ext/jni/src/c/sqlite3-jni.h 383a357c8920e05ea2b6ca7f9548ee04a263319f018ef3daeeaa719727be8b72 +F ext/jni/src/c/sqlite3-jni.c 2da08d92d1cd858353071a2559a260333425e87a79f3da09d85f07f35930a573 +F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,17 +262,17 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5a05c67b994d3f431d61203ab1de842d49491714e78cf99ccd5aa5257b66e9ff +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 35ead9802bf3b16f9afba663ac73f629b3ebdc5cacad151f38403daee9f1e6b0 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 95fd3d3c0068cd7ebf2e89bb7db16fba541e6cf872f64f08c1e1350f6585682b -F ext/jni/src/org/sqlite/jni/TesterFts5.java 6f135c60e24c89e8eecb9fe61dde0f3bb2906de668ca6c9186bcf34bdaf94629 +F ext/jni/src/org/sqlite/jni/Tester1.java d4ab6f3f83cbb96e763dd4feb6e5527864d9957eb5e79259bfbe57dcf6d0103e +F ext/jni/src/org/sqlite/jni/TesterFts5.java 02b59ea7d75666fd565d90bb8dc7b0c09441bb9d1af091fad9f6d7377297a474 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 -F ext/jni/src/org/sqlite/jni/annotation/Canonical.java ff9fc59004303d8ef89c516ede9ef5f51c881e9c9ba982f0ebb1bdd9a18550bc +F ext/jni/src/org/sqlite/jni/annotation/Canonical.java d9ff79f1bf9d063d0c3e3b768ec7df15f51e4ca51a5bb291d33b7a6ea9a24f3a F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 @@ -2116,8 +2116,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 5fe5b0a585dbfa06cfca1fea40aea5ea3ccfe8295f41306ad2d5b851ace27203 -R e68a872b68a0b0146fb6e1b06b988d94 +P dc0fa76b395c5e352116dc33cc1b455e5e9c9f01c285af52ccba4d37e4453b87 +R 8eeecadbd0aad723daa22691fc77aaf3 U stephan -Z 2904ef85d8a184bf73f88a40f15d384b +Z 2c93c72b42f574b692bce8cc766cb46c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1740a09513..f6e2e419ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc0fa76b395c5e352116dc33cc1b455e5e9c9f01c285af52ccba4d37e4453b87 \ No newline at end of file +eb24f97253d9c8e7c728c2ac67a0824b10ca67362ac4f8abb94d5d3c54c58c5b \ No newline at end of file From 4ea63e5609be66f72ddacc4dffb385c37d24293b Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 14:20:39 +0000 Subject: [PATCH 10/36] Make the JNI-internal metrics opt-in rather than opt-out so client builds won't have them by default. Unrelated doc tweaks. FossilOrigin-Name: aa72d25a22c80a7a376127266b8923f0661147c8bc483baa327230364851a255 --- ext/jni/GNUmakefile | 4 ++- ext/jni/src/c/sqlite3-jni.c | 37 ++++++++++++---------- ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 24 +++++++++----- manifest | 16 +++++----- manifest.uuid | 2 +- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index ae0c53f902..346351b06b 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -177,6 +177,7 @@ $(sqlite3.c): $(sqlite3.h) opt.threadsafe ?= 1 opt.fatal-oom ?= 1 opt.debug ?= 1 +opt.metrics ?= 1 SQLITE_OPT = \ -DSQLITE_ENABLE_RTREE \ -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ @@ -194,7 +195,8 @@ SQLITE_OPT = \ -DSQLITE_TEMP_STORE=2 \ -DSQLITE_USE_URI=1 \ -DSQLITE_C=$(sqlite3.c) \ - -DSQLITE_JNI_FATAL_OOM=$(opt.fatal-oom) + -DSQLITE_JNI_FATAL_OOM=$(opt.fatal-oom) \ + -DSQLITE_JNI_ENABLE_METRICS=$(opt.metrics) ifeq (1,$(opt.debug)) SQLITE_OPT += -DSQLITE_DEBUG -g -DDEBUG -UNDEBUG diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 831a4d8001..0744b99d0a 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -420,8 +420,8 @@ struct S3JniHook{ /* We lookup the jObj.xDestroy() method as-needed for contexts which ** have custom finalizers. */ jobject jExtra /* Global ref to a per-hook-type value */; - int doXDestroy /* If true call jObj->xDestroy() when - this object is S3JniHook_unref()'d. */; + int doXDestroy /* If true then S3JniHook_unref() will call + jObj->xDestroy() if it's available. */; S3JniHook * pNext /* Next entry in S3Global.hooks.aFree */; }; /* For clean bitwise-copy init of local instances. */ @@ -543,10 +543,8 @@ struct S3JniUdf { S3JniUdf * pNext /* Next entry in SJG.udf.aFree. */; }; -#if !defined(SQLITE_JNI_OMIT_METRICS) && !defined(SQLITE_JNI_ENABLE_METRICS) -# ifdef SQLITE_DEBUG -# define SQLITE_JNI_ENABLE_METRICS -# endif +#if defined(SQLITE_JNI_ENABLE_METRICS) && 0==SQLITE_JNI_ENABLE_METRICS +# undef SQLITE_JNI_ENABLE_METRICS #endif /* @@ -1105,10 +1103,10 @@ static void s3jni__call_xDestroy(JNIEnv * const env, jobject jObj){ /* ** Internal helper for many hook callback impls. Locks the S3JniDb -** mutex, makes a copy of src into dest, with a some differences: (1) if -** src->jObj or src->jExtra are not NULL then dest will be a new LOCAL -** ref to it instead of a copy of the prior GLOBAL ref. (2) dest->doXDestroy -** is always false. +** mutex, makes a copy of src into dest, with a some differences: (1) +** if src->jObj or src->jExtra are not NULL then dest will be a new +** LOCAL ref to it instead of a copy of the prior GLOBAL ref. (2) +** dest->doXDestroy is always false. ** ** If dest->jObj is not NULL when this returns then the caller is ** obligated to eventually free the new ref by passing *dest to @@ -1186,8 +1184,8 @@ static S3JniHook *S3JniHook__alloc(JNIEnv * const env){ #define S3JniHook_alloc() S3JniHook__alloc(env) /* -** The rightful fate of all results from S3JniHook_alloc(). doXDestroy -** is passed on as-is to S3JniHook_unref(). Locks the global mutex. +** The rightful fate of all results from S3JniHook_alloc(). Locks the +** global mutex. */ static void S3JniHook__free(JNIEnv * const env, S3JniHook * const p){ if(p){ @@ -1637,7 +1635,7 @@ static int encodingTypeIsValid(int eTextRep){ } /* For use with sqlite3_result/value_pointer() */ -#define ResultJavaValuePtrStr "org.sqlite.jni.ResultJavaVal" +static const char * const ResultJavaValuePtrStr = "org.sqlite.jni.ResultJavaVal"; /* ** If v is not NULL, it must be a jobject global reference. Its @@ -1804,7 +1802,9 @@ typedef struct { ** Converts the given (cx, argc, argv) into arguments for the given ** 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. +** error. On error *jCx and *jArgv will be set to 0. The output +** objects are of type org.sqlite.jni.sqlite3_context and +** array-of-org.sqlite3.jni.sqlite3_value, respectively. */ static int udf_args(JNIEnv *env, sqlite3_context * const cx, @@ -2831,8 +2831,10 @@ S3JniApi(sqlite3_context_db_handle(),jobject,1context_1db_1handle)( return ps ? ps->jDb : 0; } -/** - State for CollationCallbacks. +/* +** State for CollationCallbacks. This used to be its own separate +** type, but has since been consolidated with S3JniHook. It retains +** its own typedef for code legibility and searchability reasons. */ typedef S3JniHook S3JniCollationCallback; @@ -2915,7 +2917,8 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(), return (jint)rc; } -S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() sqlite3_create_window_function(), +S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() + sqlite3_create_window_function(), jint,1create_1function )(JniArgsEnvClass, jobject jDb, jstring jFuncName, jint nArg, jint eTextRep, jobject jFunctor){ diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 9225e48281..e7e5c62bcf 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -217,13 +217,19 @@ public final class SQLite3Jni { /** Requires that paramName be a NUL-terminated UTF-8 string. + + This overload is private because: (A) to keep users from + inadvertently passing non-NUL-terminated byte arrays (an easy + thing to do). (B) it is cheaper to NUL-terminate the + String-to-byte-array conversion in the public-facing Java-side + overload than to do that in C, so that signature is the + public-facing one. */ @Canonical - public static native int sqlite3_bind_parameter_index( - @NotNull sqlite3_stmt stmt, byte[] paramName + private static native int sqlite3_bind_parameter_index( + @NotNull sqlite3_stmt stmt, @NotNull byte[] paramName ); - @Canonical public static int sqlite3_bind_parameter_index( @NotNull sqlite3_stmt stmt, @NotNull String paramName ){ @@ -316,9 +322,9 @@ public final class SQLite3Jni { ); /** - As for the C-level function of the same name, with a BusyHandlerCallback - instance in place of a callback function. Pass it a null handler - to clear the busy handler. + As for the C-level function of the same name, with a + BusyHandlerCallback instance in place of a callback + function. Pass it a null handler to clear the busy handler. */ @Canonical public static native int sqlite3_busy_handler( @@ -420,6 +426,8 @@ public final class SQLite3Jni { stress that the returned bytes are encoded as UTF-8. It returns null if the underlying C-level sqlite3_column_text() returns NULL or on allocation error. + + @see #sqlite3_column_text16(sqlite3_stmt,int) */ @Canonical public static native byte[] sqlite3_column_text( @@ -480,7 +488,7 @@ public final class SQLite3Jni { /** This functions like C's sqlite3_collation_needed16() because - Java's string type is compatible with that interface. + Java's string type is inherently compatible with that interface. */ @Canonical public static native int sqlite3_collation_needed( @@ -1344,7 +1352,7 @@ public final class SQLite3Jni { /** Internal impl of the public sqlite3_strglob() method. Neither - argument may be NULL and both MUST be NUL-terminated UTF-8. + argument may be null and both must be NUL-terminated UTF-8. This overload is private because: (A) to keep users from inadvertently passing non-NUL-terminated byte arrays (an easy diff --git a/manifest b/manifest index e8040dc975..d03e82d999 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sJNI\sinterfaces\sof\ssqlite3_column/value_text()\smatch\sthe\sC\sones\sbetter.\sInternal\sJNI\scleanups\sand\ssimplifications. -D 2023-09-01T13:27:59.308 +C Make\sthe\sJNI-internal\smetrics\sopt-in\srather\sthan\sopt-out\sso\sclient\sbuilds\swon't\shave\sthem\sby\sdefault.\sUnrelated\sdoc\stweaks. +D 2023-09-01T14:20:39.576 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,10 +234,10 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile bcf386da9510e45034d90b2f7b91ab51adcd2db9e080f3900a1e63caf5999659 +F ext/jni/GNUmakefile 3e0e28c1c451eab31dd4fa9d262951ef67ed3ece3270a2efc8ec66ec57068547 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 2da08d92d1cd858353071a2559a260333425e87a79f3da09d85f07f35930a573 +F ext/jni/src/c/sqlite3-jni.c 0a814e8dbc333ff8a1a8a74aebaece435d2982ed6d4d8e8bf9b7082688b20221 F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -262,7 +262,7 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 35ead9802bf3b16f9afba663ac73f629b3ebdc5cacad151f38403daee9f1e6b0 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab F ext/jni/src/org/sqlite/jni/Tester1.java d4ab6f3f83cbb96e763dd4feb6e5527864d9957eb5e79259bfbe57dcf6d0103e @@ -2116,8 +2116,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 dc0fa76b395c5e352116dc33cc1b455e5e9c9f01c285af52ccba4d37e4453b87 -R 8eeecadbd0aad723daa22691fc77aaf3 +P eb24f97253d9c8e7c728c2ac67a0824b10ca67362ac4f8abb94d5d3c54c58c5b +R b5c8106325c21efbc360de8a5178bfb9 U stephan -Z 2c93c72b42f574b692bce8cc766cb46c +Z a20aea990735784858db150336da744c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f6e2e419ea..84b6d6a05d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eb24f97253d9c8e7c728c2ac67a0824b10ca67362ac4f8abb94d5d3c54c58c5b \ No newline at end of file +aa72d25a22c80a7a376127266b8923f0661147c8bc483baa327230364851a255 \ No newline at end of file From a5f425cc6ea78aed239573fe7af1e30c9b844390 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 16:28:46 +0000 Subject: [PATCH 11/36] Correct a Tester1.java test which inadvertently created a spurious db file in the current dir. Unrelated minor cleanups. FossilOrigin-Name: 016bbdadbf9f95cef185d2606c23e3b3c724586fcca470e11e6fbdbaefd75c79 --- ext/jni/src/c/sqlite3-jni.c | 26 ++-- ext/jni/src/org/sqlite/jni/Tester1.java | 22 ++-- .../src/org/sqlite/jni/tester/SQLTester.java | 24 ++-- ext/jni/src/tests/000-000-sanity.test | 3 +- ext/wasm/SQLTester/SQLTester.mjs | 115 ++++++++++++------ ext/wasm/SQLTester/SQLTester.run.mjs | 3 +- ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js | 4 +- ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 4 +- manifest | 38 +++--- manifest.uuid | 2 +- src/func.c | 6 +- src/json.c | 4 +- src/select.c | 10 +- test/func.test | 6 +- test/json102.test | 3 + test/selectH.test | 29 ++++- 16 files changed, 196 insertions(+), 103 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 0744b99d0a..906bca2a24 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2303,7 +2303,7 @@ S3JniApi(sqlite3_bind_text(),jint,1bind_1text)( return (jint)rc; } -S3JniApi(sqlite3_text16(),jint,1bind_1text16)( +S3JniApi(sqlite3_bind_text16(),jint,1bind_1text16)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0; @@ -2412,7 +2412,7 @@ S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)( jboolean rc = JNI_FALSE; int i; S3JniAutoExt_mutex_enter; - /* This algo mirrors the one in the core. */ + /* This algo corresponds to the one in the core. */ for( i = SJG.autoExt.nExt-1; i >= 0; --i ){ ax = &SJG.autoExt.aExt[i]; if( ax->jObj && (*env)->IsSameObject(env, ax->jObj, jAutoExt) ){ @@ -2430,7 +2430,6 @@ S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)( return rc; } - /* Wrapper for sqlite3_close(_v2)(). */ static jint s3jni_close_db(JNIEnv * const env, jobject jDb, int version){ int rc = 0; @@ -2586,8 +2585,7 @@ S3JniApi(sqlite3_column_text(),jbyteArray,1column_1text)( } #if 0 -// this impl might prove useful, but we'd need to publish the -// bytearray-returning impl with a different name. +// this impl might prove useful. S3JniApi(sqlite3_column_text(),jstring,1column_1text)( JniArgsEnvClass, jobject jpStmt, jint ndx ){ @@ -2648,11 +2646,15 @@ static void s3jni_rollback_hook_impl(void *pP){ (void)s3jni_commit_rollback_hook_impl(0, pP); } +/* +** Proxy for sqlite3_commit_hook() (if isCommit is true) or +** sqlite3_rollback_hook(). +*/ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env, jobject jDb, jobject jHook){ S3JniDb * ps; - jobject pOld = 0; - S3JniHook * pHook; + jobject pOld = 0; /* previous hoook */ + S3JniHook * pHook; /* ps->hooks.commit|rollback */ S3JniDb_mutex_enter; ps = S3JniDb_from_java(jDb); @@ -2684,7 +2686,7 @@ static jobject s3jni_commit_rollback_hook(int isCommit, JNIEnv * const env, S3JniExceptionReport; S3JniExceptionClear; s3jni_db_error(ps->pDb, SQLITE_ERROR, - "Cannot not find matching call() in" + "Cannot not find matching call() method in" "hook object."); }else{ pHook->midCallback = xCallback; @@ -2711,9 +2713,10 @@ S3JniApi(sqlite3_commit_hook(),jobject,1commit_1hook)( S3JniApi(sqlite3_compileoption_get(),jstring,1compileoption_1get)( JniArgsEnvClass, jint n ){ - jstring const rv = (*env)->NewStringUTF( env, sqlite3_compileoption_get(n) ) + const char * z = sqlite3_compileoption_get(n); + jstring const rv = z ? (*env)->NewStringUTF( env, z ) : 0; /* We know these to be ASCII, so MUTF-8 is fine. */; - s3jni_oom_check(rv); + s3jni_oom_check(z ? !!rv : 1); return rv; } @@ -4382,8 +4385,7 @@ S3JniApi(sqlite3_value_text(),jbyteArray,1value_1text)( } #if 0 -// this impl might prove useful, but we'd need to publish the -// bytearray-returning impl with a different name. +// this impl might prove useful. S3JniApi(sqlite3_value_text(),jstring,1value_1text)( JniArgsEnvClass, jobject jpSVal ){ diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index ce8eb6bd23..b4ba626222 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -220,7 +220,15 @@ public class Tester1 implements Runnable { outln("\t"+optName+"\t (used="+ sqlite3_compileoption_used(optName)+")"); } + } + private void testCompileOption(){ + int i = 0; + String optName; + for( ; null != (optName = sqlite3_compileoption_get(i)); ++i){ + } + affirm( i > 10 ); + affirm( null==sqlite3_compileoption_get(-1) ); } private void testOpenDb1(){ @@ -1330,7 +1338,7 @@ public class Tester1 implements Runnable { sqlite3 db = createNewDb(); affirm( 4==val.value ); - execSql(db, "ATTACH ':memory' as foo"); + execSql(db, "ATTACH ':memory:' as foo"); affirm( 4==val.value, "ATTACH uses the same connection, not sub-connections." ); sqlite3_close(db); db = null; @@ -1450,19 +1458,17 @@ public class Tester1 implements Runnable { rc = sqlite3_stmt_explain(stmt, 2); affirm( 2 == sqlite3_stmt_isexplain(stmt) ); sqlite3_finalize(stmt); - - sqlite3_close_v2(db); } private void testLimit(){ final sqlite3 db = createNewDb(); + int v; - int v1, v2; - v1 = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1); - affirm( v1 > 0 ); - affirm( v1 == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, v1-1) ); - affirm( v1-1 == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1) ); + v = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1); + affirm( v > 0 ); + affirm( v == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, v-1) ); + affirm( v-1 == sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1) ); sqlite3_close_v2(db); } diff --git a/ext/jni/src/org/sqlite/jni/tester/SQLTester.java b/ext/jni/src/org/sqlite/jni/tester/SQLTester.java index 47d6b6f3ef..517d8c30a5 100644 --- a/ext/jni/src/org/sqlite/jni/tester/SQLTester.java +++ b/ext/jni/src/org/sqlite/jni/tester/SQLTester.java @@ -475,12 +475,12 @@ public class SQLTester { the db's result code. appendMode specifies how/whether to append results to the result - buffer. lineMode specifies whether to output all results in a + buffer. rowMode specifies whether to output all results in a single line or one line per row. If appendMode is - ResultBufferMode.NONE then lineMode is ignored and may be null. + ResultBufferMode.NONE then rowMode is ignored and may be null. */ public int execSql(sqlite3 db, boolean throwOnError, - ResultBufferMode appendMode, ResultRowMode lineMode, + ResultBufferMode appendMode, ResultRowMode rowMode, String sql) throws SQLTesterException { if( null==db && null==aDb[0] ){ // Delay opening of the initial db to enable tests to change its @@ -562,7 +562,7 @@ public class SQLTester { throw new SQLTesterException("Unhandled ResultBufferMode: "+appendMode); } } - if( ResultRowMode.NEWLINE == lineMode ){ + if( ResultRowMode.NEWLINE == rowMode ){ spacing = 0; sb.append('\n'); } @@ -1128,8 +1128,9 @@ class TestScript { } public String getOutputPrefix(){ - String rc = "["+(moduleName==null ? filename : moduleName)+"]"; + String rc = "["+(moduleName==null ? "" : moduleName)+"]"; if( null!=testCaseName ) rc += "["+testCaseName+"]"; + if( null!=filename ) rc += "["+filename+"]"; return rc + " line "+ cur.lineNo; } @@ -1273,6 +1274,7 @@ class TestScript { } private boolean checkRequiredProperties(SQLTester t, String[] props) throws SQLTesterException{ + if( true ) return false; int nOk = 0; for(String rp : props){ verbose1("REQUIRED_PROPERTIES: ",rp); @@ -1293,6 +1295,12 @@ class TestScript { t.appendDbInitSql("pragma temp_store=0;"); ++nOk; break; + case "AUTOVACUUM": + t.appendDbInitSql("pragma auto_vacuum=full;"); + ++nOk; + case "INCRVACUUM": + t.appendDbInitSql("pragma auto_vacuum=incremental;"); + ++nOk; default: break; } @@ -1331,9 +1339,9 @@ class TestScript { m = patternRequiredProperties.matcher(line); if( m.find() ){ final String rp = m.group(1); - //if( ! checkRequiredProperties( tester, rp.split("\\s+") ) ){ - throw new IncompatibleDirective(this, "REQUIRED_PROPERTIES: "+rp); - //} + if( ! checkRequiredProperties( tester, rp.split("\\s+") ) ){ + throw new IncompatibleDirective(this, "REQUIRED_PROPERTIES: "+rp); + } } m = patternMixedModuleName.matcher(line); if( m.find() ){ diff --git a/ext/jni/src/tests/000-000-sanity.test b/ext/jni/src/tests/000-000-sanity.test index 2bfacb1cec..4ccbece31c 100644 --- a/ext/jni/src/tests/000-000-sanity.test +++ b/ext/jni/src/tests/000-000-sanity.test @@ -6,7 +6,8 @@ ** xMODULE_NAME: module-name ** xREQUIRED_PROPERTIES: small fast reliable ** xREQUIRED_PROPERTIES: RECURSIVE_TRIGGERS -** xREQUIRED_PROPERTIES: TEMPSTORE_MEM TEMPSTORE_FILE +** xREQUIRED_PROPERTIES: TEMPSTORE_FILE TEMPSTORE_MEM +** xREQUIRED_PROPERTIES: AUTOVACUUM INCRVACUUM ** */ --print starting up 😃 diff --git a/ext/wasm/SQLTester/SQLTester.mjs b/ext/wasm/SQLTester/SQLTester.mjs index 8741b81524..a72399aefc 100644 --- a/ext/wasm/SQLTester/SQLTester.mjs +++ b/ext/wasm/SQLTester/SQLTester.mjs @@ -112,12 +112,6 @@ class SQLTesterException extends globalThis.Error { } this.name = 'SQLTesterException'; } - /** - If this overrideable method returns false (the default) then - exceptions of that type are fatal to a whole test run, instead of - just the test which triggered it. If the the "keep going" flag - is set, this preference is ignored. - */ isFatal() { return false; } } @@ -169,6 +163,7 @@ const __SAB = ('undefined'===typeof globalThis.SharedArrayBuffer) ? function(){} : globalThis.SharedArrayBuffer; +/* Frequently-reused regexes. */ const Rx = newObj({ requiredProperties: / REQUIRED_PROPERTIES:[ \t]*(\S.*)\s*$/, scriptModuleName: / SCRIPT_MODULE_NAME:[ \t]*(\S+)\s*$/, @@ -176,7 +171,6 @@ const Rx = newObj({ command: /^--(([a-z-]+)( .*)?)$/, //! "Special" characters - we have to escape output if it contains any. special: /[\x00-\x20\x22\x5c\x7b\x7d]/, - //! Either of '{' or '}'. squiggly: /[{}]/ }); @@ -189,7 +183,7 @@ const Util = newObj({ argvToString: (list)=>{ const m = [...list]; - m.shift(); + m.shift() /* strip command name */; return m.join(" ") }, @@ -257,9 +251,10 @@ class Outer { } } + static #verboseLabel = ["🔈",/*"🔉",*/"🔊","📢"]; verboseN(lvl, args){ if( this.#verbosity>=lvl ){ - this.#outlnImpl(lvl,'VERBOSE ',lvl,': ',...args); + this.#outlnImpl(lvl, Outer.#verboseLabel[lvl-1],': ',...args); } } verbose1(...args){ return this.verboseN(1,args); } @@ -364,8 +359,24 @@ class SQLTester { this.#resultBuffer.push(line); if( addNL ) this.#resultBuffer.push('\n'); } + appendDbInitSql(sql){ + this.#db.initSql.push(sql); + if( this.currentDb() ){ + this.execSql(null, true, ResultBufferMode.NONE, null, sql); + } + } - #clearBuffer(buffer){ + #runInitSql(pDb){ + let rc = 0; + for(const sql of this.#db.initSql){ + this.#outer.verbose2("RUNNING DB INIT CODE: ",sql); + rc = this.execSql(pDb, false, ResultBufferMode.NONE, null, sql); + if( rc ) break; + } + return rc; + } + +#clearBuffer(buffer){ buffer.length = 0; return buffer; } @@ -390,27 +401,21 @@ class SQLTester { } nullValue(){ - if( 0==arguments.length ){ - return this.#nullView; - }else{ - this.#nullView = ''+arguments[0]; - } + return (0==arguments.length) + ? this.#nullView + : (this.#nullView = ''+arguments[0]); } outputColumnNames(){ - if( 0==arguments.length ){ - return this.#emitColNames; - }else{ - this.#emitColNames = !!arguments[0]; - } + return (0==arguments.length) + ? this.#emitColNames + : (this.#emitColNames = !!arguments[0]); } currentDbId(){ - if( 0==arguments.length ){ - return this.#db.iCurrentDb; - }else{ - this.#affirmDbId(arguments[0]).#db.iCurrentDb = arguments[0]; - } + return (0==arguments.length) + ? this.#db.iCurrentDb + : (this.#affirmDbId(arguments[0]).#db.iCurrentDb = arguments[0]); } #affirmDbId(id){ @@ -438,9 +443,9 @@ class SQLTester { if( 0==arguments.length ){ id = this.#db.iCurrentDb; } - const db = this.#affirmDbId(id).#db.list[id]; - if( db ){ - sqlite3.capi.sqlite3_close_v2(db); + const pDb = this.#affirmDbId(id).#db.list[id]; + if( pDb ){ + sqlite3.capi.sqlite3_close_v2(pDb); this.#db.list[id] = null; } } @@ -474,10 +479,9 @@ class SQLTester { rc = sqlite3.capi.sqlite3_open_v2(name, ppOut, flags, null); pDb = wasm.peekPtr(ppOut); }); + let sql; if( 0==rc && this.#db.initSql.length > 0){ - this.#outer.verbose2("RUNNING DB INIT CODE: ",this.#db.initSql.toString()); - rc = this.execSql(pDb, false, ResultBufferMode.NONE, - null, this.#db.initSql.join('')); + rc = this.#runInitSql(pDb); } if( 0!=rc ){ sqlite3.SQLite3Error.toss( @@ -613,7 +617,7 @@ class SQLTester { sqlite3.oo1.DB.checkRc(pDb, rc); } - execSql(pDb, throwOnError, appendMode, lineMode, sql){ + execSql(pDb, throwOnError, appendMode, rowMode, sql){ if( !pDb && !this.#db.list[0] ){ this.#setupInitialDb(); } @@ -685,7 +689,7 @@ class SQLTester { } }/* column loop */ }/* row loop */ - if( ResultRowMode.NEWLINE === lineMode ){ + if( ResultRowMode.NEWLINE === rowMode ){ spacing = 0; sb.push('\n'); } @@ -806,8 +810,9 @@ class TestScript { } getOutputPrefix() { - let rc = "["+(this.#moduleName || this.#filename)+"]"; + let rc = "["+(this.#moduleName || '')+"]"; if( this.#testCaseName ) rc += "["+this.#testCaseName+"]"; + if( this.#filename ) rc += '['+this.#filename+']'; return rc + " line "+ this.#cursor.lineNo; } @@ -829,6 +834,42 @@ class TestScript { return args.length ? this : rc; } + #checkRequiredProperties(tester, props){ + if(true) return false; + let nOk = 0; + for(const rp of props){ + this.verbose2("REQUIRED_PROPERTIES: ",rp); + switch(rp){ + case "RECURSIVE_TRIGGERS": + tester.appendDbInitSql("pragma recursive_triggers=on;"); + ++nOk; + break; + case "TEMPSTORE_FILE": + /* This _assumes_ that the lib is built with SQLITE_TEMP_STORE=1 or 2, + which we just happen to know is the case */ + tester.appendDbInitSql("pragma temp_store=1;"); + ++nOk; + break; + case "TEMPSTORE_MEM": + /* This _assumes_ that the lib is built with SQLITE_TEMP_STORE=1 or 2, + which we just happen to know is the case */ + tester.appendDbInitSql("pragma temp_store=0;"); + ++nOk; + break; + case "AUTOVACUUM": + tester.appendDbInitSql("pragma auto_vacuum=full;"); + ++nOk; + break; + case "INCRVACUUM": + tester.appendDbInitSql("pragma auto_vacuum=incremental;"); + ++nOk; + default: + break; + } + } + return props.length == nOk; + } + #checkForDirective(tester,line){ if(line.startsWith("#")){ throw new IncompatibleDirective(this, "C-preprocessor input: "+line); @@ -843,9 +884,9 @@ class TestScript { m = Rx.requiredProperties.exec(line); if( m ){ const rp = m[1]; - //if( ! checkRequiredProperties( tester, rp.split("\\s+") ) ){ - throw new IncompatibleDirective(this, "REQUIRED_PROPERTIES: "+rp); - //} + if( !this.#checkRequiredProperties( tester, rp.split(/\s+/).filter(v=>!!v) ) ){ + throw new IncompatibleDirective(this, "REQUIRED_PROPERTIES: "+rp); + } } m = Rx.mixedModuleName.exec(line); diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index 0f91230fd0..735fe4dcd8 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -42,7 +42,8 @@ let ts = new ns.TestScript('/foo.test',` ** xMODULE_NAME: module-name ** xREQUIRED_PROPERTIES: small fast reliable ** xREQUIRED_PROPERTIES: RECURSIVE_TRIGGERS -** xREQUIRED_PROPERTIES: TEMPSTORE_MEM TEMPSTORE_FILE +** xREQUIRED_PROPERTIES: TEMPSTORE_FILE TEMPSTORE_MEM +** xREQUIRED_PROPERTIES: AUTOVACUUM INCRVACUUM ** */ /* --verbosity 3 */ diff --git a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js index 8e874f7282..327b6a95ad 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js @@ -895,7 +895,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ sah.read( header, {at: 0} ); util.affirmDbHeader( header ); } - sah.write(new Uint8Array(2), { + sah.write(new Uint8Array([1,1]), { at: HEADER_OFFSET_DATA + 18 }/*force db out of WAL mode*/); }catch(e){ @@ -927,7 +927,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ this.setAssociatedPath(sah, '', 0); toss("Expected to write "+n+" bytes but wrote "+nWrote+"."); }else{ - sah.write(new Uint8Array([0,0]), {at: HEADER_OFFSET_DATA+18} + sah.write(new Uint8Array([1,1]), {at: HEADER_OFFSET_DATA+18} /* force db out of WAL mode */); this.setAssociatedPath(sah, name, capi.SQLITE_OPEN_MAIN_DB); } diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index ca2fde985e..af89f216f7 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -1197,7 +1197,7 @@ const installOpfsVfs = function callee(options){ sah.read( header, {at: 0} ); util.affirmDbHeader( header ); } - sah.write(new Uint8Array(2), {at: 18}/*force db out of WAL mode*/); + sah.write(new Uint8Array([1,1]), {at: 18}/*force db out of WAL mode*/); return nWrote; }catch(e){ await sah.close(); @@ -1255,7 +1255,7 @@ const installOpfsVfs = function callee(options){ if(nWrote != n){ toss("Expected to write "+n+" bytes but wrote "+nWrote+"."); } - sah.write(new Uint8Array(2), {at: 18}) /* force db out of WAL mode */; + sah.write(new Uint8Array([1,1]), {at: 18}) /* force db out of WAL mode */; return nWrote; }catch(e){ if( sah ){ await sah.close(); sah = undefined; } diff --git a/manifest b/manifest index d03e82d999..23e22a86e7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\sJNI-internal\smetrics\sopt-in\srather\sthan\sopt-out\sso\sclient\sbuilds\swon't\shave\sthem\sby\sdefault.\sUnrelated\sdoc\stweaks. -D 2023-09-01T14:20:39.576 +C Correct\sa\sTester1.java\stest\swhich\sinadvertently\screated\sa\sspurious\sdb\sfile\sin\sthe\scurrent\sdir.\sUnrelated\sminor\scleanups. +D 2023-09-01T16:28:46.444 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 3e0e28c1c451eab31dd4fa9d262951ef67ed3ece3270a2efc8ec66ec57068547 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 0a814e8dbc333ff8a1a8a74aebaece435d2982ed6d4d8e8bf9b7082688b20221 +F ext/jni/src/c/sqlite3-jni.c 00469db3f64a7f53bc1ecb60749260b937f8892ddc56d4c61d5f427f6e6758a7 F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -265,7 +265,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java d4ab6f3f83cbb96e763dd4feb6e5527864d9957eb5e79259bfbe57dcf6d0103e +F ext/jni/src/org/sqlite/jni/Tester1.java 2a6ef03fca523280731a88f697cdc8ece9548cd4cbe7e1cc90823e5bb5998e27 F ext/jni/src/org/sqlite/jni/TesterFts5.java 02b59ea7d75666fd565d90bb8dc7b0c09441bb9d1af091fad9f6d7377297a474 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -284,9 +284,9 @@ F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c38 F ext/jni/src/org/sqlite/jni/sqlite3_context.java 66ca95ce904044263a4aff684abe262d56f73e6b06bca6cf650761d79d7779ad F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a -F ext/jni/src/org/sqlite/jni/tester/SQLTester.java e5a1a4b55ed940e61558be1292aa66563219f360c7c1f9d40d770307e6da3c07 +F ext/jni/src/org/sqlite/jni/tester/SQLTester.java a6863d0284c8ec8ca5abd3d40e1fb297e7ae57fb97282ba335cd896a770e3918 F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md f9f25126127045d051e918fe59004a1485311c50a13edbf18c79a6ff9160030e -F ext/jni/src/tests/000-000-sanity.test cfe6dc1b950751d6096e3f5695becaadcdaa048bfe9567209d6eb676e693366d +F ext/jni/src/tests/000-000-sanity.test c3427a0e0ac84d7cbe4c95fdc1cd4b61f9ddcf43443408f3000139478c4dc745 F ext/jni/src/tests/000-001-ignored.test e17e874c6ab3c437f1293d88093cf06286083b65bf162317f91bbfd92f961b70 F ext/jni/src/tests/900-001-fts.test bf0ce17a8d082773450e91f2388f5bbb2dfa316d0b676c313c637a91198090f0 F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9 @@ -550,8 +550,8 @@ F ext/wasm/GNUmakefile 0e362f3fc04eab6628cbe4f1e35f4ab4a200881f6b5f753b27fb45eab F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff -F ext/wasm/SQLTester/SQLTester.mjs 20309ff838209601711087932b008734bab00176e6a47e41d95e11f6d363bae0 -F ext/wasm/SQLTester/SQLTester.run.mjs addeb962f33fb6bca723ab12f0b018303ff962dfc57ee969d051fcbf4f191569 +F ext/wasm/SQLTester/SQLTester.mjs ec2f6ba63a0f2f0562941a0fb8e46b7dc55589711513f1952349785966edfe50 +F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 F ext/wasm/SQLTester/index.html 3a12895015c165281307eb47786ce3c46b3c3f06383ad6a9fe3a8526105632f1 F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab @@ -571,8 +571,8 @@ F ext/wasm/api/sqlite3-api-worker1.js 9f32af64df1a031071912eea7a201557fe39b17386 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 8cf8a897726f14071fae6be6648125162b256dfb4f96555b865dbb7a6b65e379 F ext/wasm/api/sqlite3-v-helper.js 7daa0eab0a513a25b05e9abae7b5beaaa39209b3ed12f86aeae9ef8d2719ed25 -F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 561463ac5380e4ccf1839a1922e6d7a5585660f32e3b9701a270b78cd35566cf -F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js d9e62d42b86f7bb3143eb071628b24e2ba7dcc749e41a0e9d3e2451bfea1a6b6 +F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 327a8c363a8c84c61770dc3c46cc83d7cc0eb6b59a3b29728bddf087651d3b77 +F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 46c4afa6c50d7369252c104f274ad977a97e91ccfafc38b400fe36e90bdda88e F ext/wasm/api/sqlite3-wasm.c 65d60439671e24d50d9119ca805ac1c68fb36129e164377eb46f8d037bd88b07 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js bc06df0d599e625bde6a10a394e326dc68da9ff07fa5404354580f81566e591f F ext/wasm/api/sqlite3-worker1.c-pp.js da509469755035e919c015deea41b4514b5e84c12a1332e6cc8d42cb2cc1fb75 @@ -659,14 +659,14 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 1affe0cc049683ef0ef3545d9b6901508556b0ef7e2892a344c3df6d7288d79d F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c a7fcbf7e66d14dbb73cf49f31489ebf66d0e6006c62b95246924a3bae9f37b36 -F src/func.c c96c7f55b97493ce278937e6ab6578a866b7e5d6dd486d58b220e9d17e88a750 +F src/func.c 154f08966f8a3a7cad6c438205df1abf58fb2826961a0683e82e120fa647e84c F src/global.c 29f56a330ed9d1b5cd9b79ac0ca36f97ac3afc730ff8bfa987b0db9e559d684d F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 -F src/json.c ae840f87b418f039f5d336b488933d09396bd31e6b31e855b93055ccaee4e255 +F src/json.c 51141f1c09ccb177057e5813e6302a5e32e5ba88cc4a756318a35081010fc6df F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c 2adfb1973ee495977f8c75d6590aae9882161d5f8749b46621299656a2df0cc6 @@ -706,7 +706,7 @@ F src/printf.c e3ba080e2f409f9bfcc8d34724e6fc160e9c718dc92d0548f6b71b8b6f860ce2 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 37953a5f36c60bea413c3c04efcd433b6177009f508ef2ace0494728912fe2e9 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 -F src/select.c 5f545a2c8702d4d3430bbb188cfec47d6c122d899061ef00cbe56af14591c574 +F src/select.c e9fb48546ab1882639a3a960383f6342dddb776c0227615f8e19de51f0102f68 F src/shell.c.in 2f9be25294b68b07e7e81f0adcec4475aba6011b64f160e414efe226910c4d7b F src/sqlite.h.in 7dbea32976fb18740214edc314253c902e127dac7645a705e566644ed4aa5ef5 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1179,7 +1179,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test 719076723b13a6bfcff7b00b7987b1d7b06876ceb71e868b3d13d571d9b42cae +F test/func.test cbcf086273529d4a99b7199086da637a99039d2cad81dd7d7c4c9e25258ae164 F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test 2285fb5792d593fef442358763f0fd9de806eda47dbc7a5934df57ffdc484c31 @@ -1298,7 +1298,7 @@ F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd286 F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307 F test/json/json-speed-check.sh 8b7babf530faa58bd59d6d362cec8e9036a68c5457ff46f3b1f1511d21af6737 x F test/json101.test dc9d5a2a5b1fd1b54dbd71c538b17933cc98d84b4c1f821ead754933663dca55 -F test/json102.test 24f6f204f9cde45b971016691d0b92a9b4c58040d699e36d6b12cb165f9083ff +F test/json102.test 4c69694773a470f1fda34e5f4ba24920b35184fb66050b450fc2ef9ab5ad310b F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1 F test/json105.test 11670a4387f4308ae0318cadcbd6a918ea7edcd19fbafde020720a073952675d @@ -1525,7 +1525,7 @@ F test/selectD.test 6d1909b49970bf92f45ce657505befcef5fc7cbc13544e18103a316d3218 F test/selectE.test a8730ca330fcf40ace158f134f4fe0eb00c7edbf F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3 F test/selectG.test 089f7d3d7e6db91566f00b036cb353107a2cca6220eb1cb264085a836dae8840 -F test/selectH.test 88237ded5925adfb3f27fdafb5428c2ffc4d61e313bceb854e225ffc3ef0d206 +F test/selectH.test 0b54599f1917d99568c9b929df22ec6261ed7b6d2f02a46b5945ef81b7871aac F test/session.test 78fa2365e93d3663a6e933f86e7afc395adf18be F test/sessionfuzz-data1.db 1f8d5def831f19b1c74571037f0d53a588ea49a6c4ca2a028fc0c27ef896dbcb F test/sessionfuzz.c 5eef09af01eeff6f20250ae4c0112c2e576e4d2f2026cc9a49dc5be6886fa6ee @@ -2116,8 +2116,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 eb24f97253d9c8e7c728c2ac67a0824b10ca67362ac4f8abb94d5d3c54c58c5b -R b5c8106325c21efbc360de8a5178bfb9 +P aa72d25a22c80a7a376127266b8923f0661147c8bc483baa327230364851a255 +R 42c737a27d848aaab44302c5d742eacf U stephan -Z a20aea990735784858db150336da744c +Z 76973b081c5a9e008b03ef52a45413be # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 84b6d6a05d..7b3492731b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aa72d25a22c80a7a376127266b8923f0661147c8bc483baa327230364851a255 \ No newline at end of file +016bbdadbf9f95cef185d2606c23e3b3c724586fcca470e11e6fbdbaefd75c79 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 3332523486..8739035b5b 100644 --- a/src/func.c +++ b/src/func.c @@ -1907,7 +1907,8 @@ static void avgFinalize(sqlite3_context *context){ if( p && p->cnt>0 ){ double r; if( p->approx ){ - r = p->rSum+p->rErr; + r = p->rSum; + if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } @@ -1920,7 +1921,8 @@ static void totalFinalize(sqlite3_context *context){ p = sqlite3_aggregate_context(context, 0); if( p ){ if( p->approx ){ - r = p->rSum+p->rErr; + r = p->rSum; + if( !sqlite3IsNaN(p->rErr) ) r += p->rErr; }else{ r = (double)(p->iSum); } diff --git a/src/json.c b/src/json.c index f8d4aa2a77..253fce9f49 100644 --- a/src/json.c +++ b/src/json.c @@ -2484,7 +2484,9 @@ static void jsonArrayLengthFunc( } if( pNode->eType==JSON_ARRAY ){ while( 1 /*exit-by-break*/ ){ - for(i=1; i<=pNode->n; n++){ + i = 1; + while( i<=pNode->n ){ + if( (pNode[i].jnFlags & JNODE_REMOVE)==0 ) n++; i += jsonNodeSize(&pNode[i]); } if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; diff --git a/src/select.c b/src/select.c index 321badd07f..90b284036c 100644 --- a/src/select.c +++ b/src/select.c @@ -5301,12 +5301,12 @@ static int disableUnusedSubqueryResultColumns(SrcItem *pItem){ assert( pItem->pSelect!=0 ); pSub = pItem->pSelect; assert( pSub->pEList->nExpr==pTab->nCol ); - if( (pSub->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){ - testcase( pSub->selFlags & SF_Distinct ); - testcase( pSub->selFlags & SF_Aggregate ); - return 0; - } for(pX=pSub; pX; pX=pX->pPrior){ + if( (pX->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){ + testcase( pX->selFlags & SF_Distinct ); + testcase( pX->selFlags & SF_Aggregate ); + return 0; + } if( pX->pPrior && pX->op!=TK_ALL ){ /* This optimization does not work for compound subqueries that ** use UNION, INTERSECT, or EXCEPT. Only UNION ALL is allowed. */ diff --git a/test/func.test b/test/func.test index 4743e109bd..aea372e08e 100644 --- a/test/func.test +++ b/test/func.test @@ -1549,8 +1549,8 @@ do_catchsql_test func-37.120 { # Incorrect handling of infinity by SUM(). # do_execsql_test func-38.100 { - WITH t1(x) AS (VALUES(9e+999)) SELECT sum(x) FROM t1; - WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x) FROM t1; -} {Inf -Inf} + WITH t1(x) AS (VALUES(9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; + WITH t1(x) AS (VALUES(-9e+999)) SELECT sum(x), avg(x), total(x) FROM t1; +} {Inf Inf Inf -Inf -Inf -Inf} finish_test diff --git a/test/json102.test b/test/json102.test index 276c1816a7..ce901efeb1 100644 --- a/test/json102.test +++ b/test/json102.test @@ -48,6 +48,9 @@ do_execsql_test json102-180 { do_execsql_test json102-190 { SELECT json_array_length('[1,2,3,4]'); } {{4}} +do_execsql_test json102-191 { + SELECT json_array_length( json_remove('[1,2,3,4]','$[2]') ); +} {{3}} do_execsql_test json102-200 { SELECT json_array_length('[1,2,3,4]', '$'); } {{4}} diff --git a/test/selectH.test b/test/selectH.test index a97679bda2..41f0999fe3 100644 --- a/test/selectH.test +++ b/test/selectH.test @@ -113,6 +113,33 @@ do_execsql_test 4.1 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); SELECT 1 FROM (SELECT DISTINCT name COLLATE rtrim FROM sqlite_schema UNION ALL SELECT a FROM t1); -} 1 +} {1 1} + +do_execsql_test 4.2 { + SELECT DISTINCT name COLLATE rtrim FROM sqlite_schema + UNION ALL + SELECT a FROM t1 +} {v1 t1} + +#------------------------------------------------------------------------- +# forum post https://sqlite.org/forum/forumpost/b83c7b2168 +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1 (val1); + INSERT INTO t1 VALUES(4); + INSERT INTO t1 VALUES(5); + CREATE TABLE t2 (val2); +} +do_execsql_test 5.1 { + SELECT DISTINCT val1 FROM t1 UNION ALL SELECT val2 FROM t2; +} { + 4 5 +} +do_execsql_test 5.2 { + SELECT count(1234) FROM ( + SELECT DISTINCT val1 FROM t1 UNION ALL SELECT val2 FROM t2 + ) +} {2} finish_test From 49a40ef6d242e8babc2697fa6b2208b62ebb93de Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 1 Sep 2023 17:51:09 +0000 Subject: [PATCH 12/36] Add a timer to the JS SQLTester app to warn if it appears that loading the module has failed, which is commonly caused by the test scripts not being compiled. FossilOrigin-Name: f9c1f9cad1ad22f689a4afa13d59bf9969ddaed6624cbc16cb1bf5d1fd0c8a5b --- ext/wasm/SQLTester/index.html | 8 ++++++++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ext/wasm/SQLTester/index.html b/ext/wasm/SQLTester/index.html index cd1423ac37..1dffad63e2 100644 --- a/ext/wasm/SQLTester/index.html +++ b/ext/wasm/SQLTester/index.html @@ -96,6 +96,13 @@ logClass('','index.html:',...args); return f; }; + + const timerId = setTimeout( ()=>{ + logClass('error',"The SQLTester module is taking an unusually ", + "long time to load. More information may be available", + "in the dev console."); + }, 3000 /* assuming localhost */ ); + W.onmessage = function({data}){ switch(data.type){ case 'stdout': log2(data.payload.message); break; @@ -105,6 +112,7 @@ log("test results:",data.payload); break; case 'is-ready': + clearTimeout(timerId); runTests(); break; default: log("unhandled onmessage",data); diff --git a/manifest b/manifest index 23e22a86e7..8128a83550 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Correct\sa\sTester1.java\stest\swhich\sinadvertently\screated\sa\sspurious\sdb\sfile\sin\sthe\scurrent\sdir.\sUnrelated\sminor\scleanups. -D 2023-09-01T16:28:46.444 +C Add\sa\stimer\sto\sthe\sJS\sSQLTester\sapp\sto\swarn\sif\sit\sappears\sthat\sloading\sthe\smodule\shas\sfailed,\swhich\sis\scommonly\scaused\sby\sthe\stest\sscripts\snot\sbeing\scompiled. +D 2023-09-01T17:51:09.091 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -552,7 +552,7 @@ F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff F ext/wasm/SQLTester/SQLTester.mjs ec2f6ba63a0f2f0562941a0fb8e46b7dc55589711513f1952349785966edfe50 F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 -F ext/wasm/SQLTester/index.html 3a12895015c165281307eb47786ce3c46b3c3f06383ad6a9fe3a8526105632f1 +F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b @@ -2116,8 +2116,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 aa72d25a22c80a7a376127266b8923f0661147c8bc483baa327230364851a255 -R 42c737a27d848aaab44302c5d742eacf +P 016bbdadbf9f95cef185d2606c23e3b3c724586fcca470e11e6fbdbaefd75c79 +R 4133358901b76bfadefddc6665a81e23 U stephan -Z 76973b081c5a9e008b03ef52a45413be +Z eab9aeb866f5eecf9b7d34e391979f20 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7b3492731b..dcede0167e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -016bbdadbf9f95cef185d2606c23e3b3c724586fcca470e11e6fbdbaefd75c79 \ No newline at end of file +f9c1f9cad1ad22f689a4afa13d59bf9969ddaed6624cbc16cb1bf5d1fd0c8a5b \ No newline at end of file From 63f4a9c4db36f80a2e8fc5ba65c729cba819c1f2 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 08:51:14 +0000 Subject: [PATCH 13/36] Further JNI cleanups. FossilOrigin-Name: 30e38173c3ece0c9f8e7a9710f46cb5e8e8ef101c04531318a7adb070242f5dd --- ext/jni/GNUmakefile | 1 - ext/jni/src/c/sqlite3-jni.c | 260 ++++++++++-------- .../src/org/sqlite/jni/Fts5ExtensionApi.java | 34 ++- ext/jni/src/org/sqlite/jni/Fts5Function.java | 27 -- ext/jni/src/org/sqlite/jni/Tester1.java | 9 +- ext/jni/src/org/sqlite/jni/TesterFts5.java | 45 +-- ext/jni/src/org/sqlite/jni/fts5_api.java | 43 +-- .../sqlite/jni/fts5_extension_function.java | 20 +- manifest | 25 +- manifest.uuid | 2 +- 10 files changed, 262 insertions(+), 204 deletions(-) delete mode 100644 ext/jni/src/org/sqlite/jni/Fts5Function.java diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 346351b06b..92819688d8 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -110,7 +110,6 @@ ifeq (1,$(enable.fts5)) Fts5.java \ Fts5Context.java \ Fts5ExtensionApi.java \ - Fts5Function.java \ Fts5PhraseIter.java \ Fts5Tokenizer.java \ TesterFts5.java \ diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 906bca2a24..d54cc1ca9c 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -269,6 +269,8 @@ static void * s3jni_realloc_or_die(JNIEnv * const env, void * p, size_t n){ #endif //#define S3JniDb_oom(pDb,EXPR) ((EXPR) ? sqlite3OomFault(pDb) : 0) +#define s3jni_db_oom(pDb) (void)((pDb) ? ((pDb)->mallocFailed=1) : 0) + /* Helpers for Java value reference management. */ static jobject s3jni_ref_global(JNIEnv * const env, jobject const v){ jobject const rv = v ? (*env)->NewGlobalRef(env, v) : NULL; @@ -402,7 +404,7 @@ struct S3JniNphClass { */ jclass klazz; volatile jmethodID midCtor /* klazz's no-arg constructor. Used by - ** new_NativePointerHolder_object(). */; + ** NativePointerHolder_new(). */; volatile jfieldID fidValue /* NativePointerHolder.nativePointer or ** OutputPointer.T.value */; volatile jfieldID fidAggCtx /* sqlite3_context.aggregateContext, used only @@ -464,7 +466,10 @@ struct S3JniDb { #endif } hooks; #ifdef SQLITE_ENABLE_FTS5 - jobject jFtsApi /* global ref to s3jni_fts5_api_from_db() */; + /* FTS5-specific state */ + struct { + jobject jApi /* global ref to s3jni_fts5_api_from_db() */; + } fts; #endif S3JniDb * pNext /* Next entry in SJG.perDb.aFree */; }; @@ -581,18 +586,22 @@ struct S3JniGlobalType { /* Global mutex. */ sqlite3_mutex * mutex; /* - ** Cache of Java refs and method IDs for NativePointerHolder - ** subclasses and OutputPointer.T types. + ** Cache of references to Java classes and method IDs for + ** NativePointerHolder subclasses and OutputPointer.T types. */ - S3JniNphClass nph[S3Jni_NphCache_size]; + struct { + S3JniNphClass list[S3Jni_NphCache_size]; + sqlite3_mutex * mutex; /* mutex for this->list */ + void const * locker; /* sanity-checking-only context object + for this->mutex */ + } nph; /* ** Cache of per-thread state. */ struct { S3JniEnv * aHead /* Linked list of in-use instances */; S3JniEnv * aFree /* Linked list of free instances */; - sqlite3_mutex * mutex /* mutex for aHead and aFree, and first-time - inits of nph[] entries. */; + sqlite3_mutex * mutex /* mutex for aHead and aFree. */; void const * locker /* env mutex is held on this object's behalf. Used only for sanity checking. */; } envCache; @@ -642,7 +651,7 @@ struct S3JniGlobalType { } autoExt; #ifdef SQLITE_ENABLE_FTS5 struct { - volatile jobject jFtsExt /* Global ref to Java singleton for the + volatile jobject jExt /* Global ref to Java singleton for the Fts5ExtensionApi instance. */; struct { jfieldID fidA /* Fts5Phrase::a member */; @@ -665,7 +674,7 @@ struct S3JniGlobalType { volatile unsigned nEnvAlloc; volatile unsigned nMutexEnv /* number of times envCache.mutex was entered for a S3JniEnv operation. */; - volatile unsigned nMutexEnv2 /* number of times envCache.mutex was entered */; + volatile unsigned nMutexNph /* number of times SJG.mutex was entered for NPH init */; volatile unsigned nMutexPerDb /* number of times perDb.mutex was entered */; volatile unsigned nMutexAutoExt /* number of times autoExt.mutex was entered */; volatile unsigned nMutexGlobal /* number of times global mutex was entered. */; @@ -730,11 +739,11 @@ static void s3jni_incr( volatile unsigned int * const p ){ SJG.envCache.locker = 0; \ sqlite3_mutex_leave( SJG.envCache.mutex ) -#define S3JniAutoExt_mutex_enter \ +#define S3JniAutoExt_mutex_enter \ sqlite3_mutex_enter( SJG.autoExt.mutex ); \ SJG.autoExt.locker = env; \ s3jni_incr( &SJG.metrics.nMutexAutoExt ) -#define S3JniAutoExt_mutex_leave \ +#define S3JniAutoExt_mutex_leave \ assert( env == SJG.autoExt.locker && "Misuse of S3JniGlobal.autoExt.mutex" ); \ sqlite3_mutex_leave( SJG.autoExt.mutex ) #define S3JniAutoExt_mutex_assertLocker \ @@ -743,29 +752,28 @@ static void s3jni_incr( volatile unsigned int * const p ){ #define S3JniGlobal_mutex_enter \ sqlite3_mutex_enter( SJG.mutex ); \ s3jni_incr(&SJG.metrics.nMutexGlobal); -#define S3JniGlobal_mutex_leave \ - sqlite3_mutex_leave( SJG.mutex ) +#define S3JniGlobal_mutex_leave sqlite3_mutex_leave( SJG.mutex ) -#define S3JniNph_mutex_enter \ - S3JniEnv_mutex_assertNotLocker; \ - sqlite3_mutex_enter( SJG.envCache.mutex ); \ - s3jni_incr( &SJG.metrics.nMutexEnv2 ); \ - SJG.envCache.locker = env -#define S3JniNph_mutex_leave \ - S3JniEnv_mutex_assertLocker; \ - SJG.envCache.locker = 0; \ - sqlite3_mutex_leave( SJG.envCache.mutex ) +#define S3JniNph_mutex_enter \ + sqlite3_mutex_enter( SJG.nph.mutex ); \ + assert( !SJG.nph.locker && "Misuse of S3JniGlobal.nph.mutex" ); \ + s3jni_incr( &SJG.metrics.nMutexNph ); \ + SJG.nph.locker = env +#define S3JniNph_mutex_leave \ + assert( (env) == SJG.nph.locker && "Misuse of S3JniGlobal.nph.mutex" ); \ + SJG.nph.locker = 0; \ + sqlite3_mutex_leave( SJG.nph.mutex ) #define S3JniDb_mutex_assertLocker \ assert( (env) == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ) -#define S3JniDb_mutex_enter \ - sqlite3_mutex_enter( SJG.perDb.mutex ); \ +#define S3JniDb_mutex_enter \ + sqlite3_mutex_enter( SJG.perDb.mutex ); \ assert( 0==SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ - s3jni_incr( &SJG.metrics.nMutexPerDb ); \ + s3jni_incr( &SJG.metrics.nMutexPerDb ); \ SJG.perDb.locker = env; -#define S3JniDb_mutex_leave \ +#define S3JniDb_mutex_leave \ assert( env == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ - SJG.perDb.locker = 0; \ + SJG.perDb.locker = 0; \ sqlite3_mutex_leave( SJG.perDb.mutex ) #else /* SQLITE_THREADSAFE==0 */ @@ -1120,12 +1128,12 @@ static void s3jni__call_xDestroy(JNIEnv * const env, jobject jObj){ */ static void S3JniHook__localdup( JNIEnv * const env, S3JniHook const * const src, S3JniHook * const dest ){ - S3JniDb_mutex_enter; + S3JniGlobal_mutex_enter; *dest = *src; if(src->jObj) dest->jObj = S3JniRefLocal(src->jObj); if(src->jExtra) dest->jExtra = S3JniRefLocal(src->jExtra); dest->doXDestroy = 0; - S3JniDb_mutex_leave; + S3JniGlobal_mutex_leave; } #define S3JniHook_localdup(src,dest) S3JniHook__localdup(env,src,dest) @@ -1309,7 +1317,7 @@ static int S3JniEnv_uncache(JNIEnv * const env){ ** (2023-07-31) tests. */ static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ - S3JniNphClass * const pNC = &SJG.nph[pRef->index]; + S3JniNphClass * const pNC = &SJG.nph.list[pRef->index]; assert( (void*)pRef>=(void*)&S3JniNphRefs && (void*)pRef<(void*)(&S3JniNphRefs + 1) && "pRef is out of range" ); @@ -1341,7 +1349,7 @@ static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ ** that requirement). If necessary, this fetches the jfieldID for ** jOut's pRef->zMember, which must be of the type represented by the ** JNI type signature pRef->zTypeSig, and stores it in -** S3JniGlobal.nph[pRef->index]. Fails fatally if the pRef->zMember +** S3JniGlobal.nph.list[pRef->index]. Fails fatally if the pRef->zMember ** property is not found, as that presents a serious internal misuse. ** ** Property lookups are cached on a per-pRef basis. @@ -1661,8 +1669,9 @@ static void ResultJavaValue_finalizer(void *v){ ** Always use a static pointer from the S3JniNphRefs struct for the ** 2nd argument. */ -static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef const * pRef, - const void * pNative){ +static jobject NativePointerHolder_new(JNIEnv * const env, + S3JniNphRef const * pRef, + const void * pNative){ jobject rv = 0; S3JniNphClass * const pNC = s3jni_nph(pRef); if( !pNC->midCtor ){ @@ -1680,17 +1689,17 @@ static jobject new_NativePointerHolder_object(JNIEnv * const env, S3JniNphRef co return rv; } -static inline jobject new_sqlite3_wrapper(JNIEnv * const env, sqlite3 *sv){ - return new_NativePointerHolder_object(env, S3JniNph(sqlite3), sv); +static inline jobject new_java_sqlite3(JNIEnv * const env, sqlite3 *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3), sv); } -static inline jobject new_sqlite3_context_wrapper(JNIEnv * const env, sqlite3_context *sv){ - return new_NativePointerHolder_object(env, S3JniNph(sqlite3_context), sv); +static inline jobject new_java_sqlite3_context(JNIEnv * const env, sqlite3_context *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3_context), sv); } -static inline jobject new_sqlite3_stmt_wrapper(JNIEnv * const env, sqlite3_stmt *sv){ - return new_NativePointerHolder_object(env, S3JniNph(sqlite3_stmt), sv); +static inline jobject new_java_sqlite3_stmt(JNIEnv * const env, sqlite3_stmt *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3_stmt), sv); } -static inline jobject new_sqlite3_value_wrapper(JNIEnv * const env, sqlite3_value *sv){ - return new_NativePointerHolder_object(env, S3JniNph(sqlite3_value), sv); +static inline jobject new_java_sqlite3_value(JNIEnv * const env, sqlite3_value *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3_value), sv); } /* Helper typedefs for UDF callback types. */ @@ -1811,7 +1820,7 @@ static int udf_args(JNIEnv *env, int argc, sqlite3_value**argv, jobject * jCx, jobjectArray *jArgv){ jobjectArray ja = 0; - jobject jcx = new_sqlite3_context_wrapper(env, cx); + jobject jcx = new_java_sqlite3_context(env, cx); jint i; *jCx = 0; *jArgv = 0; @@ -1822,7 +1831,7 @@ static int udf_args(JNIEnv *env, s3jni_oom_check( ja ); if( !ja ) goto error_oom; for(i = 0; i < argc; ++i){ - jobject jsv = new_sqlite3_value_wrapper(env, argv[i]); + jobject jsv = new_java_sqlite3_value(env, argv[i]); if( !jsv ) goto error_oom; (*env)->SetObjectArrayElement(env, ja, i, jsv); S3JniUnrefLocal(jsv)/*ja has a ref*/; @@ -1909,7 +1918,7 @@ static int udf_xFV(sqlite3_context* cx, S3JniUdf * s, jmethodID xMethodID, const char *zFuncType){ S3JniDeclLocal_env; - jobject jcx = new_sqlite3_context_wrapper(env, cx); + jobject jcx = new_java_sqlite3_context(env, cx); int rc = 0; int const isFinal = 'F'==zFuncType[1]/*xFinal*/; @@ -2104,21 +2113,30 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, if( 0==SJG.autoExt.nExt ) return 0; env = s3jni_env(); jc = S3JniEnv_get(); - ps = jc->pdbOpening; + S3JniAutoExt_mutex_enter; + ps = jc->pdbOpening ? jc->pdbOpening : S3JniDb_from_c(pDb); if( !ps ){ *pzErr = sqlite3_mprintf("Unexpected arrival of null S3JniDb in " "auto-extension runner."); + S3JniAutoExt_mutex_leave; return SQLITE_ERROR; } - jc->pdbOpening = 0; - assert( !ps->pDb && "it's still being opened" ); assert( ps->jDb ); - rc = sqlite3_set_clientdata(pDb, S3JniDb_clientdata_key, - ps, 0/* we'll re-set this after open() - completes. */); - if( rc ){ - return rc; + if( !ps->pDb ){ + assert( jc->pdbOpening == ps ); + rc = sqlite3_set_clientdata(pDb, S3JniDb_clientdata_key, + ps, 0/* we'll re-set this after open() + completes. */); + if( rc ){ + S3JniAutoExt_mutex_leave; + return rc; + } } + else{ + assert( ps == jc->pdbOpening ); + jc->pdbOpening = 0; + } + S3JniAutoExt_mutex_leave; NativePointerHolder_set(S3JniNph(sqlite3), ps->jDb, pDb) /* As of here, the Java/C connection is complete except for the (temporary) lack of finalizer for the ps object. */; @@ -2534,7 +2552,8 @@ S3JniApi(sqlite3_collation_needed(),jint,1collation_1needed)( "Cannot not find matching call() in " "CollationNeededCallback object."); }else{ - rc = sqlite3_collation_needed16(ps->pDb, pHook, s3jni_collation_needed_impl16); + rc = sqlite3_collation_needed16(ps->pDb, pHook, + s3jni_collation_needed_impl16); if( 0==rc ){ S3JniHook_unref(pHook); pHook->midCallback = xCallback; @@ -2610,7 +2629,7 @@ S3JniApi(sqlite3_column_value(),jobject,1column_1value)( ){ sqlite3_value * const sv = sqlite3_column_value(PtrGet_sqlite3_stmt(jpStmt), (int)ndx); - return new_sqlite3_value_wrapper(env, sv); + return new_java_sqlite3_value(env, sv); } /* @@ -2896,7 +2915,7 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(), "Could not get call() method from " "CollationCallback object."); }else{ - char * const zName = s3jni_jstring_to_utf8( name, 0); + char * const zName = s3jni_jstring_to_utf8(name, 0); S3JniCollationCallback * const pCC = zName ? S3JniHook_alloc() : 0; if( pCC ){ @@ -3253,7 +3272,7 @@ static int s3jni_open_pre(JNIEnv * const env, S3JniEnv **jc, rc = SQLITE_NOMEM; goto end; } - jDb = new_sqlite3_wrapper(env, 0); + jDb = new_java_sqlite3(env, 0); if( !jDb ){ sqlite3_free(*zDbName); *zDbName = 0; @@ -3371,7 +3390,7 @@ jint sqlite3_jni_prepare_v123( int prepVersion, JNIEnv * const env, jclass self, rc = baSql ? SQLITE_NOMEM : SQLITE_MISUSE; goto end; } - jStmt = new_sqlite3_stmt_wrapper(env, 0); + jStmt = new_java_sqlite3_stmt(env, 0); if( !jStmt ){ rc = SQLITE_NOMEM; goto end; @@ -3616,7 +3635,7 @@ static int s3jni_preupdate_newold(JNIEnv * const env, int isNew, jobject jDb, isNew ? sqlite3_preupdate_new : sqlite3_preupdate_old; rc = fOrig(pDb, (int)iCol, &pOut); if( 0==rc ){ - jobject pWrap = new_sqlite3_value_wrapper(env, pOut); + jobject pWrap = new_java_sqlite3_value(env, pOut); if( pWrap ){ OutputPointer_set_sqlite3_value(env, jOut, pWrap); S3JniUnrefLocal(pWrap); @@ -4235,7 +4254,7 @@ static int s3jni_trace_impl(unsigned traceflag, void *pC, void *pP, void *pX){ if( 0==rc ){ if( !jP ){ /* Create a new temporary sqlite3_stmt wrapper */ - jP = jPUnref = new_sqlite3_stmt_wrapper(env, pP); + jP = jPUnref = new_java_sqlite3_stmt(env, pP); if( !jP ){ rc = SQLITE_NOMEM; } @@ -4347,7 +4366,7 @@ S3JniApi(sqlite3_value_dup(),jobject,1value_1dup)( JniArgsEnvClass, jobject jpSVal ){ sqlite3_value * const sv = sqlite3_value_dup(PtrGet_sqlite3_value(jpSVal)); - return sv ? new_sqlite3_value_wrapper(env, sv) : 0; + return sv ? new_java_sqlite3_value(env, sv) : 0; } S3JniApi(sqlite3_value_free(),void,1value_1free)( @@ -4444,7 +4463,7 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ "\n\tS3JniUdf = %u (free-list)" "\n\tmetrics = %u\n", SJG.metrics.nMutexGlobal, SJG.metrics.nMutexEnv, - SJG.metrics.nMutexEnv2, SJG.metrics.nMutexPerDb, + SJG.metrics.nMutexNph, SJG.metrics.nMutexPerDb, SJG.metrics.nMutexAutoExt, SJG.metrics.nMutexUdf, SJG.metrics.nMetrics); puts("Allocs:"); @@ -4501,7 +4520,8 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ #define PtrGet_fts5_tokenizer(OBJ) NativePointerHolder_get(OBJ,S3JniNph(fts5_tokenizer)) #define PtrGet_Fts5Context(OBJ) NativePointerHolder_get(OBJ,S3JniNph(Fts5Context)) #define PtrGet_Fts5Tokenizer(OBJ) NativePointerHolder_get(OBJ,S3JniNph(Fts5Tokenizer)) -#define Fts5ExtDecl Fts5ExtensionApi const * const fext = s3jni_ftsext() +#define s3jni_ftsext() &sFts5Api/*singleton from sqlite3.c*/ +#define Fts5ExtDecl Fts5ExtensionApi const * const ext = s3jni_ftsext() /** State for binding Java-side FTS5 auxiliary functions. @@ -4541,7 +4561,7 @@ static Fts5JniAux * Fts5JniAux_alloc(JNIEnv * const env, jobject jObj){ memset(s, 0, sizeof(Fts5JniAux)); s->jObj = S3JniRefGlobal(jObj); klazz = (*env)->GetObjectClass(env, jObj); - s->jmid = (*env)->GetMethodID(env, klazz, "xFunction", + s->jmid = (*env)->GetMethodID(env, klazz, "call", "(Lorg/sqlite/jni/Fts5ExtensionApi;" "Lorg/sqlite/jni/Fts5Context;" "Lorg/sqlite/jni/sqlite3_context;" @@ -4557,15 +4577,11 @@ static Fts5JniAux * Fts5JniAux_alloc(JNIEnv * const env, jobject jObj){ return s; } -static inline Fts5ExtensionApi const * s3jni_ftsext(void){ - return &sFts5Api/*singleton from sqlite3.c*/; +static inline jobject new_java_Fts5Context(JNIEnv * const env, Fts5Context *sv){ + return NativePointerHolder_new(env, S3JniNph(Fts5Context), sv); } - -static inline jobject new_Fts5Context_wrapper(JNIEnv * const env, Fts5Context *sv){ - return new_NativePointerHolder_object(env, S3JniNph(Fts5Context), sv); -} -static inline jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){ - return new_NativePointerHolder_object(env, S3JniNph(fts5_api), sv); +static inline jobject new_java_fts5_api(JNIEnv * const env, fts5_api *sv){ + return NativePointerHolder_new(env, S3JniNph(fts5_api), sv); } /* @@ -4573,20 +4589,20 @@ static inline jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){ ** instance, or NULL on OOM. */ static jobject s3jni_getFts5ExensionApi(JNIEnv * const env){ - if( !SJG.fts5.jFtsExt ){ - jobject pNPH = new_NativePointerHolder_object( - env, S3JniNph(Fts5ExtensionApi), s3jni_ftsext() - ); - S3JniEnv_mutex_enter; - if( pNPH ){ - if( !SJG.fts5.jFtsExt ){ - SJG.fts5.jFtsExt = S3JniRefGlobal(pNPH); + if( !SJG.fts5.jExt ){ + S3JniGlobal_mutex_enter; + if( !SJG.fts5.jExt ){ + jobject const pNPH = NativePointerHolder_new( + env, S3JniNph(Fts5ExtensionApi), s3jni_ftsext() + ); + if( pNPH ){ + SJG.fts5.jExt = S3JniRefGlobal(pNPH); + S3JniUnrefLocal(pNPH); } - S3JniUnrefLocal(pNPH); } - S3JniEnv_mutex_leave; + S3JniGlobal_mutex_leave; } - return SJG.fts5.jFtsExt; + return SJG.fts5.jExt; } /* @@ -4607,18 +4623,33 @@ static fts5_api *s3jni_fts5_api_from_db(sqlite3 *db){ JniDeclFtsApi(jobject,getInstanceForDb)(JniArgsEnvClass,jobject jDb){ S3JniDb * const ps = S3JniDb_from_java(jDb); +#if 0 jobject rv = 0; if( !ps ) return 0; - else if( ps->jFtsApi ){ - rv = ps->jFtsApi; + else if( ps->fts.jApi ){ + rv = ps->fts.jApi; }else{ fts5_api * const pApi = s3jni_fts5_api_from_db(ps->pDb); if( pApi ){ - rv = new_fts5_api_wrapper(env, pApi); - ps->jFtsApi = rv ? S3JniRefGlobal(rv) : 0; + rv = new_java_fts5_api(env, pApi); + ps->fts.jApi = rv ? S3JniRefGlobal(rv) : 0; } } return rv; +#else + if( ps && !ps->fts.jApi ){ + S3JniDb_mutex_enter; + if( !ps->fts.jApi ){ + fts5_api * const pApi = s3jni_fts5_api_from_db(ps->pDb); + if( pApi ){ + jobject const rv = new_java_fts5_api(env, pApi); + ps->fts.jApi = rv ? S3JniRefGlobal(rv) : 0; + } + } + S3JniDb_mutex_leave; + } + return ps ? ps->fts.jApi : 0; +#endif } @@ -4628,13 +4659,13 @@ JniDeclFtsXA(jobject,getInstance)(JniArgsEnvClass){ JniDeclFtsXA(jint,xColumnCount)(JniArgsEnvObj,jobject jCtx){ Fts5ExtDecl; - return (jint)fext->xColumnCount(PtrGet_Fts5Context(jCtx)); + return (jint)ext->xColumnCount(PtrGet_Fts5Context(jCtx)); } JniDeclFtsXA(jint,xColumnSize)(JniArgsEnvObj,jobject jCtx, jint iIdx, jobject jOut32){ Fts5ExtDecl; int n1 = 0; - int const rc = fext->xColumnSize(PtrGet_Fts5Context(jCtx), (int)iIdx, &n1); + int const rc = ext->xColumnSize(PtrGet_Fts5Context(jCtx), (int)iIdx, &n1); if( 0==rc ) OutputPointer_set_Int32(env, jOut32, n1); return rc; } @@ -4644,7 +4675,7 @@ JniDeclFtsXA(jint,xColumnText)(JniArgsEnvObj,jobject jCtx, jint iCol, Fts5ExtDecl; const char *pz = 0; int pn = 0; - int rc = fext->xColumnText(PtrGet_Fts5Context(jCtx), (int)iCol, + int rc = ext->xColumnText(PtrGet_Fts5Context(jCtx), (int)iCol, &pz, &pn); if( 0==rc ){ jstring jstr = pz ? s3jni_utf8_to_jstring( pz, pn) : 0; @@ -4663,7 +4694,7 @@ JniDeclFtsXA(jint,xColumnText)(JniArgsEnvObj,jobject jCtx, jint iCol, JniDeclFtsXA(jint,xColumnTotalSize)(JniArgsEnvObj,jobject jCtx, jint iCol, jobject jOut64){ Fts5ExtDecl; sqlite3_int64 nOut = 0; - int const rc = fext->xColumnTotalSize(PtrGet_Fts5Context(jCtx), (int)iCol, &nOut); + int const rc = ext->xColumnTotalSize(PtrGet_Fts5Context(jCtx), (int)iCol, &nOut); if( 0==rc && jOut64 ) OutputPointer_set_Int64(env, jOut64, (jlong)nOut); return (jint)rc; } @@ -4688,20 +4719,21 @@ static void s3jni_fts5_extension_function(Fts5ExtensionApi const *pApi, assert(pAux); jFXA = s3jni_getFts5ExensionApi(env); if( !jFXA ) goto error_oom; - jpFts = new_Fts5Context_wrapper(env, pFts); + jpFts = new_java_Fts5Context(env, pFts); if( !jpFts ) goto error_oom; rc = udf_args(env, pCx, argc, argv, &jpCx, &jArgv); if( rc ) goto error_oom; (*env)->CallVoidMethod(env, pAux->jObj, pAux->jmid, jFXA, jpFts, jpCx, jArgv); S3JniIfThrew{ - udf_report_exception(env, 1, pCx, pAux->zFuncName, "xFunction"); + udf_report_exception(env, 1, pCx, pAux->zFuncName, "call"); } S3JniUnrefLocal(jpFts); S3JniUnrefLocal(jpCx); S3JniUnrefLocal(jArgv); return; error_oom: + s3jni_db_oom( sqlite3_context_db_handle(pCx) ); assert( !jArgv ); assert( !jpCx ); S3JniUnrefLocal(jpFts); @@ -4761,7 +4793,7 @@ static void S3JniFts5AuxData_xDestroy(void *x){ JniDeclFtsXA(jobject,xGetAuxdata)(JniArgsEnvObj,jobject jCtx, jboolean bClear){ Fts5ExtDecl; jobject rv = 0; - S3JniFts5AuxData * const pAux = fext->xGetAuxdata(PtrGet_Fts5Context(jCtx), bClear); + S3JniFts5AuxData * const pAux = ext->xGetAuxdata(PtrGet_Fts5Context(jCtx), bClear); if( pAux ){ if( bClear ){ if( pAux->jObj ){ @@ -4781,7 +4813,7 @@ JniDeclFtsXA(jint,xInst)(JniArgsEnvObj,jobject jCtx, jint iIdx, jobject jOutPhra jobject jOutCol, jobject jOutOff){ Fts5ExtDecl; int n1 = 0, n2 = 2, n3 = 0; - int const rc = fext->xInst(PtrGet_Fts5Context(jCtx), (int)iIdx, &n1, &n2, &n3); + int const rc = ext->xInst(PtrGet_Fts5Context(jCtx), (int)iIdx, &n1, &n2, &n3); if( 0==rc ){ OutputPointer_set_Int32(env, jOutPhrase, n1); OutputPointer_set_Int32(env, jOutCol, n2); @@ -4793,14 +4825,14 @@ JniDeclFtsXA(jint,xInst)(JniArgsEnvObj,jobject jCtx, jint iIdx, jobject jOutPhra JniDeclFtsXA(jint,xInstCount)(JniArgsEnvObj,jobject jCtx, jobject jOut32){ Fts5ExtDecl; int nOut = 0; - int const rc = fext->xInstCount(PtrGet_Fts5Context(jCtx), &nOut); + int const rc = ext->xInstCount(PtrGet_Fts5Context(jCtx), &nOut); if( 0==rc && jOut32 ) OutputPointer_set_Int32(env, jOut32, nOut); return (jint)rc; } JniDeclFtsXA(jint,xPhraseCount)(JniArgsEnvObj,jobject jCtx){ Fts5ExtDecl; - return (jint)fext->xPhraseCount(PtrGet_Fts5Context(jCtx)); + return (jint)ext->xPhraseCount(PtrGet_Fts5Context(jCtx)); } /* Copy the 'a' and 'b' fields from pSrc to Fts5PhraseIter object jIter. */ @@ -4834,7 +4866,7 @@ JniDeclFtsXA(jint,xPhraseFirst)(JniArgsEnvObj,jobject jCtx, jint iPhrase, Fts5ExtDecl; Fts5PhraseIter iter; int rc, iCol = 0, iOff = 0; - rc = fext->xPhraseFirst(PtrGet_Fts5Context(jCtx), (int)iPhrase, + rc = ext->xPhraseFirst(PtrGet_Fts5Context(jCtx), (int)iPhrase, &iter, &iCol, &iOff); if( 0==rc ){ OutputPointer_set_Int32(env, jOutCol, iCol); @@ -4849,7 +4881,7 @@ JniDeclFtsXA(jint,xPhraseFirstColumn)(JniArgsEnvObj,jobject jCtx, jint iPhrase, Fts5ExtDecl; Fts5PhraseIter iter; int rc, iCol = 0; - rc = fext->xPhraseFirstColumn(PtrGet_Fts5Context(jCtx), (int)iPhrase, + rc = ext->xPhraseFirstColumn(PtrGet_Fts5Context(jCtx), (int)iPhrase, &iter, &iCol); if( 0==rc ){ OutputPointer_set_Int32(env, jOutCol, iCol); @@ -4864,7 +4896,7 @@ JniDeclFtsXA(void,xPhraseNext)(JniArgsEnvObj,jobject jCtx, jobject jIter, Fts5PhraseIter iter; int iCol = 0, iOff = 0; s3jni_phraseIter_JToN(env, jIter, &iter); - fext->xPhraseNext(PtrGet_Fts5Context(jCtx), &iter, &iCol, &iOff); + ext->xPhraseNext(PtrGet_Fts5Context(jCtx), &iter, &iCol, &iOff); OutputPointer_set_Int32(env, jOutCol, iCol); OutputPointer_set_Int32(env, jOutOff, iOff); s3jni_phraseIter_NToJ(env, &iter, jIter); @@ -4876,7 +4908,7 @@ JniDeclFtsXA(void,xPhraseNextColumn)(JniArgsEnvObj,jobject jCtx, jobject jIter, Fts5PhraseIter iter; int iCol = 0; s3jni_phraseIter_JToN(env, jIter, &iter); - fext->xPhraseNextColumn(PtrGet_Fts5Context(jCtx), &iter, &iCol); + ext->xPhraseNextColumn(PtrGet_Fts5Context(jCtx), &iter, &iCol); OutputPointer_set_Int32(env, jOutCol, iCol); s3jni_phraseIter_NToJ(env, &iter, jIter); } @@ -4884,12 +4916,12 @@ JniDeclFtsXA(void,xPhraseNextColumn)(JniArgsEnvObj,jobject jCtx, jobject jIter, JniDeclFtsXA(jint,xPhraseSize)(JniArgsEnvObj,jobject jCtx, jint iPhrase){ Fts5ExtDecl; - return (jint)fext->xPhraseSize(PtrGet_Fts5Context(jCtx), (int)iPhrase); + return (jint)ext->xPhraseSize(PtrGet_Fts5Context(jCtx), (int)iPhrase); } /* State for use with xQueryPhrase() and xTokenize(). */ struct s3jni_xQueryPhraseState { - Fts5ExtensionApi const * fext; + Fts5ExtensionApi const * ext; S3JniEnv const * jc; jmethodID midCallback; jobject jCallback; @@ -4910,7 +4942,7 @@ static int s3jni_xQueryPhrase(const Fts5ExtensionApi *xapi, struct s3jni_xQueryPhraseState const * s = pData; S3JniDeclLocal_env; int rc = (int)(*env)->CallIntMethod(env, s->jCallback, s->midCallback, - SJG.fts5.jFtsExt, s->jFcx); + SJG.fts5.jExt, s->jFcx); S3JniIfThrew{ S3JniExceptionWarnCallbackThrew("xQueryPhrase() callback"); S3JniExceptionClear; @@ -4930,13 +4962,13 @@ JniDeclFtsXA(jint,xQueryPhrase)(JniArgsEnvObj,jobject jFcx, jint iPhrase, s.jc = jc; s.jCallback = jCallback; s.jFcx = jFcx; - s.fext = fext; - s.midCallback = (*env)->GetMethodID(env, klazz, "xCallback", + s.ext = ext; + s.midCallback = (*env)->GetMethodID(env, klazz, "call", "(Lorg.sqlite.jni.Fts5ExtensionApi;" "Lorg.sqlite.jni.Fts5Context;)I"); S3JniUnrefLocal(klazz); - S3JniExceptionIsFatal("Could not extract xQueryPhraseCallback.xCallback method."); - return (jint)fext->xQueryPhrase(PtrGet_Fts5Context(jFcx), iPhrase, &s, + S3JniExceptionIsFatal("Could not extract xQueryPhraseCallback.call() method."); + return (jint)ext->xQueryPhrase(PtrGet_Fts5Context(jFcx), iPhrase, &s, s3jni_xQueryPhrase); } @@ -4944,14 +4976,14 @@ JniDeclFtsXA(jint,xQueryPhrase)(JniArgsEnvObj,jobject jFcx, jint iPhrase, JniDeclFtsXA(jint,xRowCount)(JniArgsEnvObj,jobject jCtx, jobject jOut64){ Fts5ExtDecl; sqlite3_int64 nOut = 0; - int const rc = fext->xRowCount(PtrGet_Fts5Context(jCtx), &nOut); + int const rc = ext->xRowCount(PtrGet_Fts5Context(jCtx), &nOut); if( 0==rc && jOut64 ) OutputPointer_set_Int64(env, jOut64, (jlong)nOut); return (jint)rc; } JniDeclFtsXA(jlong,xRowid)(JniArgsEnvObj,jobject jCtx){ Fts5ExtDecl; - return (jlong)fext->xRowid(PtrGet_Fts5Context(jCtx)); + return (jlong)ext->xRowid(PtrGet_Fts5Context(jCtx)); } JniDeclFtsXA(int,xSetAuxdata)(JniArgsEnvObj,jobject jCtx, jobject jAux){ @@ -4969,7 +5001,7 @@ JniDeclFtsXA(int,xSetAuxdata)(JniArgsEnvObj,jobject jCtx, jobject jAux){ return SQLITE_NOMEM; } pAux->jObj = S3JniRefGlobal(jAux); - rc = fext->xSetAuxdata(PtrGet_Fts5Context(jCtx), pAux, + rc = ext->xSetAuxdata(PtrGet_Fts5Context(jCtx), pAux, S3JniFts5AuxData_xDestroy); return rc; } @@ -5018,7 +5050,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphRef const *pRef, s.jc = jc; s.jCallback = jCallback; s.jFcx = jFcx; - s.fext = fext; + s.ext = ext; s.midCallback = (*env)->GetMethodID(env, klazz, "call", "(I[BII)I"); S3JniUnrefLocal(klazz); S3JniIfThrew { @@ -5031,7 +5063,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphRef const *pRef, s.tok.zPrev = (const char *)pText; s.tok.nPrev = (int)nText; if( pRef == S3JniNph(Fts5ExtensionApi) ){ - rc = fext->xTokenize(PtrGet_Fts5Context(jFcx), + rc = ext->xTokenize(PtrGet_Fts5Context(jFcx), (const char *)pText, (int)nText, &s, s3jni_xTokenize_xToken); }else if( pRef == S3JniNph(fts5_tokenizer) ){ @@ -5065,7 +5097,7 @@ JniDeclFtsTok(jint,xTokenize)(JniArgsEnvObj,jobject jFcx, jint tokFlags, JniDeclFtsXA(jobject,xUserData)(JniArgsEnvObj,jobject jFcx){ Fts5ExtDecl; - Fts5JniAux * const pAux = fext->xUserData(PtrGet_Fts5Context(jFcx)); + Fts5JniAux * const pAux = ext->xUserData(PtrGet_Fts5Context(jFcx)); return pAux ? pAux->jUserData : 0; } @@ -5337,6 +5369,8 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ SJG.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); s3jni_oom_fatal( SJG.mutex ); + SJG.nph.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); + s3jni_oom_fatal( SJG.nph.mutex ); SJG.envCache.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); s3jni_oom_fatal( SJG.envCache.mutex ); SJG.perDb.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); diff --git a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java index ab2995f378..a575ebdb91 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java +++ b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java @@ -28,7 +28,7 @@ public final class Fts5ExtensionApi extends NativePointerHolder val = new ValueHolder<>(0); final ValueHolder toss = new ValueHolder<>(null); final AutoExtensionCallback ax = new AutoExtensionCallback(){ - @Override public synchronized int call(sqlite3 db){ + @Override public int call(sqlite3 db){ ++val.value; if( null!=toss.value ){ throw new RuntimeException(toss.value); @@ -1650,7 +1650,7 @@ public class Tester1 implements Runnable { { // Build list of tests to run from the methods named test*(). testMethods = new ArrayList<>(); - out("Skipping tests in multi-thread mode:"); + int nSkipped = 0; for(final java.lang.reflect.Method m : Tester1.class.getDeclaredMethods()){ final String name = m.getName(); if( name.equals("testFail") ){ @@ -1659,13 +1659,16 @@ public class Tester1 implements Runnable { } }else if( !m.isAnnotationPresent( ManualTest.class ) ){ if( nThread>1 && m.isAnnotationPresent( SingleThreadOnly.class ) ){ + if( 0==nSkipped++ ){ + out("Skipping tests in multi-thread mode:"); + } out(" "+name+"()"); }else if( name.startsWith("test") ){ testMethods.add(m); } } } - out("\n"); + if( nSkipped>0 ) out("\n"); } final long timeStart = System.currentTimeMillis(); diff --git a/ext/jni/src/org/sqlite/jni/TesterFts5.java b/ext/jni/src/org/sqlite/jni/TesterFts5.java index 70c8e255d2..5f0be352a5 100644 --- a/ext/jni/src/org/sqlite/jni/TesterFts5.java +++ b/ext/jni/src/org/sqlite/jni/TesterFts5.java @@ -18,7 +18,7 @@ import static org.sqlite.jni.Tester1.*; public class TesterFts5 { private static void test1(){ - Fts5ExtensionApi fea = Fts5ExtensionApi.getInstance(); + final Fts5ExtensionApi fea = Fts5ExtensionApi.getInstance(); affirm( null != fea ); affirm( fea.getNativePointer() != 0 ); affirm( fea == Fts5ExtensionApi.getInstance() )/*singleton*/; @@ -38,21 +38,18 @@ public class TesterFts5 { ValueHolder xDestroyCalled = new ValueHolder<>(false); ValueHolder xFuncCount = new ValueHolder<>(0); final fts5_extension_function func = new fts5_extension_function(){ - public void xFunction(Fts5ExtensionApi ext, Fts5Context fCx, - sqlite3_context pCx, sqlite3_value argv[]){ + @Override public void call(Fts5ExtensionApi ext, Fts5Context fCx, + sqlite3_context pCx, sqlite3_value argv[]){ int nCols = ext.xColumnCount(fCx); affirm( 2 == nCols ); affirm( nCols == argv.length ); affirm( ext.xUserData(fCx) == pUserData ); - if(true){ - OutputPointer.String op = new OutputPointer.String(); - for(int i = 0; i < nCols; ++i ){ - int rc = ext.xColumnText(fCx, i, op); - affirm( 0 == rc ); - final String val = op.value; - affirm( val.equals(sqlite3_value_text16(argv[i])) ); - //outln("xFunction col "+i+": "+val); - } + final OutputPointer.String op = new OutputPointer.String(); + for(int i = 0; i < nCols; ++i ){ + int rc = ext.xColumnText(fCx, i, op); + affirm( 0 == rc ); + final String val = op.value; + affirm( val.equals(sqlite3_value_text16(argv[i])) ); } ++xFuncCount.value; } @@ -72,18 +69,24 @@ public class TesterFts5 { affirm( xDestroyCalled.value ); } + private void runTests(){ + test1(); + } + public TesterFts5(boolean verbose){ if(verbose){ - final long timeStart = System.currentTimeMillis(); - final int oldAffirmCount = Tester1.affirmCount; - test1(); - final int affirmCount = Tester1.affirmCount - oldAffirmCount; - final long timeEnd = System.currentTimeMillis(); - outln("FTS5 Tests done. Assertions checked = ",affirmCount, - ", Total time = ",(timeEnd - timeStart),"ms"); + synchronized(Tester1.class) { + final long timeStart = System.currentTimeMillis(); + final int oldAffirmCount = Tester1.affirmCount; + runTests(); + final int affirmCount = Tester1.affirmCount - oldAffirmCount; + final long timeEnd = System.currentTimeMillis(); + outln("FTS5 Tests done. Assertions checked = ",affirmCount, + ", Total time = ",(timeEnd - timeStart),"ms"); + } }else{ - test1(); + runTests(); } } - public TesterFts5(){ this(false); } + public TesterFts5(){ this(true); } } diff --git a/ext/jni/src/org/sqlite/jni/fts5_api.java b/ext/jni/src/org/sqlite/jni/fts5_api.java index 92ca7c669a..a0376dfc8f 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_api.java +++ b/ext/jni/src/org/sqlite/jni/fts5_api.java @@ -33,6 +33,31 @@ public final class fts5_api extends NativePointerHolder { */ public static synchronized native fts5_api getInstanceForDb(@NotNull sqlite3 db); + @Canonical + public synchronized native int xCreateFunction(@NotNull String name, + @Nullable Object userData, + @NotNull fts5_extension_function xFunction); + + /** + Convenience overload which passes null as the 2nd argument to the + 3-parameter form. + */ + public int xCreateFunction(@NotNull String name, + @NotNull fts5_extension_function xFunction){ + return xCreateFunction(name, null, xFunction); + } + + // /* Create a new auxiliary function */ + // int (*xCreateFunction)( + // fts5_api *pApi, + // const char *zName, + // void *pContext, + // fts5_extension_function xFunction, + // void (*xDestroy)(void*) + // ); + + // Still potentially todo: + // int (*xCreateTokenizer)( // fts5_api *pApi, // const char *zName, @@ -49,22 +74,4 @@ public final class fts5_api extends NativePointerHolder { // fts5_tokenizer *pTokenizer // ); - // /* Create a new auxiliary function */ - // int (*xCreateFunction)( - // fts5_api *pApi, - // const char *zName, - // void *pContext, - // fts5_extension_function xFunction, - // void (*xDestroy)(void*) - // ); - - public synchronized native int xCreateFunction(@NotNull String name, - @Nullable Object userData, - @NotNull fts5_extension_function xFunction); - - public int xCreateFunction(@NotNull String name, - @NotNull fts5_extension_function xFunction){ - return xCreateFunction(name, null, xFunction); - } - } diff --git a/ext/jni/src/org/sqlite/jni/fts5_extension_function.java b/ext/jni/src/org/sqlite/jni/fts5_extension_function.java index 0e273119f5..9247003168 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_extension_function.java +++ b/ext/jni/src/org/sqlite/jni/fts5_extension_function.java @@ -15,9 +15,8 @@ package org.sqlite.jni; /** JNI-level wrapper for C's fts5_extension_function type. - */ -public abstract class fts5_extension_function { +public interface fts5_extension_function { // typedef void (*fts5_extension_function)( // const Fts5ExtensionApi *pApi, /* API offered by current FTS version */ // Fts5Context *pFts, /* First arg to pass to pApi functions */ @@ -30,8 +29,17 @@ public abstract class fts5_extension_function { The callback implementation, corresponding to the xFunction argument of C's fts5_api::xCreateFunction(). */ - public abstract void xFunction(Fts5ExtensionApi ext, Fts5Context fCx, - sqlite3_context pCx, sqlite3_value argv[]); - //! Optionally override - public void xDestroy(){} + void call(Fts5ExtensionApi ext, Fts5Context fCx, + sqlite3_context pCx, sqlite3_value argv[]); + /** + Is called when this function is destroyed by sqlite3. Typically + this function will be empty. + */ + void xDestroy(); + + public static abstract class Abstract implements fts5_extension_function { + @Override public abstract void call(Fts5ExtensionApi ext, Fts5Context fCx, + sqlite3_context pCx, sqlite3_value argv[]); + @Override public void xDestroy(){} + } } diff --git a/manifest b/manifest index 8128a83550..4f091a5f46 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stimer\sto\sthe\sJS\sSQLTester\sapp\sto\swarn\sif\sit\sappears\sthat\sloading\sthe\smodule\shas\sfailed,\swhich\sis\scommonly\scaused\sby\sthe\stest\sscripts\snot\sbeing\scompiled. -D 2023-09-01T17:51:09.091 +C Further\sJNI\scleanups. +D 2023-09-02T08:51:14.022 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,10 +234,10 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 3e0e28c1c451eab31dd4fa9d262951ef67ed3ece3270a2efc8ec66ec57068547 +F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 00469db3f64a7f53bc1ecb60749260b937f8892ddc56d4c61d5f427f6e6758a7 +F ext/jni/src/c/sqlite3-jni.c d98030bb7f502b42990eeb0f2bd103af0b1f1312ba82892949c5ced85262e036 F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -251,8 +251,7 @@ F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 F ext/jni/src/org/sqlite/jni/Fts5.java 3ebfbd5b95fdb9d7bc40306f2e682abd12e247d9224e92510b8dd103b4f96fe8 F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 -F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 2fd11abb7c5403318181d69bb7b702a79cba7ab460105140f5161bea9bc505d1 -F ext/jni/src/org/sqlite/jni/Fts5Function.java 65cde7151e441fee012250a5e03277de7babcd11a0c308a832b7940574259bcc +F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 6ac342951c5805b48ba1e46dd41dff3b74c609dc5bf1c26fca5738db36493031 F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d @@ -265,8 +264,8 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 2a6ef03fca523280731a88f697cdc8ece9548cd4cbe7e1cc90823e5bb5998e27 -F ext/jni/src/org/sqlite/jni/TesterFts5.java 02b59ea7d75666fd565d90bb8dc7b0c09441bb9d1af091fad9f6d7377297a474 +F ext/jni/src/org/sqlite/jni/Tester1.java 93e89c4f72065bf28625cf435c47ed2bd3d937fe5c2431e6e7c3407f09f3f9bc +F ext/jni/src/org/sqlite/jni/TesterFts5.java 2b2d6f3cc9f508358c103b774aee296c0f3d8c2f387d6abae9b8b9055f62c800 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee @@ -276,8 +275,8 @@ F ext/jni/src/org/sqlite/jni/annotation/Canonical.java d9ff79f1bf9d063d0c3e3b768 F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 -F ext/jni/src/org/sqlite/jni/fts5_api.java ee47f1837d32968f7bb62278c7504c0fb572a68ec107371b714578312e9f734b -F ext/jni/src/org/sqlite/jni/fts5_extension_function.java ac825035d7d83fc7fd960347abfa6803e1614334a21533302041823ad5fc894c +F ext/jni/src/org/sqlite/jni/fts5_api.java bf7009a7fd2d11a77280380e6e2c7f98e377494b3f265e50fc44cbb9a24275d9 +F ext/jni/src/org/sqlite/jni/fts5_extension_function.java bec9f17a7e784d57eca99d812a65ecc9dd74c8df62d6d90cc1ecb3e37de14d47 F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc @@ -2116,8 +2115,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 016bbdadbf9f95cef185d2606c23e3b3c724586fcca470e11e6fbdbaefd75c79 -R 4133358901b76bfadefddc6665a81e23 +P f9c1f9cad1ad22f689a4afa13d59bf9969ddaed6624cbc16cb1bf5d1fd0c8a5b +R 215167a378a1f1105562740ffd0f1842 U stephan -Z eab9aeb866f5eecf9b7d34e391979f20 +Z 15dc34b47fe3ed21ed7cc58408f87312 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dcede0167e..bbd378b4fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9c1f9cad1ad22f689a4afa13d59bf9969ddaed6624cbc16cb1bf5d1fd0c8a5b \ No newline at end of file +30e38173c3ece0c9f8e7a9710f46cb5e8e8ef101c04531318a7adb070242f5dd \ No newline at end of file From 70b58fc1199e66c401f5ab10791cf679235329cf Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 10:18:10 +0000 Subject: [PATCH 14/36] Remove a superfluous level of indirection in the JNI internals. FossilOrigin-Name: 8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726 --- ext/jni/src/c/sqlite3-jni.c | 188 ++++++++++++------------ ext/jni/src/org/sqlite/jni/Tester1.java | 15 +- manifest | 14 +- manifest.uuid | 2 +- 4 files changed, 104 insertions(+), 115 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index d54cc1ca9c..a9e1552cf8 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -294,43 +294,66 @@ static inline void s3jni_unref_local(JNIEnv * const env, jobject const v){ #define S3JniUnrefLocal(VAR) s3jni_unref_local(env, (VAR)) /* -** Lookup key type for use with s3jni_nph(). +** Lookup key type for use with s3jni_nphop() and a cache of a +** frequently-needed Java-side class reference and one or two Java +** class member IDs. */ -typedef struct S3JniNphRef S3JniNphRef; -struct S3JniNphRef { +typedef struct S3JniNphOp S3JniNphOp; +struct S3JniNphOp { const int index /* index into S3JniGlobal.nph[] */; const char * const zName /* Full Java name of the class */; const char * const zMember /* Name of member property */; const char * const zTypeSig /* JNI type signature of zMember */; + /* + ** klazz is a global ref to the class represented by pRef. + ** + ** According to: + ** + ** https://developer.ibm.com/articles/j-jni/ + ** + ** > ... the IDs returned for a given class don't change for the + ** lifetime of the JVM process. But the call to get the field or + ** method can require significant work in the JVM, because fields + ** and methods might have been inherited from superclasses, making + ** the JVM walk up the class hierarchy to find them. Because the + ** IDs are the same for a given class, you should look them up + ** once and then reuse them. Similarly, looking up class objects + ** can be expensive, so they should be cached as well. + */ + jclass klazz; + volatile jfieldID fidValue /* NativePointerHolder.nativePointer or + ** OutputPointer.T.value */; + volatile jmethodID midCtor /* klazz's no-arg constructor. Used by + ** NativePointerHolder_new(). */; }; /* ** Cache keys for each concrete NativePointerHolder subclasses and -** OutputPointer.T types. The members are to be used with s3jni_nph() +** OutputPointer.T types. The members are to be used with s3jni_nphop() ** and friends, and each one's member->index corresponds to its index ** in the S3JniGlobal.nph[] array. */ static const struct { - const S3JniNphRef sqlite3; - const S3JniNphRef sqlite3_stmt; - const S3JniNphRef sqlite3_context; - const S3JniNphRef sqlite3_value; - const S3JniNphRef OutputPointer_Bool; - const S3JniNphRef OutputPointer_Int32; - const S3JniNphRef OutputPointer_Int64; - const S3JniNphRef OutputPointer_sqlite3; - const S3JniNphRef OutputPointer_sqlite3_stmt; - const S3JniNphRef OutputPointer_sqlite3_value; - const S3JniNphRef OutputPointer_String; + const S3JniNphOp sqlite3; + const S3JniNphOp sqlite3_stmt; + const S3JniNphOp sqlite3_context; + const S3JniNphOp sqlite3_value; + const S3JniNphOp OutputPointer_Bool; + const S3JniNphOp OutputPointer_Int32; + const S3JniNphOp OutputPointer_Int64; + const S3JniNphOp OutputPointer_sqlite3; + const S3JniNphOp OutputPointer_sqlite3_stmt; + const S3JniNphOp OutputPointer_sqlite3_value; + const S3JniNphOp OutputPointer_String; #ifdef SQLITE_ENABLE_FTS5 - const S3JniNphRef OutputPointer_ByteArray; - const S3JniNphRef Fts5Context; - const S3JniNphRef Fts5ExtensionApi; - const S3JniNphRef fts5_api; - const S3JniNphRef fts5_tokenizer; - const S3JniNphRef Fts5Tokenizer; + const S3JniNphOp OutputPointer_ByteArray; + const S3JniNphOp Fts5Context; + const S3JniNphOp Fts5ExtensionApi; + const S3JniNphOp fts5_api; + const S3JniNphOp fts5_tokenizer; + const S3JniNphOp Fts5Tokenizer; #endif -} S3JniNphRefs = { +} S3JniNphOps = { #define MkRef(INDEX, KLAZZ, MEMBER, SIG) \ { INDEX, "org/sqlite/jni/" KLAZZ, MEMBER, SIG } /* NativePointerHolder ref */ @@ -364,51 +387,17 @@ static const struct { #undef RefO }; -#define S3JniNph(T) &S3JniNphRefs.T +#define S3JniNph(T) &S3JniNphOps.T enum { /* ** Size of the NativePointerHolder cache. Need enough space for ** (only) the library's NativePointerHolder and OutputPointer types, ** a fixed count known at build-time. This value needs to be - ** exactly the number of S3JniNphRef entries in the S3JniNphRefs + ** exactly the number of S3JniNphOp entries in the S3JniNphOps ** object. */ - S3Jni_NphCache_size = sizeof(S3JniNphRefs) / sizeof(S3JniNphRef) -}; - -/* -** Cache entry for NativePointerHolder subclasses and OutputPointer -** types. The pRef and klazz fields are set up the first time the -** entry is fetched using s3jni_nph(). The other fields are -** populated as needed by the routines which use them. -*/ -typedef struct S3JniNphClass S3JniNphClass; -struct S3JniNphClass { - volatile const S3JniNphRef * pRef /* Entry from S3JniNphRefs */; - /* - ** klazz is a global ref to the class represented by pRef. - ** - ** According to: - ** - ** https://developer.ibm.com/articles/j-jni/ - ** - ** > ... the IDs returned for a given class don't change for the - ** lifetime of the JVM process. But the call to get the field or - ** method can require significant work in the JVM, because fields - ** and methods might have been inherited from superclasses, making - ** the JVM walk up the class hierarchy to find them. Because the - ** IDs are the same for a given class, you should look them up - ** once and then reuse them. Similarly, looking up class objects - ** can be expensive, so they should be cached as well. - */ - jclass klazz; - volatile jmethodID midCtor /* klazz's no-arg constructor. Used by - ** NativePointerHolder_new(). */; - volatile jfieldID fidValue /* NativePointerHolder.nativePointer or - ** OutputPointer.T.value */; - volatile jfieldID fidAggCtx /* sqlite3_context.aggregateContext, used only - ** by the sqlite3_context binding. */; + S3Jni_NphCache_size = sizeof(S3JniNphOps) / sizeof(S3JniNphOp) }; /* @@ -420,7 +409,9 @@ struct S3JniHook{ jmethodID midCallback /* callback method. Signature depends on ** jObj's type */; /* We lookup the jObj.xDestroy() method as-needed for contexts which - ** have custom finalizers. */ + ** support custom finalizers. Fundamentally we can support them for + ** any Java type, but we only want to expose support for them where + ** the C API does. */ jobject jExtra /* Global ref to a per-hook-type value */; int doXDestroy /* If true then S3JniHook_unref() will call jObj->xDestroy() if it's available. */; @@ -590,10 +581,10 @@ struct S3JniGlobalType { ** NativePointerHolder subclasses and OutputPointer.T types. */ struct { - S3JniNphClass list[S3Jni_NphCache_size]; + S3JniNphOp list[S3Jni_NphCache_size]; sqlite3_mutex * mutex; /* mutex for this->list */ - void const * locker; /* sanity-checking-only context object - for this->mutex */ + volatile void const * locker; /* sanity-checking-only context object + for this->mutex */ } nph; /* ** Cache of per-thread state. @@ -602,8 +593,9 @@ struct S3JniGlobalType { S3JniEnv * aHead /* Linked list of in-use instances */; S3JniEnv * aFree /* Linked list of free instances */; sqlite3_mutex * mutex /* mutex for aHead and aFree. */; - void const * locker /* env mutex is held on this object's behalf. - Used only for sanity checking. */; + volatile void const * locker /* env mutex is held on this + object's behalf. Used only for + sanity checking. */; } envCache; /* ** Per-db state. This can move into the core library once we can tie @@ -612,8 +604,10 @@ struct S3JniGlobalType { struct { S3JniDb * aFree /* Linked list of free instances */; sqlite3_mutex * mutex /* mutex for aHead and aFree */; - void const * locker /* perDb mutex is held on this object's - behalf. Used only for sanity checking. */; + volatile void const * locker + /* perDb mutex is held on this object's behalf. Used only for + sanity checking. Note that the mutex is at the class level, not + instance level. */; } perDb; struct { S3JniUdf * aFree /* Head of the free-item list. Guarded by global @@ -646,8 +640,9 @@ struct S3JniGlobalType { int nExt /* number of active entries in aExt, all in the first nExt'th array elements. */; sqlite3_mutex * mutex /* mutex for manipulation/traversal of aExt */; - const void * locker /* object on whose behalf the mutex is held. - Only for sanity checking in debug builds. */; + volatile const void * locker /* object on whose behalf the mutex + is held. Only for sanity checking + in debug builds. */; } autoExt; #ifdef SQLITE_ENABLE_FTS5 struct { @@ -1316,23 +1311,20 @@ static int S3JniEnv_uncache(JNIEnv * const env){ ** This simple cache catches >99% of searches in the current ** (2023-07-31) tests. */ -static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ - S3JniNphClass * const pNC = &SJG.nph.list[pRef->index]; +static S3JniNphOp * s3jni__nphop(JNIEnv * const env, S3JniNphOp const* pRef){ + S3JniNphOp * const pNC = &SJG.nph.list[pRef->index]; - assert( (void*)pRef>=(void*)&S3JniNphRefs && (void*)pRef<(void*)(&S3JniNphRefs + 1) + assert( (void*)pRef>=(void*)&S3JniNphOps && (void*)pRef<(void*)(&S3JniNphOps + 1) && "pRef is out of range" ); assert( pRef->index>=0 - && (pRef->index < (sizeof(S3JniNphRefs) / sizeof(S3JniNphRef))) + && (pRef->index < (sizeof(S3JniNphOps) / sizeof(S3JniNphOp))) && "pRef->index is out of range" ); - if( !pNC->pRef ){ + if( !pNC->klazz ){ S3JniNph_mutex_enter; - if( !pNC->pRef ){ + if( !pNC->klazz ){ jclass const klazz = (*env)->FindClass(env, pRef->zName); S3JniExceptionIsFatal("FindClass() unexpectedly threw"); pNC->klazz = S3JniRefGlobal(klazz); - pNC->pRef = pRef - /* Must come last to avoid a race condition where pNC->klass - can be NULL after this function returns. */; } S3JniNph_mutex_leave; } @@ -1340,11 +1332,11 @@ static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ return pNC; } -#define s3jni_nph(PRef) s3jni__nph(env, PRef) +#define s3jni_nphop(PRef) s3jni__nphop(env, PRef) /* ** Common code for accessor functions for NativePointerHolder and -** OutputPointer types. pRef must be a pointer from S3JniNphRefs. jOut +** OutputPointer types. pRef must be a pointer from S3JniNphOps. jOut ** must be an instance of that class (Java's type safety takes care of ** that requirement). If necessary, this fetches the jfieldID for ** jOut's pRef->zMember, which must be of the type represented by the @@ -1354,8 +1346,8 @@ static S3JniNphClass * s3jni__nph(JNIEnv * const env, S3JniNphRef const* pRef){ ** ** Property lookups are cached on a per-pRef basis. */ -static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphRef const* pRef){ - S3JniNphClass * const pNC = s3jni_nph(pRef); +static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphOp const* pRef){ + S3JniNphOp * const pNC = s3jni_nphop(pRef); if( !pNC->fidValue ){ S3JniNph_mutex_enter; @@ -1363,7 +1355,7 @@ static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphRef const* pRef){ pNC->fidValue = (*env)->GetFieldID(env, pNC->klazz, pRef->zMember, pRef->zTypeSig); S3JniExceptionIsFatal("Code maintenance required: missing " - "required S3JniNphClass::fidValue."); + "required S3JniNphOp::fidValue."); } S3JniNph_mutex_leave; } @@ -1376,7 +1368,7 @@ static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphRef const* pRef){ ** zClassName must be a static string so we can use its address ** as a cache key. */ -static void NativePointerHolder__set(JNIEnv * const env, S3JniNphRef const* pRef, +static void NativePointerHolder__set(JNIEnv * const env, S3JniNphOp const* pRef, jobject ppOut, const void * p){ assert( ppOut ); (*env)->SetLongField(env, ppOut, s3jni_nphop_field(env, pRef), (jlong)p); @@ -1392,7 +1384,7 @@ static void NativePointerHolder__set(JNIEnv * const env, S3JniNphRef const* pRef ** no-op if pObj is NULL. */ static void * NativePointerHolder__get(JNIEnv * env, jobject pObj, - S3JniNphRef const* pRef){ + S3JniNphOp const* pRef){ void * rv = 0; if( pObj ){ rv = (void*)(*env)->GetLongField(env, pObj, s3jni_nphop_field(env, pRef)); @@ -1570,7 +1562,7 @@ static void OutputPointer_set_Int64(JNIEnv * const env, jobject const jOut, ** Object type. */ static void OutputPointer_set_obj(JNIEnv * const env, - S3JniNphRef const * const pRef, + S3JniNphOp const * const pRef, jobject const jOut, jobject v){ (*env)->SetObjectField(env, jOut, s3jni_nphop_field(env, pRef), v); @@ -1666,14 +1658,14 @@ static void ResultJavaValue_finalizer(void *v){ ** if Java fails to allocate, but the JNI docs are not entirely clear ** on that detail. ** -** Always use a static pointer from the S3JniNphRefs struct for the +** Always use a static pointer from the S3JniNphOps struct for the ** 2nd argument. */ static jobject NativePointerHolder_new(JNIEnv * const env, - S3JniNphRef const * pRef, + S3JniNphOp const * pRef, const void * pNative){ jobject rv = 0; - S3JniNphClass * const pNC = s3jni_nph(pRef); + S3JniNphOp * const pNC = s3jni_nphop(pRef); if( !pNC->midCtor ){ S3JniNph_mutex_enter; if( !pNC->midCtor ){ @@ -1826,7 +1818,7 @@ static int udf_args(JNIEnv *env, *jArgv = 0; if( !jcx ) goto error_oom; ja = (*env)->NewObjectArray( - env, argc, s3jni_nph(S3JniNph(sqlite3_value))->klazz, + env, argc, s3jni_nphop(S3JniNph(sqlite3_value))->klazz, NULL); s3jni_oom_check( ja ); if( !ja ) goto error_oom; @@ -2113,12 +2105,12 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, if( 0==SJG.autoExt.nExt ) return 0; env = s3jni_env(); jc = S3JniEnv_get(); - S3JniAutoExt_mutex_enter; + S3JniDb_mutex_enter; ps = jc->pdbOpening ? jc->pdbOpening : S3JniDb_from_c(pDb); if( !ps ){ *pzErr = sqlite3_mprintf("Unexpected arrival of null S3JniDb in " "auto-extension runner."); - S3JniAutoExt_mutex_leave; + S3JniDb_mutex_leave; return SQLITE_ERROR; } assert( ps->jDb ); @@ -2128,7 +2120,7 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, ps, 0/* we'll re-set this after open() completes. */); if( rc ){ - S3JniAutoExt_mutex_leave; + S3JniDb_mutex_leave; return rc; } } @@ -2136,7 +2128,7 @@ static int s3jni_run_java_auto_extensions(sqlite3 *pDb, const char **pzErr, assert( ps == jc->pdbOpening ); jc->pdbOpening = 0; } - S3JniAutoExt_mutex_leave; + S3JniDb_mutex_leave; NativePointerHolder_set(S3JniNph(sqlite3), ps->jDb, pDb) /* As of here, the Java/C connection is complete except for the (temporary) lack of finalizer for the ps object. */; @@ -4442,10 +4434,12 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ SO(S3JniEnv); SO(S3JniHook); SO(S3JniDb); - SO(S3JniNphRefs); + SO(S3JniNphOps); printf("\t(^^^ %u NativePointerHolder/OutputPointer.T types)\n", (unsigned)S3Jni_NphCache_size); SO(S3JniGlobal); + SO(S3JniGlobal.nph); + SO(S3JniGlobal.metrics); SO(S3JniAutoExtension); SO(S3JniUdf); #undef SO @@ -4457,7 +4451,7 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ printf("Mutex entry:" "\n\tglobal = %u" "\n\tenv = %u" - "\n\tnph = %u for S3JniNphClass init" + "\n\tnph = %u for S3JniNphOp init" "\n\tperDb = %u" "\n\tautoExt list = %u" "\n\tS3JniUdf = %u (free-list)" @@ -5034,7 +5028,7 @@ static int s3jni_xTokenize_xToken(void *p, int tFlags, const char* z, ** Proxy for Fts5ExtensionApi.xTokenize() and ** fts5_tokenizer.xTokenize() */ -static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphRef const *pRef, +static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef, jint tokFlags, jobject jFcx, jbyteArray jbaText, jobject jCallback){ Fts5ExtDecl; diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index a0aaa82bbd..e396c94c3b 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -122,7 +122,7 @@ public class Tester1 implements Runnable { affirm(v, "Affirmation failed."); } - @ManualTest /* because testing this for threading is pointless */ + @SingleThreadOnly /* because it's thread-agnostic */ private void test1(){ affirm(sqlite3_libversion_number() == SQLITE_VERSION_NUMBER); } @@ -610,7 +610,7 @@ public class Tester1 implements Runnable { affirm( 1 == xDestroyCalled.value ); } - @ManualTest /* because threading is meaningless here */ + @SingleThreadOnly /* because it's thread-agnostic */ private void testToUtf8(){ /** https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html @@ -978,8 +978,8 @@ public class Tester1 implements Runnable { affirm( 7 == counter.value ); } - @ManualTest /* because threads inherently break this test */ - private void testBusy(){ + @SingleThreadOnly /* because threads inherently break this test */ + private static void testBusy(){ final String dbName = "_busy-handler.db"; final OutputPointer.sqlite3 outDb = new OutputPointer.sqlite3(); final OutputPointer.sqlite3_stmt outStmt = new OutputPointer.sqlite3_stmt(); @@ -1482,7 +1482,7 @@ public class Tester1 implements Runnable { } - @ManualTest /* we really only want to run this test manually. */ + @ManualTest /* we really only want to run this test manually */ private void testSleep(){ out("Sleeping briefly... "); sqlite3_sleep(600); @@ -1525,8 +1525,6 @@ public class Tester1 implements Runnable { outln(); } } - testToUtf8(); - test1(); for(java.lang.reflect.Method m : mlist){ nap(); try{ @@ -1536,9 +1534,6 @@ public class Tester1 implements Runnable { throw e; } } - if( !fromThread ){ - testBusy(); - } synchronized( this.getClass() ){ ++nTestRuns; } diff --git a/manifest b/manifest index 4f091a5f46..32c1abd2c7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\sJNI\scleanups. -D 2023-09-02T08:51:14.022 +C Remove\sa\ssuperfluous\slevel\sof\sindirection\sin\sthe\sJNI\sinternals. +D 2023-09-02T10:18:10.477 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c d98030bb7f502b42990eeb0f2bd103af0b1f1312ba82892949c5ced85262e036 +F ext/jni/src/c/sqlite3-jni.c 1ce08538c568ec47ccf9e88e8b6d0e5b8a874520238d809adbfc93feb9f54d27 F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -264,7 +264,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 93e89c4f72065bf28625cf435c47ed2bd3d937fe5c2431e6e7c3407f09f3f9bc +F ext/jni/src/org/sqlite/jni/Tester1.java e62b0e855ef19a703dc53c1eb8395ff49f5dc4c9471627f5ba71b9b831a18b37 F ext/jni/src/org/sqlite/jni/TesterFts5.java 2b2d6f3cc9f508358c103b774aee296c0f3d8c2f387d6abae9b8b9055f62c800 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2115,8 +2115,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 f9c1f9cad1ad22f689a4afa13d59bf9969ddaed6624cbc16cb1bf5d1fd0c8a5b -R 215167a378a1f1105562740ffd0f1842 +P 30e38173c3ece0c9f8e7a9710f46cb5e8e8ef101c04531318a7adb070242f5dd +R 5b531d67a390c107642befa040c21413 U stephan -Z 15dc34b47fe3ed21ed7cc58408f87312 +Z 11b0834dd4cedde9630a4a43d0bbc08f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bbd378b4fe..96a63aefce 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30e38173c3ece0c9f8e7a9710f46cb5e8e8ef101c04531318a7adb070242f5dd \ No newline at end of file +8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726 \ No newline at end of file From 216433636d86c02129616c7fa368f993b6a84d6e Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 11:26:36 +0000 Subject: [PATCH 15/36] Duplicate code consolidation. FossilOrigin-Name: a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148 --- ext/jni/src/c/sqlite3-jni.c | 175 ++++++++++++++++++++---------------- manifest | 12 +-- manifest.uuid | 2 +- 3 files changed, 103 insertions(+), 86 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index a9e1552cf8..1595fcbb3c 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -574,7 +574,10 @@ struct S3JniGlobalType { ** JNIEnv when necessary. */ JavaVM * jvm; - /* Global mutex. */ + /* + ** Global mutex. It must not be used for anything which might call + ** back into the JNI layer. + */ sqlite3_mutex * mutex; /* ** Cache of references to Java classes and method IDs for @@ -647,19 +650,22 @@ struct S3JniGlobalType { #ifdef SQLITE_ENABLE_FTS5 struct { volatile jobject jExt /* Global ref to Java singleton for the - Fts5ExtensionApi instance. */; + Fts5ExtensionApi instance. */; struct { - jfieldID fidA /* Fts5Phrase::a member */; - jfieldID fidB /* Fts5Phrase::b member */; + jfieldID fidA /* Fts5Phrase::a member */; + jfieldID fidB /* Fts5Phrase::b member */; } jPhraseIter; } fts5; #endif #ifdef SQLITE_ENABLE_SQLLOG struct { - S3JniHook sqllog /* sqlite3_config(SQLITE_CONFIG_SQLLOG) callback */; - S3JniHook * aFree /* free-item list, for recycling. Guarded by - the global mutex. */; - } hooks; + S3JniHook sqllog /* sqlite3_config(SQLITE_CONFIG_SQLLOG) callback */; + S3JniHook * aFree /* free-item list, for recycling. */; + sqlite3_mutex * mutex /* mutex for aFree */; + volatile const void * locker /* object on whose behalf the mutex + is held. Only for sanity checking + in debug builds. */; + } hook; #endif #ifdef SQLITE_JNI_ENABLE_METRICS /* Internal metrics. */ @@ -669,7 +675,8 @@ struct S3JniGlobalType { volatile unsigned nEnvAlloc; volatile unsigned nMutexEnv /* number of times envCache.mutex was entered for a S3JniEnv operation. */; - volatile unsigned nMutexNph /* number of times SJG.mutex was entered for NPH init */; + volatile unsigned nMutexNph /* number of times SJG.mutex was entered */; + volatile unsigned nMutexHook /* number of times SJG.mutex hooks.was entered */; volatile unsigned nMutexPerDb /* number of times perDb.mutex was entered */; volatile unsigned nMutexAutoExt /* number of times autoExt.mutex was entered */; volatile unsigned nMutexGlobal /* number of times global mutex was entered. */; @@ -717,6 +724,21 @@ static void s3jni_incr( volatile unsigned int * const p ){ /* Helpers for working with specific mutexes. */ #if SQLITE_THREADSAFE +#define s3jni_mutex_enter2(M, Metric) \ + sqlite3_mutex_enter( M ); \ + s3jni_incr( &SJG.metrics.Metric ) +#define s3jni_mutex_leave2(M) \ + sqlite3_mutex_leave( M ) + +#define s3jni_mutex_enter(M, L, Metric) \ + assert( (void*)env != (void*)L && "Invalid use of " #L); \ + s3jni_mutex_enter2( M, Metric ); \ + L = env +#define s3jni_mutex_leave(M, L) \ + assert( (void*)env == (void*)L && "Invalid use of " #L); \ + L = 0; \ + s3jni_mutex_leave2( M ) + #define S3JniEnv_mutex_assertLocked \ assert( 0 != SJG.envCache.locker && "Misuse of S3JniGlobal.envCache.mutex" ) #define S3JniEnv_mutex_assertLocker \ @@ -724,69 +746,58 @@ static void s3jni_incr( volatile unsigned int * const p ){ #define S3JniEnv_mutex_assertNotLocker \ assert( (env) != SJG.envCache.locker && "Misuse of S3JniGlobal.envCache.mutex" ) -#define S3JniEnv_mutex_enter \ - S3JniEnv_mutex_assertNotLocker; \ - sqlite3_mutex_enter( SJG.envCache.mutex ); \ - s3jni_incr(&SJG.metrics.nMutexEnv); \ - SJG.envCache.locker = env -#define S3JniEnv_mutex_leave \ - S3JniEnv_mutex_assertLocker; \ - SJG.envCache.locker = 0; \ - sqlite3_mutex_leave( SJG.envCache.mutex ) +#define S3JniEnv_mutex_enter \ + s3jni_mutex_enter( SJG.envCache.mutex, SJG.envCache.locker, nMutexEnv ) +#define S3JniEnv_mutex_leave \ + s3jni_mutex_leave( SJG.envCache.mutex, SJG.envCache.locker ) -#define S3JniAutoExt_mutex_enter \ - sqlite3_mutex_enter( SJG.autoExt.mutex ); \ - SJG.autoExt.locker = env; \ - s3jni_incr( &SJG.metrics.nMutexAutoExt ) -#define S3JniAutoExt_mutex_leave \ - assert( env == SJG.autoExt.locker && "Misuse of S3JniGlobal.autoExt.mutex" ); \ - sqlite3_mutex_leave( SJG.autoExt.mutex ) +#define S3JniAutoExt_mutex_enter \ + s3jni_mutex_enter( SJG.autoExt.mutex, SJG.autoExt.locker, nMutexAutoExt ) +#define S3JniAutoExt_mutex_leave \ + s3jni_mutex_leave( SJG.autoExt.mutex, SJG.autoExt.locker ) #define S3JniAutoExt_mutex_assertLocker \ assert( env == SJG.autoExt.locker && "Misuse of S3JniGlobal.autoExt.mutex" ) -#define S3JniGlobal_mutex_enter \ - sqlite3_mutex_enter( SJG.mutex ); \ - s3jni_incr(&SJG.metrics.nMutexGlobal); -#define S3JniGlobal_mutex_leave sqlite3_mutex_leave( SJG.mutex ) +#define S3JniGlobal_mutex_enter \ + s3jni_mutex_enter2( SJG.mutex, nMutexGlobal ) +#define S3JniGlobal_mutex_leave \ + s3jni_mutex_leave2( SJG.mutex ) -#define S3JniNph_mutex_enter \ - sqlite3_mutex_enter( SJG.nph.mutex ); \ - assert( !SJG.nph.locker && "Misuse of S3JniGlobal.nph.mutex" ); \ - s3jni_incr( &SJG.metrics.nMutexNph ); \ - SJG.nph.locker = env -#define S3JniNph_mutex_leave \ - assert( (env) == SJG.nph.locker && "Misuse of S3JniGlobal.nph.mutex" ); \ - SJG.nph.locker = 0; \ - sqlite3_mutex_leave( SJG.nph.mutex ) +#define S3JniHook_mutex_enter \ + s3jni_mutex_enter( SJG.hook.mutex, SJG.hook.locker, nMutexHook ) +#define S3JniHook_mutex_leave \ + s3jni_mutex_leave( SJG.hook.mutex, SJG.hook.locker ) + +#define S3JniNph_mutex_enter \ + s3jni_mutex_enter( SJG.nph.mutex, SJG.nph.locker, nMutexNph ) +#define S3JniNph_mutex_leave \ + s3jni_mutex_leave( SJG.nph.mutex, SJG.nph.locker ) #define S3JniDb_mutex_assertLocker \ assert( (env) == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ) -#define S3JniDb_mutex_enter \ - sqlite3_mutex_enter( SJG.perDb.mutex ); \ - assert( 0==SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ - s3jni_incr( &SJG.metrics.nMutexPerDb ); \ - SJG.perDb.locker = env; -#define S3JniDb_mutex_leave \ - assert( env == SJG.perDb.locker && "Misuse of S3JniGlobal.perDb.mutex" ); \ - SJG.perDb.locker = 0; \ - sqlite3_mutex_leave( SJG.perDb.mutex ) +#define S3JniDb_mutex_enter \ + s3jni_mutex_enter( SJG.perDb.mutex, SJG.perDb.locker, nMutexPerDb ) +#define S3JniDb_mutex_leave \ + s3jni_mutex_leave( SJG.perDb.mutex, SJG.perDb.locker ) #else /* SQLITE_THREADSAFE==0 */ +#define S3JniAutoExt_mutex_assertLocker +#define S3JniAutoExt_mutex_enter +#define S3JniAutoExt_mutex_leave +#define S3JniDb_mutex_assertLocker +#define S3JniDb_mutex_enter +#define S3JniDb_mutex_leave #define S3JniEnv_mutex_assertLocked #define S3JniEnv_mutex_assertLocker #define S3JniEnv_mutex_assertNotLocker #define S3JniEnv_mutex_enter #define S3JniEnv_mutex_leave -#define S3JniAutoExt_mutex_assertLocker -#define S3JniAutoExt_mutex_enter -#define S3JniAutoExt_mutex_leave #define S3JniGlobal_mutex_enter #define S3JniGlobal_mutex_leave +#define S3JniHook_mutex_enter +#define S3JniHook_mutex_leave #define S3JniNph_mutex_enter #define S3JniNph_mutex_leave -#define S3JniDb_mutex_assertLocker -#define S3JniDb_mutex_enter -#define S3JniDb_mutex_leave #endif /* Helpers for jstring and jbyteArray. */ @@ -1123,12 +1134,12 @@ static void s3jni__call_xDestroy(JNIEnv * const env, jobject jObj){ */ static void S3JniHook__localdup( JNIEnv * const env, S3JniHook const * const src, S3JniHook * const dest ){ - S3JniGlobal_mutex_enter; + S3JniHook_mutex_enter; *dest = *src; if(src->jObj) dest->jObj = S3JniRefLocal(src->jObj); if(src->jExtra) dest->jExtra = S3JniRefLocal(src->jExtra); dest->doXDestroy = 0; - S3JniGlobal_mutex_leave; + S3JniHook_mutex_leave; } #define S3JniHook_localdup(src,dest) S3JniHook__localdup(env,src,dest) @@ -1165,14 +1176,14 @@ static void S3JniHook__unref(JNIEnv * const env, S3JniHook * const s){ */ static S3JniHook *S3JniHook__alloc(JNIEnv * const env){ S3JniHook * p = 0; - S3JniGlobal_mutex_enter; - if( SJG.hooks.aFree ){ - p = SJG.hooks.aFree; - SJG.hooks.aFree = p->pNext; + S3JniHook_mutex_enter; + if( SJG.hook.aFree ){ + p = SJG.hook.aFree; + SJG.hook.aFree = p->pNext; p->pNext = 0; s3jni_incr(&SJG.metrics.nHookRecycled); } - S3JniGlobal_mutex_leave; + S3JniHook_mutex_leave; if( 0==p ){ p = s3jni_malloc(sizeof(S3JniHook)); if( p ){ @@ -1187,17 +1198,17 @@ static S3JniHook *S3JniHook__alloc(JNIEnv * const env){ #define S3JniHook_alloc() S3JniHook__alloc(env) /* -** The rightful fate of all results from S3JniHook_alloc(). Locks the -** global mutex. +** The rightful fate of all results from S3JniHook_alloc(). Locks on +** SJG>hooks.mutex. */ static void S3JniHook__free(JNIEnv * const env, S3JniHook * const p){ if(p){ assert( !p->pNext ); S3JniHook_unref(p); - S3JniGlobal_mutex_enter; - p->pNext = SJG.hooks.aFree; - SJG.hooks.aFree = p; - S3JniGlobal_mutex_leave; + S3JniHook_mutex_enter; + p->pNext = SJG.hook.aFree; + SJG.hook.aFree = p; + S3JniHook_mutex_leave; } } #define S3JniHook_free(hook) S3JniHook__free(env, hook) @@ -1207,10 +1218,10 @@ static void S3JniHook__free(JNIEnv * const env, S3JniHook * const p){ static void S3JniHook__free_unlocked(JNIEnv * const env, S3JniHook * const p){ if(p){ assert( !p->pNext ); - assert( p->pNext != SJG.hooks.aFree ); + assert( p->pNext != SJG.hook.aFree ); S3JniHook_unref(p); - p->pNext = SJG.hooks.aFree; - SJG.hooks.aFree = p; + p->pNext = SJG.hook.aFree; + SJG.hook.aFree = p; } } #define S3JniHook_free_unlocked(hook) S3JniHook__free_unlocked(env, hook) @@ -1751,7 +1762,8 @@ static S3JniUdf * S3JniUdf_alloc(JNIEnv * const env, jobject jObj){ S3JniUnrefLocal(klazz); if( s->jmidxFunc ) s->type = UDF_SCALAR; else if( s->jmidxStep && s->jmidxFinal ){ - s->type = s->jmidxValue ? UDF_WINDOW : UDF_AGGREGATE; + s->type = (s->jmidxValue && s->jmidxInverse) + ? UDF_WINDOW : UDF_AGGREGATE; }else{ s->type = UDF_UNKNOWN_TYPE; } @@ -2764,7 +2776,7 @@ static void s3jni_config_sqllog(void *ignored, sqlite3 *pDb, const char *z, int S3JniHook hook = S3JniHook_empty; if( ps ){ - S3JniHook_localdup(&SJG.hooks.sqllog, &hook); + S3JniHook_localdup(&SJG.hook.sqllog, &hook); } if( !hook.jObj ) return; jArg0 = S3JniRefLocal(ps->jDb); @@ -2801,7 +2813,7 @@ S3JniApi(sqlite3_config() /* for SQLLOG */, #ifndef SQLITE_ENABLE_SQLLOG return SQLITE_MISUSE; #else - S3JniHook * const pHook = &SJG.hooks.sqllog; + S3JniHook * const pHook = &SJG.hook.sqllog; int rc = 0; S3JniGlobal_mutex_enter; @@ -4047,17 +4059,19 @@ S3JniApi(sqlite3_shutdown(),jint,1shutdown)( u->pNext = 0; S3JniUdf_free(env, u, 0); } + } S3JniGlobal_mutex_leave; + S3JniHook_mutex_enter; { /* Free up S3JniHook recycling bin. */ - while( S3JniGlobal.hooks.aFree ){ - S3JniHook * const u = S3JniGlobal.hooks.aFree; - S3JniGlobal.hooks.aFree = u->pNext; + while( S3JniGlobal.hook.aFree ){ + S3JniHook * const u = S3JniGlobal.hook.aFree; + S3JniGlobal.hook.aFree = u->pNext; u->pNext = 0; assert( !u->doXDestroy ); assert( !u->jObj ); assert( !u->jExtra ); sqlite3_free( u ); } - } S3JniGlobal_mutex_leave; + } S3JniHook_mutex_leave; /* Free up env cache. */ S3JniEnv_mutex_enter; { while( SJG.envCache.aHead ){ @@ -4452,14 +4466,15 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ "\n\tglobal = %u" "\n\tenv = %u" "\n\tnph = %u for S3JniNphOp init" + "\n\thook = %u" "\n\tperDb = %u" "\n\tautoExt list = %u" "\n\tS3JniUdf = %u (free-list)" "\n\tmetrics = %u\n", SJG.metrics.nMutexGlobal, SJG.metrics.nMutexEnv, - SJG.metrics.nMutexNph, SJG.metrics.nMutexPerDb, - SJG.metrics.nMutexAutoExt, SJG.metrics.nMutexUdf, - SJG.metrics.nMetrics); + SJG.metrics.nMutexNph, SJG.metrics.nMutexHook, + SJG.metrics.nMutexPerDb, SJG.metrics.nMutexAutoExt, + SJG.metrics.nMutexUdf, SJG.metrics.nMetrics); puts("Allocs:"); printf("\tS3JniDb: %u alloced (*%u = %u bytes), %u recycled\n", SJG.metrics.nPdbAlloc, (unsigned) sizeof(S3JniDb), @@ -5363,6 +5378,8 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ SJG.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); s3jni_oom_fatal( SJG.mutex ); + SJG.hook.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); + s3jni_oom_fatal( SJG.hook.mutex ); SJG.nph.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); s3jni_oom_fatal( SJG.nph.mutex ); SJG.envCache.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); diff --git a/manifest b/manifest index 32c1abd2c7..dff6865b86 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\ssuperfluous\slevel\sof\sindirection\sin\sthe\sJNI\sinternals. -D 2023-09-02T10:18:10.477 +C Duplicate\scode\sconsolidation. +D 2023-09-02T11:26:36.375 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 1ce08538c568ec47ccf9e88e8b6d0e5b8a874520238d809adbfc93feb9f54d27 +F ext/jni/src/c/sqlite3-jni.c 2b274355058b64edb76cbbec8f6459ea977f56bf648becd8c4dba96b9c5147ec F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -2115,8 +2115,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 30e38173c3ece0c9f8e7a9710f46cb5e8e8ef101c04531318a7adb070242f5dd -R 5b531d67a390c107642befa040c21413 +P 8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726 +R cd45a82215972a4be2e15156d78c2ac2 U stephan -Z 11b0834dd4cedde9630a4a43d0bbc08f +Z ff41a71811c7dc2406bc2ebbdfa8abb1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 96a63aefce..b8415855cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726 \ No newline at end of file +a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148 \ No newline at end of file From 7d31de600bc57d291ae9d2f61c91590ae7bc289c Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 12:53:25 +0000 Subject: [PATCH 16/36] Expose sqlite3_complete() to JNI. Slightly widen the definition of "canonical" for the purposes of the @Canonical annotation. Add a few new tests. FossilOrigin-Name: a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce --- ext/jni/src/c/sqlite3-jni.c | 16 ++++++ ext/jni/src/c/sqlite3-jni.h | 24 ++++++--- ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 51 +++++++++++++++---- ext/jni/src/org/sqlite/jni/Tester1.java | 6 +++ ext/jni/src/org/sqlite/jni/TesterFts5.java | 9 +++- .../org/sqlite/jni/annotation/Canonical.java | 10 ++-- manifest | 22 ++++---- manifest.uuid | 2 +- 8 files changed, 107 insertions(+), 33 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 1595fcbb3c..3158622994 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2743,6 +2743,22 @@ S3JniApi(sqlite3_compileoption_get(),jstring,1compileoption_1get)( return rv; } +S3JniApi(sqlite3_complete(),int,1complete)( + JniArgsEnvClass, jbyteArray jSql +){ + jbyte * const pBuf = s3jni_jbytearray_bytes(jSql); + const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jSql) : 0; + int rc; + + assert( (nBa>0 ? 0==pBuf[nBa-1] : (pBuf ? 0==*pBuf : 1)) + && "Byte array is not NUL-terminated." ); + rc = (pBuf && 0==pBuf[(nBa ? nBa-1 : 0)]) + ? sqlite3_complete( (const char *)pBuf ) + : (jSql ? SQLITE_NOMEM : SQLITE_ERROR); + s3jni_jbytearray_release(jSql, pBuf); + return rc; +} + S3JniApi(sqlite3_compileoption_used(),jboolean,1compileoption_1used)( JniArgsEnvClass, jstring name ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 754d57063f..edf1825946 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1099,14 +1099,6 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1column_1value JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1collation_1needed (JNIEnv *, jclass, jobject, jobject); -/* - * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_context_db_handle - * Signature: (Lorg/sqlite/jni/sqlite3_context;)Lorg/sqlite/jni/sqlite3; - */ -JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1context_1db_1handle - (JNIEnv *, jclass, jobject); - /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_commit_hook @@ -1131,6 +1123,14 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1compileoption_ JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1compileoption_1used (JNIEnv *, jclass, jstring); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_complete + * Signature: ([B)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1complete + (JNIEnv *, jclass, jbyteArray); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_config @@ -1147,6 +1147,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__I JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__Lorg_sqlite_jni_ConfigSqllogCallback_2 (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_context_db_handle + * Signature: (Lorg/sqlite/jni/sqlite3_context;)Lorg/sqlite/jni/sqlite3; + */ +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1context_1db_1handle + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_create_collation diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index e7e5c62bcf..66aa504fe6 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -230,6 +230,7 @@ public final class SQLite3Jni { @NotNull sqlite3_stmt stmt, @NotNull byte[] paramName ); + @Canonical public static int sqlite3_bind_parameter_index( @NotNull sqlite3_stmt stmt, @NotNull String paramName ){ @@ -495,11 +496,6 @@ public final class SQLite3Jni { @NotNull sqlite3 db, @Nullable CollationNeededCallback callback ); - @Canonical - public static native sqlite3 sqlite3_context_db_handle( - @NotNull sqlite3_context cx - ); - @Canonical public static native CommitHookCallback sqlite3_commit_hook( @NotNull sqlite3 db, @Nullable CommitHookCallback hook @@ -515,6 +511,24 @@ public final class SQLite3Jni { @NotNull String optName ); + /** + This implementation is private because it's too easy to pass it + non-NUL-terminated arrays. + */ + @Canonical + private static native int sqlite3_complete( + @NotNull byte[] nulTerminatedUtf8Sql + ); + + @Canonical() + public static int sqlite3_complete(@NotNull String sql){ + /* Design note: we don't implement this in native code because we + won't get a NUL-terminated string there unless we make our own + copy to add a terminator. That's much easier to do here. */ + return sqlite3_complete( (sql+"\0").getBytes(StandardCharsets.UTF_8) ); + } + + /**

Works like in the C API with the exception that it only supports the following subset of configution flags: @@ -554,6 +568,11 @@ public final class SQLite3Jni { @Canonical(comment="Option subset: SQLITE_CONFIG_SQLLOG") public static native int sqlite3_config( @Nullable ConfigSqllogCallback logger ); + @Canonical + public static native sqlite3 sqlite3_context_db_handle( + @NotNull sqlite3_context cx + ); + @Canonical public static native int sqlite3_create_collation( @NotNull sqlite3 db, @NotNull String name, int eTextRep, @@ -761,6 +780,7 @@ public final class SQLite3Jni {

Several overloads provided simplified call signatures. */ + @Canonical public static int sqlite3_prepare( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, @NotNull OutputPointer.sqlite3_stmt outStmt, @@ -815,6 +835,7 @@ public final class SQLite3Jni { output paramter is returned as the index offset into the given byte array at which SQL parsing stopped. */ + @Canonical public static int sqlite3_prepare_v2( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, @NotNull OutputPointer.sqlite3_stmt outStmt, @@ -865,6 +886,7 @@ public final class SQLite3Jni { output paramter is returned as the index offset into the given byte array at which SQL parsing stopped. */ + @Canonical public static int sqlite3_prepare_v3( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, int prepFlags, @NotNull OutputPointer.sqlite3_stmt outStmt, @@ -998,20 +1020,22 @@ public final class SQLite3Jni { The main sqlite3_result_error() impl of which all others are proxies. eTextRep must be one of SQLITE_UTF8 or SQLITE_UTF16 and msg must be encoded correspondingly. Any other eTextRep value - results in the C-level sqlite3_result_error() being called with - a complaint about the invalid argument. + results in the C-level sqlite3_result_error() being called with a + complaint about the invalid argument. */ @Canonical private static native void sqlite3_result_error( @NotNull sqlite3_context cx, @NotNull byte[] msg, int eTextRep ); + @Canonical public static void sqlite3_result_error( @NotNull sqlite3_context cx, @NotNull byte[] utf8 ){ sqlite3_result_error(cx, utf8, SQLITE_UTF8); } + @Canonical public static void sqlite3_result_error( @NotNull sqlite3_context cx, @NotNull String msg ){ @@ -1178,6 +1202,7 @@ public final class SQLite3Jni { @NotNull sqlite3_context cx, @Nullable byte[] blob, int maxLen ); + @Canonical public static void sqlite3_result_blob( @NotNull sqlite3_context cx, @Nullable byte[] blob ){ @@ -1207,6 +1232,7 @@ public final class SQLite3Jni { @NotNull sqlite3_context cx, @Nullable byte[] blob, long maxLen ); + @Canonical public static void sqlite3_result_blob64( @NotNull sqlite3_context cx, @Nullable byte[] blob ){ @@ -1222,12 +1248,14 @@ public final class SQLite3Jni { @NotNull sqlite3_context cx, @Nullable byte[] utf8, int maxLen ); + @Canonical public static void sqlite3_result_text( @NotNull sqlite3_context cx, @Nullable byte[] utf8 ){ sqlite3_result_text(cx, utf8, null==utf8 ? 0 : utf8.length); } + @Canonical public static void sqlite3_result_text( @NotNull sqlite3_context cx, @Nullable String text ){ @@ -1271,12 +1299,14 @@ public final class SQLite3Jni { Sets the current UDF result to the given bytes, which are assumed be encoded in UTF-16 using the platform's byte order. */ + @Canonical public static void sqlite3_result_text16( @NotNull sqlite3_context cx, @Nullable byte[] utf16 ){ sqlite3_result_text64(cx, utf16, utf16.length, SQLITE_UTF16); } + @Canonical public static void sqlite3_result_text16( @NotNull sqlite3_context cx, @Nullable String text ){ @@ -1363,9 +1393,10 @@ public final class SQLite3Jni { */ @Canonical private static native int sqlite3_strglob( - @NotNull byte[] glob, @NotNull byte[] txt + @NotNull byte[] glob, @NotNull byte[] nullTerminatedUtf8 ); + @Canonical public static int sqlite3_strglob( @NotNull String glob, @NotNull String txt ){ @@ -1380,9 +1411,11 @@ public final class SQLite3Jni { */ @Canonical private static native int sqlite3_strlike( - @NotNull byte[] glob, @NotNull byte[] txt, int escChar + @NotNull byte[] glob, @NotNull byte[] nullTerminatedUtf8, + int escChar ); + @Canonical public static int sqlite3_strlike( @NotNull String glob, @NotNull String txt, char escChar ){ diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index e396c94c3b..dd2c73657f 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1472,6 +1472,12 @@ public class Tester1 implements Runnable { sqlite3_close_v2(db); } + private void testComplete(){ + affirm( 0==sqlite3_complete("select 1") ); + affirm( 0!=sqlite3_complete("select 1;") ); + affirm( 0!=sqlite3_complete("nope 'nope' 'nope' 1;"), "Yup" ); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); diff --git a/ext/jni/src/org/sqlite/jni/TesterFts5.java b/ext/jni/src/org/sqlite/jni/TesterFts5.java index 5f0be352a5..5cbaed22c0 100644 --- a/ext/jni/src/org/sqlite/jni/TesterFts5.java +++ b/ext/jni/src/org/sqlite/jni/TesterFts5.java @@ -40,16 +40,23 @@ public class TesterFts5 { final fts5_extension_function func = new fts5_extension_function(){ @Override public void call(Fts5ExtensionApi ext, Fts5Context fCx, sqlite3_context pCx, sqlite3_value argv[]){ - int nCols = ext.xColumnCount(fCx); + final int nCols = ext.xColumnCount(fCx); affirm( 2 == nCols ); affirm( nCols == argv.length ); affirm( ext.xUserData(fCx) == pUserData ); final OutputPointer.String op = new OutputPointer.String(); + final OutputPointer.Int32 colsz = new OutputPointer.Int32(); + final OutputPointer.Int64 colTotalSz = new OutputPointer.Int64(); for(int i = 0; i < nCols; ++i ){ int rc = ext.xColumnText(fCx, i, op); affirm( 0 == rc ); final String val = op.value; affirm( val.equals(sqlite3_value_text16(argv[i])) ); + rc = ext.xColumnSize(fCx, i, colsz); + affirm( 0==rc ); + affirm( 3==sqlite3_value_bytes(argv[i]) ); + rc = ext.xColumnTotalSize(fCx, i, colTotalSz); + affirm( 0==rc ); } ++xFuncCount.value; } diff --git a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java index 24b0f82d4c..fdb157335f 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/Canonical.java +++ b/ext/jni/src/org/sqlite/jni/annotation/Canonical.java @@ -10,9 +10,13 @@ package org.sqlite.jni.annotation; same semantics as their counterparts in the C API documentation, despite their signatures perhaps differing - slightly. The Java API adds a number of overloads to simplify use, - as well as a few Java-specific functions, and those are never - flagged as @Canonical. + slightly. Canonical forms may be native or implemented in Java. + Sometimes multiple overloads are labeled as Canonical because one + or more of them are just type- or encoding-related conversion + wrappers but provide identical semantics (e.g. from a String to a + byte[]). The Java API adds a number of convenience overloads to + simplify use, as well as a few Java-specific functions, and those + are never flagged as @Canonical.

In some cases, the canonical version of a function is private and exposed to Java via public overloads. diff --git a/manifest b/manifest index dff6865b86..4430edf981 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Duplicate\scode\sconsolidation. -D 2023-09-02T11:26:36.375 +C Expose\ssqlite3_complete()\sto\sJNI.\sSlightly\swiden\sthe\sdefinition\sof\s"canonical"\sfor\sthe\spurposes\sof\sthe\s@Canonical\sannotation.\sAdd\sa\sfew\snew\stests. +D 2023-09-02T12:53:25.655 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 2b274355058b64edb76cbbec8f6459ea977f56bf648becd8c4dba96b9c5147ec -F ext/jni/src/c/sqlite3-jni.h c22f0189254abe26fad3ba132b484785b19a1aa96d34d30d7d8c5ffe6a9b25d1 +F ext/jni/src/c/sqlite3-jni.c 88e7ced81dcb82200b16cebf6d67564c3844f9af1c17717a94afda38793b7a08 +F ext/jni/src/c/sqlite3-jni.h eed8d955de3b55c50242d44104f3f5bf299625f69b97e747541509c04019c9ce F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -261,17 +261,17 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 98f8d62492e2d6693336dd42c12267ea7f21eefe219aa85b8dd399bd6b0732bd +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 900c43e4789a0faf822febdbe0ae58719832d43ad6b78bee2cfc4a20c38fdab5 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java e62b0e855ef19a703dc53c1eb8395ff49f5dc4c9471627f5ba71b9b831a18b37 -F ext/jni/src/org/sqlite/jni/TesterFts5.java 2b2d6f3cc9f508358c103b774aee296c0f3d8c2f387d6abae9b8b9055f62c800 +F ext/jni/src/org/sqlite/jni/Tester1.java f67a63e3b138495b0c51dcb4f0e1ee1fcb91d772107afabf6d90256ea0ce3c4a +F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 -F ext/jni/src/org/sqlite/jni/annotation/Canonical.java d9ff79f1bf9d063d0c3e3b768ec7df15f51e4ca51a5bb291d33b7a6ea9a24f3a +F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0f8234d379d266d1b2c21400a057864b538a0ea5 F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 @@ -2115,8 +2115,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 8dca6f7660c15eacbda20da1c66c9ef1de36864f78750658226b1a7baf22b726 -R cd45a82215972a4be2e15156d78c2ac2 +P a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148 +R 728b2c246df3114419f3af688349a1b0 U stephan -Z ff41a71811c7dc2406bc2ebbdfa8abb1 +Z abdadbf4f03136eea88913bb00194ef2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b8415855cf..a4982f259e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148 \ No newline at end of file +a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce \ No newline at end of file From de4d1c357f8bf8cf246b4cd3159306be141e0c38 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 2 Sep 2023 14:36:41 +0000 Subject: [PATCH 17/36] Add sqlite3_config(SQLITE_CONFIG_LOG) support to Java and correct clearing of SQLITE_CONFIG_SQLLOG. Correct missing names in propagated UDF exception messages. FossilOrigin-Name: 652e2e82100ac3d8238d15ef6d43de4162fd02d695db4936ad5706fe4f2d7dc3 --- ext/jni/GNUmakefile | 1 + ext/jni/src/c/sqlite3-jni.c | 74 +++++++++++++++++-- ext/jni/src/c/sqlite3-jni.h | 8 ++ .../src/org/sqlite/jni/ConfigLogCallback.java | 25 +++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 8 +- ext/jni/src/org/sqlite/jni/Tester1.java | 18 ++++- manifest | 21 +++--- manifest.uuid | 2 +- 8 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 ext/jni/src/org/sqlite/jni/ConfigLogCallback.java diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 92819688d8..1e0b33be0a 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -77,6 +77,7 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\ CollationCallback.java \ CollationNeededCallback.java \ CommitHookCallback.java \ + ConfigLogCallback.java \ ConfigSqllogCallback.java \ NativePointerHolder.java \ OutputPointer.java \ diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 3158622994..2f89e3c250 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -657,16 +657,17 @@ struct S3JniGlobalType { } jPhraseIter; } fts5; #endif -#ifdef SQLITE_ENABLE_SQLLOG struct { +#ifdef SQLITE_ENABLE_SQLLOG S3JniHook sqllog /* sqlite3_config(SQLITE_CONFIG_SQLLOG) callback */; +#endif + S3JniHook configlog /* sqlite3_config(SQLITE_CONFIG_LOG) callback */; S3JniHook * aFree /* free-item list, for recycling. */; sqlite3_mutex * mutex /* mutex for aFree */; volatile const void * locker /* object on whose behalf the mutex is held. Only for sanity checking in debug builds. */; } hook; -#endif #ifdef SQLITE_JNI_ENABLE_METRICS /* Internal metrics. */ struct { @@ -2781,6 +2782,60 @@ S3JniApi(sqlite3_config() /*for a small subset of options.*/, return SQLITE_MISUSE; } } +/* C-to-Java SQLITE_CONFIG_LOG wrapper. */ +static void s3jni_config_log(void *ignored, int errCode, const char *z){ + S3JniDeclLocal_env; + S3JniHook hook = S3JniHook_empty; + + S3JniHook_localdup(&SJG.hook.configlog, &hook); + if( hook.jObj ){ + jstring const jArg1 = z ? s3jni_utf8_to_jstring(z, -1) : 0; + if( z ? !!jArg1 : 1 ){ + (*env)->CallVoidMethod(env, hook.jObj, hook.midCallback, errCode, jArg1); + } + S3JniIfThrew{ + S3JniExceptionWarnCallbackThrew("SQLITE_CONFIG_LOG callback"); + S3JniExceptionClear; + } + S3JniHook_localundup(hook); + S3JniUnrefLocal(jArg1); + } +} + +S3JniApi(sqlite3_config() /* for SQLITE_CONFIG_LOG */, + jint, 1config__Lorg_sqlite_jni_ConfigLogCallback_2 +)(JniArgsEnvClass, jobject jLog){ + S3JniHook * const pHook = &SJG.hook.configlog; + int rc = 0; + + S3JniGlobal_mutex_enter; + if( !jLog ){ + rc = sqlite3_config( SQLITE_CONFIG_LOG, NULL, NULL ); + if( 0==rc ){ + S3JniHook_unref(pHook); + } + }else if( pHook->jObj && (*env)->IsSameObject(env, jLog, pHook->jObj) ){ + /* No-op */ + }else { + jclass const klazz = (*env)->GetObjectClass(env, jLog); + jmethodID const midCallback = (*env)->GetMethodID(env, klazz, "call", + "(ILjava/lang/String;)V"); + S3JniUnrefLocal(klazz); + if( midCallback ){ + rc = sqlite3_config( SQLITE_CONFIG_LOG, s3jni_config_log, NULL ); + if( 0==rc ){ + S3JniHook_unref(pHook); + pHook->midCallback = midCallback; + pHook->jObj = S3JniRefGlobal(jLog); + } + }else{ + S3JniExceptionWarnIgnore; + rc = SQLITE_ERROR; + } + } + S3JniGlobal_mutex_leave; + return rc; +} #ifdef SQLITE_ENABLE_SQLLOG /* C-to-Java SQLITE_CONFIG_SQLLOG wrapper. */ @@ -2822,10 +2877,9 @@ void sqlite3_init_sqllog(void){ } #endif -S3JniApi(sqlite3_config() /* for SQLLOG */, +S3JniApi(sqlite3_config() /* for SQLITE_CONFIG_SQLLOG */, jint, 1config__Lorg_sqlite_jni_ConfigSqllogCallback_2)( - JniArgsEnvClass, jobject jLog - ){ + JniArgsEnvClass, jobject jLog){ #ifndef SQLITE_ENABLE_SQLLOG return SQLITE_MISUSE; #else @@ -2834,7 +2888,7 @@ S3JniApi(sqlite3_config() /* for SQLLOG */, S3JniGlobal_mutex_enter; if( !jLog ){ - rc = sqlite3_config( SQLITE_CONFIG_SQLLOG, s3jni_config_sqllog, 0 ); + rc = sqlite3_config( SQLITE_CONFIG_SQLLOG, NULL ); if( 0==rc ){ S3JniHook_unref(pHook); } @@ -2848,7 +2902,7 @@ S3JniApi(sqlite3_config() /* for SQLLOG */, "I)V"); S3JniUnrefLocal(klazz); if( midCallback ){ - rc = sqlite3_config( SQLITE_CONFIG_SQLLOG, s3jni_config_sqllog, 0 ); + rc = sqlite3_config( SQLITE_CONFIG_SQLLOG, s3jni_config_sqllog, NULL ); if( 0==rc ){ S3JniHook_unref(pHook); pHook->midCallback = midCallback; @@ -2988,6 +3042,7 @@ S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() S3JniUdf_free(env, s, 1); goto error_cleanup; } + s->zFuncName = zFuncName /* pass on ownership */; if( UDF_WINDOW == s->type ){ rc = sqlite3_create_window_function(pDb, zFuncName, nArg, eTextRep, s, udf_xStep, udf_xFinal, udf_xValue, @@ -3009,7 +3064,6 @@ S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() error_cleanup: /* Reminder: on sqlite3_create_function() error, s will be ** destroyed via create_function(). */ - sqlite3_free(zFuncName); return (jint)rc; } @@ -4058,6 +4112,10 @@ S3JniApi(sqlite3_shutdown(),jint,1shutdown)( JniArgsEnvClass ){ s3jni_reset_auto_extension(env); +#ifdef SQLITE_ENABLE_SQLLOG + S3JniHook_unref(&SJG.hook.sqllog); +#endif + S3JniHook_unref(&SJG.hook.configlog); /* Free up S3JniDb recycling bin. */ S3JniDb_mutex_enter; { while( S3JniGlobal.perDb.aFree ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index edf1825946..77d796ae73 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1147,6 +1147,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__I JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__Lorg_sqlite_jni_ConfigSqllogCallback_2 (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_config + * Signature: (Lorg/sqlite/jni/ConfigLogCallback;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1config__Lorg_sqlite_jni_ConfigLogCallback_2 + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_context_db_handle diff --git a/ext/jni/src/org/sqlite/jni/ConfigLogCallback.java b/ext/jni/src/org/sqlite/jni/ConfigLogCallback.java new file mode 100644 index 0000000000..2198f1e104 --- /dev/null +++ b/ext/jni/src/org/sqlite/jni/ConfigLogCallback.java @@ -0,0 +1,25 @@ +/* +** 2023-08-23 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file is part of the JNI bindings for the sqlite3 C API. +*/ +package org.sqlite.jni; + +/** + A callback for use with sqlite3_config(). +*/ +public interface ConfigLogCallback { + /** + Must function as described for a C-level callback for + {@link SQLite3Jni#sqlite3_config(ConfigLogCallback)}, with the slight signature change. + */ + void call(int errCode, String msg); +} diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 66aa504fe6..747eac410d 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -563,11 +563,17 @@ public final class SQLite3Jni {

Note that sqlite3_config() is not threadsafe with regards to the rest of the library. This must not be called when any other library APIs are being called. - */ @Canonical(comment="Option subset: SQLITE_CONFIG_SQLLOG") public static native int sqlite3_config( @Nullable ConfigSqllogCallback logger ); + /** + The sqlite3_config() overload for handling the SQLITE_CONFIG_LOG + option. + */ + @Canonical(comment="Option subset: SQLITE_CONFIG_LOG") + public static native int sqlite3_config( @Nullable ConfigLogCallback logger ); + @Canonical public static native sqlite3 sqlite3_context_db_handle( @NotNull sqlite3_context cx diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index dd2c73657f..b8600cb13c 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1590,6 +1590,7 @@ public class Tester1 implements Runnable { Integer nRepeat = 1; boolean forceFail = false; boolean sqlLog = false; + boolean configLog = false; boolean squelchTestOutput = false; for( int i = 0; i < args.length; ){ String arg = args[i++]; @@ -1610,6 +1611,8 @@ public class Tester1 implements Runnable { forceFail = true; }else if(arg.equals("sqllog")){ sqlLog = true; + }else if(arg.equals("configlog")){ + configLog = true; }else if(arg.equals("naps")){ takeNaps = true; }else if(arg.equals("q") || arg.equals("quiet")){ @@ -1633,7 +1636,7 @@ public class Tester1 implements Runnable { }; int rc = sqlite3_config( log ); affirm( 0==rc ); - rc = sqlite3_config( null ); + rc = sqlite3_config( (ConfigSqllogCallback)null ); affirm( 0==rc ); rc = sqlite3_config( log ); affirm( 0==rc ); @@ -1642,6 +1645,19 @@ public class Tester1 implements Runnable { "without SQLITE_ENABLE_SQLLOG."); } } + if( configLog ){ + final ConfigLogCallback log = new ConfigLogCallback() { + @Override public void call(int code, String msg){ + outln("ConfigLogCallback: ",ResultCode.getEntryForInt(code),": ", msg); + }; + }; + int rc = sqlite3_config( log ); + affirm( 0==rc ); + rc = sqlite3_config( (ConfigLogCallback)null ); + affirm( 0==rc ); + rc = sqlite3_config( log ); + affirm( 0==rc ); + } quietMode = squelchTestOutput; outln("If you just saw warning messages regarding CallStaticObjectMethod, ", diff --git a/manifest b/manifest index 4430edf981..3661b98108 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_complete()\sto\sJNI.\sSlightly\swiden\sthe\sdefinition\sof\s"canonical"\sfor\sthe\spurposes\sof\sthe\s@Canonical\sannotation.\sAdd\sa\sfew\snew\stests. -D 2023-09-02T12:53:25.655 +C Add\ssqlite3_config(SQLITE_CONFIG_LOG)\ssupport\sto\sJava\sand\scorrect\sclearing\sof\sSQLITE_CONFIG_SQLLOG.\sCorrect\smissing\snames\sin\spropagated\sUDF\sexception\smessages. +D 2023-09-02T14:36:41.961 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,11 +234,11 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile dc6e78f9717470d262b4b3ec17c337834295f9df81717c1539da84106324fd1e +F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 88e7ced81dcb82200b16cebf6d67564c3844f9af1c17717a94afda38793b7a08 -F ext/jni/src/c/sqlite3-jni.h eed8d955de3b55c50242d44104f3f5bf299625f69b97e747541509c04019c9ce +F ext/jni/src/c/sqlite3-jni.c 066404920b85b3e06b7ce20e84cb3ebc5754c069f044db23205d34b3b1c15134 +F ext/jni/src/c/sqlite3-jni.h 2a04e2bf686e5eaa3ae9bcf11b1c38fb348e09071f081361eb224eae2a65194f F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -248,6 +248,7 @@ F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996 F ext/jni/src/org/sqlite/jni/CollationCallback.java df327348e1a34ee65210208d694d690e5ee0bfe901410122e07caf6c98b2b7c8 F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b81154295258037f662e7c372735c2899c76e81cb3abd9fd3b39 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 +F ext/jni/src/org/sqlite/jni/ConfigLogCallback.java 636ed6b89ed03f15bc2a6f6f47bf7853b8328e5a8269e52e80630708efa703a6 F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 F ext/jni/src/org/sqlite/jni/Fts5.java 3ebfbd5b95fdb9d7bc40306f2e682abd12e247d9224e92510b8dd103b4f96fe8 F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 @@ -261,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 900c43e4789a0faf822febdbe0ae58719832d43ad6b78bee2cfc4a20c38fdab5 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java d73d372747aafed21d25b5b27c1e893f332e5977f0ad70f458412edcc747c28a F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java f67a63e3b138495b0c51dcb4f0e1ee1fcb91d772107afabf6d90256ea0ce3c4a +F ext/jni/src/org/sqlite/jni/Tester1.java d3f99cde2487dd8c9a0be9fc9146fecd28a70c6df8bfd1fd476e68c2c940114e F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2115,8 +2116,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 a1872ae959cca11d5d8bc224aaeb0b53e772d999df9924b2e9ea84ceedb99148 -R 728b2c246df3114419f3af688349a1b0 +P a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce +R e1d1983d1d616224caf72675cc27855c U stephan -Z abdadbf4f03136eea88913bb00194ef2 +Z 290673eb8d4334de0d33df1e73324ad2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a4982f259e..e20ba8d16d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce \ No newline at end of file +652e2e82100ac3d8238d15ef6d43de4162fd02d695db4936ad5706fe4f2d7dc3 \ No newline at end of file From 2966b85df3c091681c6496b46306f3d2c29a3b97 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 09:28:45 +0000 Subject: [PATCH 18/36] Export the sqlite3_keyword_...() family of functions to JNI. FossilOrigin-Name: bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7 --- ext/jni/src/c/sqlite3-jni.c | 31 +++++++++++++++++++++- ext/jni/src/c/sqlite3-jni.h | 24 +++++++++++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 11 +++++++- ext/jni/src/org/sqlite/jni/Tester1.java | 10 +++++++ manifest | 18 ++++++------- manifest.uuid | 2 +- 6 files changed, 84 insertions(+), 12 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 2f89e3c250..2832196e35 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2061,6 +2061,7 @@ WRAP_INT_DB(1error_1offset, sqlite3_error_offset) WRAP_INT_DB(1extended_1errcode, sqlite3_extended_errcode) WRAP_MUTF8_VOID(1libversion, sqlite3_libversion) WRAP_INT_VOID(1libversion_1number, sqlite3_libversion_number) +WRAP_INT_VOID(1keyword_1count, sqlite3_keyword_count) #ifdef SQLITE_ENABLE_PREUPDATE_HOOK WRAP_INT_DB(1preupdate_1blobwrite, sqlite3_preupdate_blobwrite) WRAP_INT_DB(1preupdate_1count, sqlite3_preupdate_count) @@ -2398,7 +2399,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)( rc = sqlite3_busy_handler(ps->pDb, s3jni_busy_handler, ps); if( 0==rc ){ S3JniHook_unref(pHook); - *pHook = hook; + *pHook = hook /* transfer Java ref ownership */; hook = S3JniHook_empty; } }/* else no-op */ @@ -3307,6 +3308,34 @@ JniDecl(jboolean,1java_1uncache_1thread)(JniArgsEnvClass){ return rc ? JNI_TRUE : JNI_FALSE; } +S3JniApi(sqlite3_keyword_check(),jboolean,1keyword_1check)( + JniArgsEnvClass, jstring jWord +){ + int nWord = 0; + char * zWord = s3jni_jstring_to_utf8(jWord, &nWord); + int rc = 0; + + s3jni_oom_check(jWord ? !!zWord : 1); + if( zWord && nWord ){ + rc = sqlite3_keyword_check(zWord, nWord); + } + sqlite3_free(zWord); + return rc ? JNI_TRUE : JNI_FALSE; +} + +S3JniApi(sqlite3_keyword_name(),jstring,1keyword_1name)( + JniArgsEnvClass, jint ndx +){ + const char * zWord = 0; + int n = 0; + jstring rv = 0; + + if( 0==sqlite3_keyword_name(ndx, &zWord, &n) ){ + rv = s3jni_utf8_to_jstring(zWord, n); + } + return rv; +} + S3JniApi(sqlite3_last_insert_rowid(),jlong,1last_1insert_1rowid)( JniArgsEnvClass, jobject jpDb diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 77d796ae73..7f8b351c58 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1323,6 +1323,30 @@ JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1interrupt JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1is_1interrupted (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_keyword_check + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1check + (JNIEnv *, jclass, jstring); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_keyword_count + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1count + (JNIEnv *, jclass); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_keyword_name + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1keyword_1name + (JNIEnv *, jclass, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_last_insert_rowid diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 747eac410d..a287fc9941 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -543,7 +543,6 @@ public final class SQLite3Jni {

Note that sqlite3_config() is not threadsafe with regards to the rest of the library. This must not be called when any other library APIs are being called. - */ @Canonical(comment="Option subset: "+ "SQLITE_CONFIG_SINGLETHREAD, SQLITE_CONFIG_MULTITHREAD, "+ @@ -682,6 +681,16 @@ public final class SQLite3Jni { @Canonical public static native boolean sqlite3_is_interrupted(@NotNull sqlite3 db); + @Canonical + public static native boolean sqlite3_keyword_check(@NotNull String word); + + @Canonical + public static native int sqlite3_keyword_count(); + + @Canonical + public static native String sqlite3_keyword_name(int index); + + @Canonical public static native long sqlite3_last_insert_rowid(@NotNull sqlite3 db); diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index b8600cb13c..3245821d19 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1478,6 +1478,16 @@ public class Tester1 implements Runnable { affirm( 0!=sqlite3_complete("nope 'nope' 'nope' 1;"), "Yup" ); } + private void testKeyword(){ + final int n = sqlite3_keyword_count(); + affirm( n>0 ); + affirm( !sqlite3_keyword_check("_nope_") ); + affirm( sqlite3_keyword_check("seLect") ); + affirm( null!=sqlite3_keyword_name(0) ); + affirm( null!=sqlite3_keyword_name(n-1) ); + affirm( null==sqlite3_keyword_name(n) ); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); diff --git a/manifest b/manifest index 3661b98108..eccf284707 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssqlite3_config(SQLITE_CONFIG_LOG)\ssupport\sto\sJava\sand\scorrect\sclearing\sof\sSQLITE_CONFIG_SQLLOG.\sCorrect\smissing\snames\sin\spropagated\sUDF\sexception\smessages. -D 2023-09-02T14:36:41.961 +C Export\sthe\ssqlite3_keyword_...()\sfamily\sof\sfunctions\sto\sJNI. +D 2023-09-03T09:28:45.568 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 066404920b85b3e06b7ce20e84cb3ebc5754c069f044db23205d34b3b1c15134 -F ext/jni/src/c/sqlite3-jni.h 2a04e2bf686e5eaa3ae9bcf11b1c38fb348e09071f081361eb224eae2a65194f +F ext/jni/src/c/sqlite3-jni.c a873c29cc80b14dd775a75359f7a3973642e8d9a84a8f37e3bcb85ab426aa820 +F ext/jni/src/c/sqlite3-jni.h ff6f69ffc2ace23ac7a7628405efe9846e33586a4399bfe48cec846be79e39df F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java d73d372747aafed21d25b5b27c1e893f332e5977f0ad70f458412edcc747c28a +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java b9dd5ba6b538648a27ed9c61217a5ae56645d0494b205b814fd488d375857984 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java d3f99cde2487dd8c9a0be9fc9146fecd28a70c6df8bfd1fd476e68c2c940114e +F ext/jni/src/org/sqlite/jni/Tester1.java 410fd7e126847456011372e38977d4331888f054e8ca509545aab65e3c0ed96a F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2116,8 +2116,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 a59fe0cd9552128ca4186f4e66f0d188f2a57c7647f43828e42cb95801f350ce -R e1d1983d1d616224caf72675cc27855c +P 652e2e82100ac3d8238d15ef6d43de4162fd02d695db4936ad5706fe4f2d7dc3 +R 7fd736a7d08745015fcc69ede4fd14cc U stephan -Z 290673eb8d4334de0d33df1e73324ad2 +Z b7483f74605eb1221b65312bed3e2257 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e20ba8d16d..4787060430 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -652e2e82100ac3d8238d15ef6d43de4162fd02d695db4936ad5706fe4f2d7dc3 \ No newline at end of file +bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7 \ No newline at end of file From 24a689cf01faf8b4079c9f5a47f894c838d04bf4 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 10:23:03 +0000 Subject: [PATCH 19/36] Export the sqlite3_backup_...() APIs to JNI. FossilOrigin-Name: 865a3df5d550f6f4edbf95854750706e4e747d8f1825ae73d300b8e31934959b --- ext/jni/src/c/sqlite3-jni.c | 119 +++++++++++++----- ext/jni/src/c/sqlite3-jni.h | 40 ++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 20 +++ ext/jni/src/org/sqlite/jni/Tester1.java | 29 +++++ .../src/org/sqlite/jni/sqlite3_backup.java | 25 ++++ manifest | 19 +-- manifest.uuid | 2 +- 7 files changed, 214 insertions(+), 40 deletions(-) create mode 100644 ext/jni/src/org/sqlite/jni/sqlite3_backup.java diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 2832196e35..a587764408 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -335,8 +335,9 @@ struct S3JniNphOp { */ static const struct { const S3JniNphOp sqlite3; - const S3JniNphOp sqlite3_stmt; + const S3JniNphOp sqlite3_backup; const S3JniNphOp sqlite3_context; + const S3JniNphOp sqlite3_stmt; const S3JniNphOp sqlite3_value; const S3JniNphOp OutputPointer_Bool; const S3JniNphOp OutputPointer_Int32; @@ -361,26 +362,27 @@ static const struct { /* OutputPointer.T ref */ #define RefO(INDEX, KLAZZ, SIG) MkRef(INDEX, KLAZZ, "value", SIG) RefN(0, "sqlite3"), - RefN(1, "sqlite3_stmt"), + RefN(1, "sqlite3_backup"), RefN(2, "sqlite3_context"), - RefN(3, "sqlite3_value"), - RefO(4, "OutputPointer$Bool", "Z"), - RefO(5, "OutputPointer$Int32", "I"), - RefO(6, "OutputPointer$Int64", "J"), - RefO(7, "OutputPointer$sqlite3", + RefN(3, "sqlite3_stmt"), + RefN(4, "sqlite3_value"), + RefO(5, "OutputPointer$Bool", "Z"), + RefO(6, "OutputPointer$Int32", "I"), + RefO(7, "OutputPointer$Int64", "J"), + RefO(8, "OutputPointer$sqlite3", "Lorg/sqlite/jni/sqlite3;"), - RefO(8, "OutputPointer$sqlite3_stmt", + RefO(9, "OutputPointer$sqlite3_stmt", "Lorg/sqlite/jni/sqlite3_stmt;"), - RefO(9, "OutputPointer$sqlite3_value", + RefO(10, "OutputPointer$sqlite3_value", "Lorg/sqlite/jni/sqlite3_value;"), - RefO(10, "OutputPointer$String", "Ljava/lang/String;"), + RefO(11, "OutputPointer$String", "Ljava/lang/String;"), #ifdef SQLITE_ENABLE_FTS5 - RefO(11, "OutputPointer$ByteArray", "[B"), - RefN(12, "Fts5Context"), - RefN(13, "Fts5ExtensionApi"), - RefN(14, "fts5_api"), - RefN(15, "fts5_tokenizer"), - RefN(16, "Fts5Tokenizer") + RefO(12, "OutputPointer$ByteArray", "[B"), + RefN(13, "Fts5Context"), + RefN(14, "Fts5ExtensionApi"), + RefN(15, "fts5_api"), + RefN(16, "fts5_tokenizer"), + RefN(17, "Fts5Tokenizer") #endif #undef MkRef #undef RefN @@ -1376,30 +1378,30 @@ static jfieldID s3jni_nphop_field(JNIEnv * const env, S3JniNphOp const* pRef){ } /* -** Sets a native ptr value in NativePointerHolder object ppOut. -** zClassName must be a static string so we can use its address -** as a cache key. +** Sets a native ptr value in NativePointerHolder object jNph, +** which must be of the native type described by pRef. jNph +** may not be NULL. */ static void NativePointerHolder__set(JNIEnv * const env, S3JniNphOp const* pRef, - jobject ppOut, const void * p){ - assert( ppOut ); - (*env)->SetLongField(env, ppOut, s3jni_nphop_field(env, pRef), (jlong)p); + jobject jNph, const void * p){ + assert( jNph ); + (*env)->SetLongField(env, jNph, s3jni_nphop_field(env, pRef), (jlong)p); S3JniExceptionIsFatal("Could not set NativePointerHolder.nativePointer."); } -#define NativePointerHolder_set(PREF,PPOUT,P) \ - NativePointerHolder__set(env, PREF, PPOUT, P) +#define NativePointerHolder_set(PREF,JNPH,P) \ + NativePointerHolder__set(env, PREF, JNPH, P) /* -** Fetches a native ptr value from NativePointerHolder object pObj, +** Fetches a native ptr value from NativePointerHolder object jNph, ** which must be of the native type described by pRef. This is a -** no-op if pObj is NULL. +** no-op if jNph is NULL. */ -static void * NativePointerHolder__get(JNIEnv * env, jobject pObj, +static void * NativePointerHolder__get(JNIEnv * env, jobject jNph, S3JniNphOp const* pRef){ void * rv = 0; - if( pObj ){ - rv = (void*)(*env)->GetLongField(env, pObj, s3jni_nphop_field(env, pRef)); + if( jNph ){ + rv = (void*)(*env)->GetLongField(env, jNph, s3jni_nphop_field(env, pRef)); S3JniExceptionIsFatal("Cannot fetch NativePointerHolder.nativePointer."); } return rv; @@ -1424,9 +1426,10 @@ static void * NativePointerHolder__get(JNIEnv * env, jobject pObj, */ #define PtrGet_T(T,OBJ) NativePointerHolder_get(OBJ, S3JniNph(T)) #define PtrGet_sqlite3(OBJ) PtrGet_T(sqlite3, OBJ) +#define PtrGet_sqlite3_backup(OBJ) PtrGet_T(sqlite3_backup, OBJ) +#define PtrGet_sqlite3_context(OBJ) PtrGet_T(sqlite3_context, OBJ) #define PtrGet_sqlite3_stmt(OBJ) PtrGet_T(sqlite3_stmt, OBJ) #define PtrGet_sqlite3_value(OBJ) PtrGet_T(sqlite3_value, OBJ) -#define PtrGet_sqlite3_context(OBJ) PtrGet_T(sqlite3_context, OBJ) #if 0 /* @@ -1696,6 +1699,9 @@ static jobject NativePointerHolder_new(JNIEnv * const env, static inline jobject new_java_sqlite3(JNIEnv * const env, sqlite3 *sv){ return NativePointerHolder_new(env, S3JniNph(sqlite3), sv); } +static inline jobject new_java_sqlite3_backup(JNIEnv * const env, sqlite3_backup *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3_backup), sv); +} static inline jobject new_java_sqlite3_context(JNIEnv * const env, sqlite3_context *sv){ return NativePointerHolder_new(env, S3JniNph(sqlite3_context), sv); } @@ -2239,6 +2245,59 @@ S3JniApi(sqlite3_auto_extension(),jint,1auto_1extension)( return rc; } +S3JniApi(sqlite3_backup_finish(),jint,1backup_1finish)( + JniArgsEnvClass, jobject jBack +){ + sqlite3_backup * const pB = PtrGet_sqlite3_backup(jBack); + NativePointerHolder_set(S3JniNph(sqlite3_backup), jBack, 0); + return sqlite3_backup_finish(pB); +} + +S3JniApi(sqlite3_backup_init(),jobject,1backup_1init)( + JniArgsEnvClass, jobject jDbDest, jstring jTDest, + jobject jDbSrc, jstring jTSrc +){ + sqlite3 * const pDest = PtrGet_sqlite3(jDbDest); + sqlite3 * const pSrc = PtrGet_sqlite3(jDbSrc); + char * const zDest = s3jni_jstring_to_utf8(jTDest, 0); + char * const zSrc = s3jni_jstring_to_utf8(jTSrc, 0); + jobject rv = 0; + + if( pDest && pSrc && zDest && zSrc ){ + sqlite3_backup * const pB = + sqlite3_backup_init(pDest, zDest, pSrc, zSrc); + if( pB ){ + rv = new_java_sqlite3_backup(env, pB); + if( rv ){ + NativePointerHolder_set(S3JniNph(sqlite3_backup), rv, pB); + }else{ + sqlite3_backup_finish( pB ); + } + } + } + sqlite3_free(zDest); + sqlite3_free(zSrc); + return rv; +} + +S3JniApi(sqlite3_backup_pagecount(),jint,1backup_1pagecount)( + JniArgsEnvClass, jobject jBack +){ + return sqlite3_backup_pagecount(PtrGet_sqlite3_backup(jBack)); +} + +S3JniApi(sqlite3_backup_remaining(),jint,1backup_1remaining)( + JniArgsEnvClass, jobject jBack +){ + return sqlite3_backup_remaining(PtrGet_sqlite3_backup(jBack)); +} + +S3JniApi(sqlite3_backup_step(),jint,1backup_1step)( + JniArgsEnvClass, jobject jBack, jint nPage +){ + return sqlite3_backup_step(PtrGet_sqlite3_backup(jBack), (int)nPage); +} + S3JniApi(sqlite3_bind_blob(),jint,1bind_1blob)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 7f8b351c58..f573eacc90 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -811,6 +811,46 @@ JNIEXPORT jlong JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1aggregate_1conte JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1auto_1extension (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_backup_finish + * Signature: (Lorg/sqlite/jni/sqlite3_backup;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1backup_1finish + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_backup_init + * Signature: (Lorg/sqlite/jni/sqlite3;Ljava/lang/String;Lorg/sqlite/jni/sqlite3;Ljava/lang/String;)Lorg/sqlite/jni/sqlite3_backup; + */ +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1backup_1init + (JNIEnv *, jclass, jobject, jstring, jobject, jstring); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_backup_pagecount + * Signature: (Lorg/sqlite/jni/sqlite3_backup;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1backup_1pagecount + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_backup_remaining + * Signature: (Lorg/sqlite/jni/sqlite3_backup;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1backup_1remaining + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_backup_step + * Signature: (Lorg/sqlite/jni/sqlite3_backup;I)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1backup_1step + (JNIEnv *, jclass, jobject, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_bind_blob diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index a287fc9941..feb6b7a92f 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -165,6 +165,26 @@ public final class SQLite3Jni { @Canonical public static native int sqlite3_auto_extension(@NotNull AutoExtensionCallback callback); + @Canonical + public static native int sqlite3_backup_finish(@NotNull sqlite3_backup b); + + @Canonical + public static native sqlite3_backup sqlite3_backup_init( + @NotNull sqlite3 dbDest, @NotNull String destTableName, + @NotNull sqlite3 dbSrc, @NotNull String srcTableName + ); + + @Canonical + public static native int sqlite3_backup_pagecount(@NotNull sqlite3_backup b); + + @Canonical + public static native int sqlite3_backup_remaining(@NotNull sqlite3_backup b); + + @Canonical + public static native int sqlite3_backup_step( + @NotNull sqlite3_backup b, int nPage + ); + /** Results are undefined if data is not null and n<0 || n>=data.length. */ diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 3245821d19..b7b8907aa2 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1488,6 +1488,35 @@ public class Tester1 implements Runnable { affirm( null==sqlite3_keyword_name(n) ); } + private void testBackup(){ + final sqlite3 db1 = createNewDb(); + final sqlite3 db2 = createNewDb(); + + execSql(db1, new String[]{ + "pragma page_size=512; VACUUM;", + "create table t(a);", + "insert into t(a) values(1),(2),(3);" + }); + affirm( null==sqlite3_backup_init(db1,"main",db1,"main") ); + final sqlite3_backup b = sqlite3_backup_init(db2,"main",db1,"main"); + affirm( null!=b ); + int rc; + while( SQLITE_DONE!=(rc = sqlite3_backup_step(b, 1)) ){ + affirm( 0==rc ); + } + affirm( sqlite3_backup_pagecount(b) > 0 ); + rc = sqlite3_backup_finish(b); + sqlite3_close_v2(db1); + affirm( 0==rc ); + + final sqlite3_stmt stmt = prepare(db2,"SELECT sum(a) from t"); + sqlite3_step(stmt); + affirm( sqlite3_column_int(stmt,0) == 6 ); + + sqlite3_finalize(stmt); + sqlite3_close_v2(db2); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); diff --git a/ext/jni/src/org/sqlite/jni/sqlite3_backup.java b/ext/jni/src/org/sqlite/jni/sqlite3_backup.java new file mode 100644 index 0000000000..d8ba78aec8 --- /dev/null +++ b/ext/jni/src/org/sqlite/jni/sqlite3_backup.java @@ -0,0 +1,25 @@ +/* +** 2023-09-03 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file is part of the JNI bindings for the sqlite3 C API. +*/ +package org.sqlite.jni; + +/** + A wrapper for passing C-level (sqlite3_backup*) instances around in + Java. These wrappers do not own their associated pointer, they + simply provide a type-safe way to communicate it between Java and C + via JNI. +*/ +public final class sqlite3_backup extends NativePointerHolder { + // Only invoked from JNI. + private sqlite3_backup(){} +} diff --git a/manifest b/manifest index eccf284707..94302f6df8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Export\sthe\ssqlite3_keyword_...()\sfamily\sof\sfunctions\sto\sJNI. -D 2023-09-03T09:28:45.568 +C Export\sthe\ssqlite3_backup_...()\sAPIs\sto\sJNI. +D 2023-09-03T10:23:03.357 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c a873c29cc80b14dd775a75359f7a3973642e8d9a84a8f37e3bcb85ab426aa820 -F ext/jni/src/c/sqlite3-jni.h ff6f69ffc2ace23ac7a7628405efe9846e33586a4399bfe48cec846be79e39df +F ext/jni/src/c/sqlite3-jni.c cd5be50471af97c0bb422aa7e3cfdaa19158f6a56b6b93af9602039b6bf56434 +F ext/jni/src/c/sqlite3-jni.h b00eab4f5412849a05ba3cb5e44f0583e4698176a41c63bc1d7d425e7e89865a F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java b9dd5ba6b538648a27ed9c61217a5ae56645d0494b205b814fd488d375857984 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 38126c76219a61ec19c972e1162b4fb4311b99f201fd986b262275dbdadeac9d F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 410fd7e126847456011372e38977d4331888f054e8ca509545aab65e3c0ed96a +F ext/jni/src/org/sqlite/jni/Tester1.java 48ffe327cae2d599059cf4ec026bd3bf11d743efd6a13dc61b9c21122efc39c8 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -281,6 +281,7 @@ F ext/jni/src/org/sqlite/jni/fts5_extension_function.java bec9f17a7e784d57eca99d F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc +F ext/jni/src/org/sqlite/jni/sqlite3_backup.java d0bb06dd6225e76999ff6b7ab20f2643b1c4d4167431b3a93ea41943e41f094b F ext/jni/src/org/sqlite/jni/sqlite3_context.java 66ca95ce904044263a4aff684abe262d56f73e6b06bca6cf650761d79d7779ad F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a @@ -2116,8 +2117,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 652e2e82100ac3d8238d15ef6d43de4162fd02d695db4936ad5706fe4f2d7dc3 -R 7fd736a7d08745015fcc69ede4fd14cc +P bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7 +R cb965cc2f3508a211c89a61afe16623f U stephan -Z b7483f74605eb1221b65312bed3e2257 +Z b11611848e8e630b2ee28833698b37c5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4787060430..508721251c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7 \ No newline at end of file +865a3df5d550f6f4edbf95854750706e4e747d8f1825ae73d300b8e31934959b \ No newline at end of file From 54021c3bd027a7ac09298e53d687c43ed2756f7b Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 10:36:21 +0000 Subject: [PATCH 20/36] Add a couple more sqlite3_backup tests. FossilOrigin-Name: 5c2cf89d2c3ae5fc31b5e311bc2f2c1fef0037bdb0dff48c0a2a6bb6610e0215 --- ext/jni/src/org/sqlite/jni/Tester1.java | 5 ++++- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index b7b8907aa2..e9b844c590 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1500,14 +1500,17 @@ public class Tester1 implements Runnable { affirm( null==sqlite3_backup_init(db1,"main",db1,"main") ); final sqlite3_backup b = sqlite3_backup_init(db2,"main",db1,"main"); affirm( null!=b ); + affirm( b.getNativePointer()!=0 ); int rc; while( SQLITE_DONE!=(rc = sqlite3_backup_step(b, 1)) ){ affirm( 0==rc ); } affirm( sqlite3_backup_pagecount(b) > 0 ); rc = sqlite3_backup_finish(b); - sqlite3_close_v2(db1); affirm( 0==rc ); + affirm( b.getNativePointer()==0 ); + + sqlite3_close_v2(db1); final sqlite3_stmt stmt = prepare(db2,"SELECT sum(a) from t"); sqlite3_step(stmt); diff --git a/manifest b/manifest index 94302f6df8..722bebdb38 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Export\sthe\ssqlite3_backup_...()\sAPIs\sto\sJNI. -D 2023-09-03T10:23:03.357 +C Add\sa\scouple\smore\ssqlite3_backup\stests. +D 2023-09-03T10:36:21.861 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -265,7 +265,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 38126c76219a61ec19c972e1162b4fb4311b99f201fd986b262275dbdadeac9d F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 48ffe327cae2d599059cf4ec026bd3bf11d743efd6a13dc61b9c21122efc39c8 +F ext/jni/src/org/sqlite/jni/Tester1.java 50a7816c5bf89310f3eecc258de751fbc9d085b4a5e6972a033c6c80f38504e9 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2117,8 +2117,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 bd554db39159d8a538ce913d55285e3c417db8823c717a3e34bfa0678de42be7 -R cb965cc2f3508a211c89a61afe16623f +P 865a3df5d550f6f4edbf95854750706e4e747d8f1825ae73d300b8e31934959b +R ca57ffa1c47e32218d423204c262cc23 U stephan -Z b11611848e8e630b2ee28833698b37c5 +Z e97299a93ec066b0b9a25543267c80c7 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 508721251c..efe21b09ab 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -865a3df5d550f6f4edbf95854750706e4e747d8f1825ae73d300b8e31934959b \ No newline at end of file +5c2cf89d2c3ae5fc31b5e311bc2f2c1fef0037bdb0dff48c0a2a6bb6610e0215 \ No newline at end of file From ce9902f8c2d4eabed7e4218ba5617a2be7c2d3f0 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 11:08:31 +0000 Subject: [PATCH 21/36] Remove some unnecessary code. FossilOrigin-Name: c7f9bbbbf0252c9749450e3ec994bf5ac945bd62428657ddff469291a0fd4b0d --- ext/jni/src/c/sqlite3-jni.c | 4 +--- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index a587764408..28502a338b 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2268,9 +2268,7 @@ S3JniApi(sqlite3_backup_init(),jobject,1backup_1init)( sqlite3_backup_init(pDest, zDest, pSrc, zSrc); if( pB ){ rv = new_java_sqlite3_backup(env, pB); - if( rv ){ - NativePointerHolder_set(S3JniNph(sqlite3_backup), rv, pB); - }else{ + if( !rv ){ sqlite3_backup_finish( pB ); } } diff --git a/manifest b/manifest index 722bebdb38..9af3b6b47e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\scouple\smore\ssqlite3_backup\stests. -D 2023-09-03T10:36:21.861 +C Remove\ssome\sunnecessary\scode. +D 2023-09-03T11:08:31.547 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c cd5be50471af97c0bb422aa7e3cfdaa19158f6a56b6b93af9602039b6bf56434 +F ext/jni/src/c/sqlite3-jni.c a1ee9263fd90816f1277fc9bb991819429de876603f0a0582816655802683c9b F ext/jni/src/c/sqlite3-jni.h b00eab4f5412849a05ba3cb5e44f0583e4698176a41c63bc1d7d425e7e89865a F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -2117,8 +2117,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 865a3df5d550f6f4edbf95854750706e4e747d8f1825ae73d300b8e31934959b -R ca57ffa1c47e32218d423204c262cc23 +P 5c2cf89d2c3ae5fc31b5e311bc2f2c1fef0037bdb0dff48c0a2a6bb6610e0215 +R 316fc221ecf481f07f9a494e67ec65bd U stephan -Z e97299a93ec066b0b9a25543267c80c7 +Z 8178d6d584b1b8e590ff75d907a1905b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index efe21b09ab..7d29917732 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c2cf89d2c3ae5fc31b5e311bc2f2c1fef0037bdb0dff48c0a2a6bb6610e0215 \ No newline at end of file +c7f9bbbbf0252c9749450e3ec994bf5ac945bd62428657ddff469291a0fd4b0d \ No newline at end of file From e30436b605ffd547b1f2abd163c12d42a71a6250 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 11:16:48 +0000 Subject: [PATCH 22/36] Expose sqlite3_get_autocommit() to JNI. FossilOrigin-Name: 67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9 --- ext/jni/src/c/sqlite3-jni.c | 7 +++++++ ext/jni/src/c/sqlite3-jni.h | 8 ++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 3 +++ ext/jni/src/org/sqlite/jni/Tester1.java | 2 ++ manifest | 18 +++++++++--------- manifest.uuid | 2 +- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 28502a338b..963107bcea 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2038,6 +2038,11 @@ static void udf_xInverse(sqlite3_context* cx, int argc, JniDecl(jint,JniNameSuffix)(JniArgsEnvClass, jobject pDb){ \ return (jint)CName(PtrGet_sqlite3(pDb)); \ } +/** Create a trivial JNI wrapper for (boolean CName(sqlite3*)). */ +#define WRAP_BOOL_DB(JniNameSuffix,CName) \ + JniDecl(jboolean,JniNameSuffix)(JniArgsEnvClass, jobject pDb){ \ + return CName(PtrGet_sqlite3(pDb)) ? JNI_TRUE : JNI_FALSE; \ + } /** Create a trivial JNI wrapper for (int64 CName(sqlite3*)). */ #define WRAP_INT64_DB(JniNameSuffix,CName) \ JniDecl(jlong,JniNameSuffix)(JniArgsEnvClass, jobject pDb){ \ @@ -2065,6 +2070,7 @@ WRAP_INT_STMT_INT(1column_1type, sqlite3_column_type) WRAP_INT_STMT(1data_1count, sqlite3_data_count) WRAP_INT_DB(1error_1offset, sqlite3_error_offset) WRAP_INT_DB(1extended_1errcode, sqlite3_extended_errcode) +WRAP_BOOL_DB(1get_1autocommit, sqlite3_get_autocommit) WRAP_MUTF8_VOID(1libversion, sqlite3_libversion) WRAP_INT_VOID(1libversion_1number, sqlite3_libversion_number) WRAP_INT_VOID(1keyword_1count, sqlite3_keyword_count) @@ -2091,6 +2097,7 @@ WRAP_INT_SVALUE(1value_1numeric_1type, sqlite3_value_numeric_type) WRAP_INT_SVALUE(1value_1subtype, sqlite3_value_subtype) WRAP_INT_SVALUE(1value_1type, sqlite3_value_type) +#undef WRAP_BOOL_DB #undef WRAP_INT64_DB #undef WRAP_INT_DB #undef WRAP_INT_INT diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index f573eacc90..872ea70275 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1323,6 +1323,14 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errmsg JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errstr (JNIEnv *, jclass, jint); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_get_autocommit + * Signature: (Lorg/sqlite/jni/sqlite3;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1get_1autocommit + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_error_offset diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index feb6b7a92f..1fe739e9c0 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -682,6 +682,9 @@ public final class SQLite3Jni { @Canonical public static native String sqlite3_errstr(int resultCode); + @Canonical + public static native boolean sqlite3_get_autocommit(@NotNull sqlite3 db); + /** Note that the returned byte offset values assume UTF-8-encoded inputs, so won't always match character offsets in Java Strings. diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index e9b844c590..a4756e6760 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1436,7 +1436,9 @@ public class Tester1 implements Runnable { private void testTxnState(){ final sqlite3 db = createNewDb(); affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); + affirm( sqlite3_get_autocommit(db) ); execSql(db, "BEGIN;"); + affirm( !sqlite3_get_autocommit(db) ); affirm( SQLITE_TXN_NONE == sqlite3_txn_state(db, null) ); execSql(db, "SELECT * FROM sqlite_schema;"); affirm( SQLITE_TXN_READ == sqlite3_txn_state(db, "main") ); diff --git a/manifest b/manifest index 9af3b6b47e..4d4fa0a7be 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\ssome\sunnecessary\scode. -D 2023-09-03T11:08:31.547 +C Expose\ssqlite3_get_autocommit()\sto\sJNI. +D 2023-09-03T11:16:48.124 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c a1ee9263fd90816f1277fc9bb991819429de876603f0a0582816655802683c9b -F ext/jni/src/c/sqlite3-jni.h b00eab4f5412849a05ba3cb5e44f0583e4698176a41c63bc1d7d425e7e89865a +F ext/jni/src/c/sqlite3-jni.c 33db80b56070ce82722f981dce36a5435d99b507d4090ef9ce6c70b6c2c8b6ed +F ext/jni/src/c/sqlite3-jni.h d4b4533a298519d112be91aec6ca858043f03b490cef06fb6b0b304bb779230d F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 38126c76219a61ec19c972e1162b4fb4311b99f201fd986b262275dbdadeac9d +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 9060a509eb15e94cf56fead3c1987cae327c5f325526ad2058dde03191371e88 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 50a7816c5bf89310f3eecc258de751fbc9d085b4a5e6972a033c6c80f38504e9 +F ext/jni/src/org/sqlite/jni/Tester1.java 0c37badac93c948d340688967fa205062fa70d6fd1c72730b5ececc1419319cd F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2117,8 +2117,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 5c2cf89d2c3ae5fc31b5e311bc2f2c1fef0037bdb0dff48c0a2a6bb6610e0215 -R 316fc221ecf481f07f9a494e67ec65bd +P c7f9bbbbf0252c9749450e3ec994bf5ac945bd62428657ddff469291a0fd4b0d +R 15dd68606e4abb0a87ecc7f9abf4f88a U stephan -Z 8178d6d584b1b8e590ff75d907a1905b +Z 0078f656620477114933b33a92cabf9c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7d29917732..b8132d004b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7f9bbbbf0252c9749450e3ec994bf5ac945bd62428657ddff469291a0fd4b0d \ No newline at end of file +67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9 \ No newline at end of file From 83a8b6dd82212c5eea3fc95bf9954912d278e9dd Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 11:58:33 +0000 Subject: [PATCH 23/36] Expose sqlite3_get/set_auxdata() to JNI. FossilOrigin-Name: 0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed --- ext/jni/src/c/sqlite3-jni.c | 20 +++++++-- ext/jni/src/c/sqlite3-jni.h | 48 ++++++++++++++-------- ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 22 +++++++--- manifest | 16 ++++---- manifest.uuid | 2 +- 5 files changed, 73 insertions(+), 35 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 963107bcea..f2fc310c0f 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -1654,9 +1654,9 @@ static const char * const ResultJavaValuePtrStr = "org.sqlite.jni.ResultJavaVal" /* ** If v is not NULL, it must be a jobject global reference. Its -** reference is relinquished and v is freed. +** reference is relinquished. */ -static void ResultJavaValue_finalizer(void *v){ +static void S3Jni_jobject_finalizer(void *v){ if( v ){ S3JniDeclLocal_env; S3JniUnrefGlobal((jobject)v); @@ -2351,7 +2351,7 @@ S3JniApi(sqlite3_bind_java_object(),jint,1bind_1java_1object)( jobject const rv = val ? S3JniRefGlobal(val) : 0; if( rv ){ rc = sqlite3_bind_pointer(pStmt, ndx, rv, ResultJavaValuePtrStr, - ResultJavaValue_finalizer); + S3Jni_jobject_finalizer); }else if(val){ rc = SQLITE_NOMEM; } @@ -3333,6 +3333,12 @@ S3JniApi(sqlite3_finalize(),jint,1finalize)( return rc; } +S3JniApi(sqlite3_get_auxdata(),jobject,1get_1auxdata)( + JniArgsEnvClass, jobject jCx, jint n +){ + return sqlite3_get_auxdata(PtrGet_sqlite3_context(jCx), (int)n); +} + S3JniApi(sqlite3_initialize(),jint,1initialize)( JniArgsEnvClass ){ @@ -4063,7 +4069,7 @@ S3JniApi(sqlite3_result_java_object(),void,1result_1java_1object)( jobject const rjv = S3JniRefGlobal(v); if( rjv ){ sqlite3_result_pointer(PtrGet_sqlite3_context(jpCx), rjv, - ResultJavaValuePtrStr, ResultJavaValue_finalizer); + ResultJavaValuePtrStr, S3Jni_jobject_finalizer); }else{ sqlite3_result_error_nomem(PtrGet_sqlite3_context(jpCx)); } @@ -4193,6 +4199,12 @@ S3JniApi(sqlite3_set_authorizer(),jint,1set_1authorizer)( return rc; } +S3JniApi(sqlite3_set_auxdata(),void,1set_1auxdata)( + JniArgsEnvClass, jobject jCx, jint n, jobject jAux +){ + sqlite3_set_auxdata(PtrGet_sqlite3_context(jCx), (int)n, + S3JniRefGlobal(jAux), S3Jni_jobject_finalizer); +} S3JniApi(sqlite3_set_last_insert_rowid(),void,1set_1last_1insert_1rowid)( JniArgsEnvClass, jobject jpDb, jlong rowId diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 872ea70275..6beb1e3f0b 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1283,6 +1283,22 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1db_1status JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errcode (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_errmsg + * Signature: (Lorg/sqlite/jni/sqlite3;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errmsg + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_errstr + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errstr + (JNIEnv *, jclass, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_expanded_sql @@ -1307,22 +1323,6 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1extended_1errcode JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1extended_1result_1codes (JNIEnv *, jclass, jobject, jboolean); -/* - * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_errmsg - * Signature: (Lorg/sqlite/jni/sqlite3;)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errmsg - (JNIEnv *, jclass, jobject); - -/* - * Class: org_sqlite_jni_SQLite3Jni - * Method: sqlite3_errstr - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errstr - (JNIEnv *, jclass, jint); - /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_get_autocommit @@ -1331,6 +1331,14 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1errstr JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1get_1autocommit (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_get_auxdata + * Signature: (Lorg/sqlite/jni/sqlite3_context;I)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1get_1auxdata + (JNIEnv *, jclass, jobject, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_error_offset @@ -1691,6 +1699,14 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1rollback_1hook JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1set_1authorizer (JNIEnv *, jclass, jobject, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_set_auxdata + * Signature: (Lorg/sqlite/jni/sqlite3_context;ILjava/lang/Object;)V + */ +JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1set_1auxdata + (JNIEnv *, jclass, jobject, jint, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_set_last_insert_rowid diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 1fe739e9c0..7c956ebb6c 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -665,6 +665,12 @@ public final class SQLite3Jni { @Canonical public static native int sqlite3_errcode(@NotNull sqlite3 db); + @Canonical + public static native String sqlite3_errmsg(@NotNull sqlite3 db); + + @Canonical + public static native String sqlite3_errstr(int resultCode); + @Canonical public static native String sqlite3_expanded_sql(@NotNull sqlite3_stmt stmt); @@ -676,15 +682,14 @@ public final class SQLite3Jni { @NotNull sqlite3 db, boolean onoff ); - @Canonical - public static native String sqlite3_errmsg(@NotNull sqlite3 db); - - @Canonical - public static native String sqlite3_errstr(int resultCode); - @Canonical public static native boolean sqlite3_get_autocommit(@NotNull sqlite3 db); + @Canonical + public static native Object sqlite3_get_auxdata( + @NotNull sqlite3_context cx, int n + ); + /** Note that the returned byte offset values assume UTF-8-encoded inputs, so won't always match character offsets in Java Strings. @@ -1365,6 +1370,11 @@ public final class SQLite3Jni { @NotNull sqlite3 db, @Nullable AuthorizerCallback auth ); + @Canonical + public static native void sqlite3_set_auxdata( + @NotNull sqlite3_context cx, int n, @Nullable Object data + ); + @Canonical public static native void sqlite3_set_last_insert_rowid( @NotNull sqlite3 db, long rowid diff --git a/manifest b/manifest index 4d4fa0a7be..0e68031bef 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_get_autocommit()\sto\sJNI. -D 2023-09-03T11:16:48.124 +C Expose\ssqlite3_get/set_auxdata()\sto\sJNI. +D 2023-09-03T11:58:33.070 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 33db80b56070ce82722f981dce36a5435d99b507d4090ef9ce6c70b6c2c8b6ed -F ext/jni/src/c/sqlite3-jni.h d4b4533a298519d112be91aec6ca858043f03b490cef06fb6b0b304bb779230d +F ext/jni/src/c/sqlite3-jni.c 649b305d2281d350067b63b1d077410a38ae9a06366634ee5e22131ba070c1ef +F ext/jni/src/c/sqlite3-jni.h c95632356c61ccc5975c41bf35e5bc79d24fd1e8375d068731ea0b2f625b51f7 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,7 +262,7 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 9060a509eb15e94cf56fead3c1987cae327c5f325526ad2058dde03191371e88 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e84f456b5f1636f45c50f1d532247631a1569c99a3a504d04c9ed4f4ed3fbf02 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab F ext/jni/src/org/sqlite/jni/Tester1.java 0c37badac93c948d340688967fa205062fa70d6fd1c72730b5ececc1419319cd @@ -2117,8 +2117,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 c7f9bbbbf0252c9749450e3ec994bf5ac945bd62428657ddff469291a0fd4b0d -R 15dd68606e4abb0a87ecc7f9abf4f88a +P 67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9 +R 85fc08c8b7dbbee0a10820fd8df0b1f2 U stephan -Z 0078f656620477114933b33a92cabf9c +Z d25cca227f7f4f43edfdc564cc64fc9b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index b8132d004b..9d8e468fc9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9 \ No newline at end of file +0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed \ No newline at end of file From 194335626814e6e424521cf08e3e476231a6a174 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 12:17:34 +0000 Subject: [PATCH 24/36] Expose sqlite3_randomness() to JNI. FossilOrigin-Name: de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf --- ext/jni/src/c/sqlite3-jni.c | 74 +++++++++++++--------- ext/jni/src/c/sqlite3-jni.h | 8 +++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 3 + ext/jni/src/org/sqlite/jni/Tester1.java | 14 ++++ manifest | 18 +++--- manifest.uuid | 2 +- 6 files changed, 79 insertions(+), 40 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index f2fc310c0f..67c90f6e89 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -813,15 +813,17 @@ static const char * s3jni__jstring_to_mutf8_bytes(JNIEnv * const env, jstring v #define s3jni_jstring_to_mutf8(ARG) s3jni__jstring_to_mutf8_bytes(env, (ARG)) #define s3jni_mutf8_release(ARG,VAR) if( VAR ) (*env)->ReleaseStringUTFChars(env, ARG, VAR) -static jbyte * s3jni__jbytearray_bytes(JNIEnv * const env, jbyteArray jBA ){ +static jbyte * s3jni__jbyteArray_bytes(JNIEnv * const env, jbyteArray jBA ){ jbyte * const rv = jBA ? (*env)->GetByteArrayElements(env, jBA, NULL) : 0; s3jni_oom_check( jBA ? !!rv : 1 ); return rv; } -#define s3jni_jbytearray_bytes(jByteArray) s3jni__jbytearray_bytes(env, (jByteArray)) -#define s3jni_jbytearray_release(jByteArray,jBytes) \ +#define s3jni_jbyteArray_bytes(jByteArray) s3jni__jbyteArray_bytes(env, (jByteArray)) +#define s3jni_jbyteArray_release(jByteArray,jBytes) \ if( jBytes ) (*env)->ReleaseByteArrayElements(env, jByteArray, jBytes, JNI_ABORT) +#define s3jni_jbyteArray_commit(jByteArray,jBytes) \ + if( jBytes ) (*env)->ReleaseByteArrayElements(env, jByteArray, jBytes, JNI_COMMIT) /* ** Returns the current JNIEnv object. Fails fatally if it cannot find @@ -2306,12 +2308,12 @@ S3JniApi(sqlite3_backup_step(),jint,1backup_1step)( S3JniApi(sqlite3_bind_blob(),jint,1bind_1blob)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ - jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0; + jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0; int rc; if( pBuf ){ rc = sqlite3_bind_blob(PtrGet_sqlite3_stmt(jpStmt), (int)ndx, pBuf, (int)nMax, SQLITE_TRANSIENT); - s3jni_jbytearray_release(baData, pBuf); + s3jni_jbyteArray_release(baData, pBuf); }else{ rc = baData ? SQLITE_NOMEM @@ -2371,11 +2373,11 @@ S3JniApi(sqlite3_bind_parameter_index(),jint,1bind_1parameter_1index)( JniArgsEnvClass, jobject jpStmt, jbyteArray jName ){ int rc = 0; - jbyte * const pBuf = s3jni_jbytearray_bytes(jName); + jbyte * const pBuf = s3jni_jbyteArray_bytes(jName); if( pBuf ){ rc = sqlite3_bind_parameter_index(PtrGet_sqlite3_stmt(jpStmt), (const char *)pBuf); - s3jni_jbytearray_release(jName, pBuf); + s3jni_jbyteArray_release(jName, pBuf); } return rc; } @@ -2383,21 +2385,21 @@ S3JniApi(sqlite3_bind_parameter_index(),jint,1bind_1parameter_1index)( S3JniApi(sqlite3_bind_text(),jint,1bind_1text)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ - jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0; + jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0; int const rc = sqlite3_bind_text(PtrGet_sqlite3_stmt(jpStmt), (int)ndx, (const char *)pBuf, (int)nMax, SQLITE_TRANSIENT); - s3jni_jbytearray_release(baData, pBuf); + s3jni_jbyteArray_release(baData, pBuf); return (jint)rc; } S3JniApi(sqlite3_bind_text16(),jint,1bind_1text16)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ - jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0; + jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0; int const rc = sqlite3_bind_text16(PtrGet_sqlite3_stmt(jpStmt), (int)ndx, pBuf, (int)nMax, SQLITE_TRANSIENT); - s3jni_jbytearray_release(baData, pBuf); + s3jni_jbyteArray_release(baData, pBuf); return (jint)rc; } @@ -2812,7 +2814,7 @@ S3JniApi(sqlite3_compileoption_get(),jstring,1compileoption_1get)( S3JniApi(sqlite3_complete(),int,1complete)( JniArgsEnvClass, jbyteArray jSql ){ - jbyte * const pBuf = s3jni_jbytearray_bytes(jSql); + jbyte * const pBuf = s3jni_jbyteArray_bytes(jSql); const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jSql) : 0; int rc; @@ -2821,7 +2823,7 @@ S3JniApi(sqlite3_complete(),int,1complete)( rc = (pBuf && 0==pBuf[(nBa ? nBa-1 : 0)]) ? sqlite3_complete( (const char *)pBuf ) : (jSql ? SQLITE_NOMEM : SQLITE_ERROR); - s3jni_jbytearray_release(jSql, pBuf); + s3jni_jbyteArray_release(jSql, pBuf); return rc; } @@ -3556,7 +3558,7 @@ jint sqlite3_jni_prepare_v123( int prepVersion, JNIEnv * const env, jclass self, sqlite3_stmt * pStmt = 0; jobject jStmt = 0; const char * zTail = 0; - jbyte * const pBuf = s3jni_jbytearray_bytes(baSql); + jbyte * const pBuf = s3jni_jbyteArray_bytes(baSql); int rc = SQLITE_ERROR; assert(prepVersion==1 || prepVersion==2 || prepVersion==3); if( !pBuf ){ @@ -3583,7 +3585,7 @@ jint sqlite3_jni_prepare_v123( int prepVersion, JNIEnv * const env, jclass self, assert(0 && "Invalid prepare() version"); } end: - s3jni_jbytearray_release(baSql,pBuf); + s3jni_jbyteArray_release(baSql,pBuf); if( 0==rc ){ if( 0!=outTail ){ /* Noting that pBuf is deallocated now but its address is all we need for @@ -3885,6 +3887,18 @@ S3JniApi(sqlite3_progress_handler(),void,1progress_1handler)( S3JniDb_mutex_leave; } +S3JniApi(sqlite3_randomness(),void,1randomness)( + JniArgsEnvClass, jbyteArray jTgt +){ + jbyte * const jba = s3jni_jbyteArray_bytes(jTgt); + if( jba ){ + jsize const nTgt = (*env)->GetArrayLength(env, jTgt); + sqlite3_randomness( (int)nTgt, jba ); + s3jni_jbyteArray_commit(jTgt, jba); + } +} + + S3JniApi(sqlite3_reset(),jint,1reset)( JniArgsEnvClass, jobject jpStmt ){ @@ -3916,7 +3930,7 @@ static void result_blob_text(int as64 /* true for text64/blob64() mode */, jbyteArray jBa, jlong nMax){ int const asBlob = 0==eTextRep; if( jBa ){ - jbyte * const pBuf = s3jni_jbytearray_bytes(jBa); + jbyte * const pBuf = s3jni_jbyteArray_bytes(jBa); jsize nBa = (*env)->GetArrayLength(env, jBa); if( nMax>=0 && nBa>(jsize)nMax ){ nBa = (jsize)nMax; @@ -3980,7 +3994,7 @@ static void result_blob_text(int as64 /* true for text64/blob64() mode */, break; } } - s3jni_jbytearray_release(jBa, pBuf); + s3jni_jbyteArray_release(jBa, pBuf); } }else{ sqlite3_result_null(pCx); @@ -4010,7 +4024,7 @@ S3JniApi(sqlite3_result_error(),void,1result_1error)( ){ const char * zUnspecified = "Unspecified error."; jsize const baLen = (*env)->GetArrayLength(env, baMsg); - jbyte * const pjBuf = baMsg ? s3jni_jbytearray_bytes(baMsg) : NULL; + jbyte * const pjBuf = baMsg ? s3jni_jbyteArray_bytes(baMsg) : NULL; switch( pjBuf ? eTextRep : SQLITE_UTF8 ){ case SQLITE_UTF8: { const char *zMsg = pjBuf ? (const char *)pjBuf : zUnspecified; @@ -4029,7 +4043,7 @@ S3JniApi(sqlite3_result_error(),void,1result_1error)( "to sqlite3_result_error().", -1); break; } - s3jni_jbytearray_release(baMsg,pjBuf); + s3jni_jbyteArray_release(baMsg,pjBuf); } S3JniApi(sqlite3_result_error_code(),void,1result_1error_1code)( @@ -4303,8 +4317,8 @@ S3JniApi(sqlite3_status64(),jint,1status64)( static int s3jni_strlike_glob(int isLike, JNIEnv *const env, jbyteArray baG, jbyteArray baT, jint escLike){ int rc = 0; - jbyte * const pG = s3jni_jbytearray_bytes(baG); - jbyte * const pT = pG ? s3jni_jbytearray_bytes(baT) : 0; + jbyte * const pG = s3jni_jbyteArray_bytes(baG); + jbyte * const pT = pG ? s3jni_jbyteArray_bytes(baT) : 0; s3jni_oom_fatal(pT); /* Note that we're relying on the byte arrays having been @@ -4313,8 +4327,8 @@ static int s3jni_strlike_glob(int isLike, JNIEnv *const env, ? sqlite3_strlike((const char *)pG, (const char *)pT, (unsigned int)escLike) : sqlite3_strglob((const char *)pG, (const char *)pT); - s3jni_jbytearray_release(baG, pG); - s3jni_jbytearray_release(baT, pT); + s3jni_jbyteArray_release(baG, pG); + s3jni_jbyteArray_release(baT, pT); return rc; } @@ -5229,7 +5243,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef, S3JniEnv * const jc = S3JniEnv_get(); struct s3jni_xQueryPhraseState s; int rc = 0; - jbyte * const pText = jCallback ? s3jni_jbytearray_bytes(jbaText) : 0; + jbyte * const pText = jCallback ? s3jni_jbyteArray_bytes(jbaText) : 0; jsize nText = pText ? (*env)->GetArrayLength(env, jbaText) : 0; jclass const klazz = jCallback ? (*env)->GetObjectClass(env, jCallback) : NULL; @@ -5244,7 +5258,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef, S3JniIfThrew { S3JniExceptionReport; S3JniExceptionClear; - s3jni_jbytearray_release(jbaText, pText); + s3jni_jbyteArray_release(jbaText, pText); return SQLITE_ERROR; } s.tok.jba = S3JniRefLocal(jbaText); @@ -5266,7 +5280,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef, assert( s.tok.zPrev ); S3JniUnrefLocal(s.tok.jba); } - s3jni_jbytearray_release(jbaText, pText); + s3jni_jbyteArray_release(jbaText, pText); return (jint)rc; } @@ -5465,15 +5479,15 @@ Java_org_sqlite_jni_tester_SQLTester_strglob( JniArgsEnvClass, jbyteArray baG, jbyteArray baT ){ int rc = 0; - jbyte * const pG = s3jni_jbytearray_bytes(baG); - jbyte * const pT = pG ? s3jni_jbytearray_bytes(baT) : 0; + jbyte * const pG = s3jni_jbyteArray_bytes(baG); + jbyte * const pT = pG ? s3jni_jbyteArray_bytes(baT) : 0; s3jni_oom_fatal(pT); /* Note that we're relying on the byte arrays having been NUL-terminated on the Java side. */ rc = !SQLTester_strnotglob((const char *)pG, (const char *)pT); - s3jni_jbytearray_release(baG, pG); - s3jni_jbytearray_release(baT, pT); + s3jni_jbyteArray_release(baG, pG); + s3jni_jbyteArray_release(baT, pT); return rc; } diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 6beb1e3f0b..0eef966bbd 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1531,6 +1531,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1preupdate_1old JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1progress_1handler (JNIEnv *, jclass, jobject, jint, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_randomness + * Signature: ([B)V + */ +JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1randomness + (JNIEnv *, jclass, jbyteArray); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_release_memory diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 7c956ebb6c..5bf5e3b08c 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1040,6 +1040,9 @@ public final class SQLite3Jni { @NotNull sqlite3 db, int n, @Nullable ProgressHandlerCallback h ); + @Canonical + public static native void sqlite3_randomness(byte[] target); + @Canonical public static native int sqlite3_release_memory(int n); diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index a4756e6760..83dd9c80bc 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1522,6 +1522,20 @@ public class Tester1 implements Runnable { sqlite3_close_v2(db2); } + private void testRandomness(){ + byte[] foo = new byte[20]; + int i = 0; + for( byte b : foo ){ + i += b; + } + affirm( i==0 ); + sqlite3_randomness(foo); + for( byte b : foo ){ + if(b!=0) ++i; + } + affirm( i!=0, "There's a very slight chance that 0 is actually correct." ); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); diff --git a/manifest b/manifest index 0e68031bef..fafe86ce17 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_get/set_auxdata()\sto\sJNI. -D 2023-09-03T11:58:33.070 +C Expose\ssqlite3_randomness()\sto\sJNI. +D 2023-09-03T12:17:34.015 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 649b305d2281d350067b63b1d077410a38ae9a06366634ee5e22131ba070c1ef -F ext/jni/src/c/sqlite3-jni.h c95632356c61ccc5975c41bf35e5bc79d24fd1e8375d068731ea0b2f625b51f7 +F ext/jni/src/c/sqlite3-jni.c 0f10efb673d94b2a4b0b76e42cc8951341df6197d8454f08b6db25b1554242c5 +F ext/jni/src/c/sqlite3-jni.h c3d1fa02f34bd5d2d71c9172be7732e59624cbc3639419ae3929512c18e102dc F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e84f456b5f1636f45c50f1d532247631a1569c99a3a504d04c9ed4f4ed3fbf02 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 8ed33203f0958c32571112164d79edd22b00bb0de4c0f5108e1a5ebf2534ce20 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 0c37badac93c948d340688967fa205062fa70d6fd1c72730b5ececc1419319cd +F ext/jni/src/org/sqlite/jni/Tester1.java caf32da9a15a1202bdb801a036c233864bf676569143057f83d70b5ba2f44ae5 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2117,8 +2117,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 67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9 -R 85fc08c8b7dbbee0a10820fd8df0b1f2 +P 0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed +R 1c9493f53aa49acbc7601207cf3c352b U stephan -Z d25cca227f7f4f43edfdc564cc64fc9b +Z a919ad1706be2f43ac4c9258eceb6670 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9d8e468fc9..8f07363627 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed \ No newline at end of file +de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf \ No newline at end of file From 286f30f85c80596ec4d346b19431423793d583f3 Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 12:32:09 +0000 Subject: [PATCH 25/36] Expose sqlite3_stmt_status() to JNI. FossilOrigin-Name: d266acc23ecb7e76c8c68c6e89a76e6f3054f33f0262e60e06b258db5a5e2ccd --- ext/jni/src/c/sqlite3-jni.c | 8 ++++++++ ext/jni/src/c/sqlite3-jni.h | 8 ++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 5 +++++ ext/jni/src/org/sqlite/jni/Tester1.java | 3 ++- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 67c90f6e89..c2fe9f8b8d 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -4314,6 +4314,14 @@ S3JniApi(sqlite3_status64(),jint,1status64)( return (jint)rc; } +S3JniApi(sqlite3_stmt_status(),jint,1stmt_1status)( + JniArgsEnvClass, jobject jStmt, jint op, jboolean reset +){ + return sqlite3_stmt_status(PtrGet_sqlite3_stmt(jStmt), + (int)op, reset ? 1 : 0); +} + + static int s3jni_strlike_glob(int isLike, JNIEnv *const env, jbyteArray baG, jbyteArray baT, jint escLike){ int rc = 0; diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 0eef966bbd..9b01f04702 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1803,6 +1803,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1isexplain JNIEXPORT jboolean JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1readonly (JNIEnv *, jclass, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_stmt_status + * Signature: (Lorg/sqlite/jni/sqlite3_stmt;IZ)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1stmt_1status + (JNIEnv *, jclass, jobject, jint, jboolean); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_strglob diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 5bf5e3b08c..41cf4988e1 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1431,6 +1431,11 @@ public final class SQLite3Jni { @Canonical public static native boolean sqlite3_stmt_readonly(@NotNull sqlite3_stmt stmt); + @Canonical + public static native int sqlite3_stmt_status( + @NotNull sqlite3_stmt stmt, int op, boolean reset + ); + /** Internal impl of the public sqlite3_strglob() method. Neither argument may be null and both must be NUL-terminated UTF-8. diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 83dd9c80bc..d5db8170c7 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -800,7 +800,7 @@ public class Tester1 implements Runnable { int rc = sqlite3_create_function(db, "myfunc", 1, SQLITE_UTF8, func); affirm(0 == rc); sqlite3_stmt stmt = prepare(db, "select myfunc(a), myfunc(a+10) from t"); - affirm( null != stmt ); + affirm( 0==sqlite3_stmt_status(stmt, SQLITE_STMTSTATUS_RUN, false) ); int n = 0; if( SQLITE_ROW == sqlite3_step(stmt) ){ int v = sqlite3_column_int(stmt, 0); @@ -812,6 +812,7 @@ public class Tester1 implements Runnable { affirm( 1==n ); affirm(!xFinalNull.value); sqlite3_reset(stmt); + affirm( 1==sqlite3_stmt_status(stmt, SQLITE_STMTSTATUS_RUN, false) ); // Ensure that the accumulator is reset on subsequent calls... n = 0; if( SQLITE_ROW == sqlite3_step(stmt) ){ diff --git a/manifest b/manifest index fafe86ce17..3877b0be95 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_randomness()\sto\sJNI. -D 2023-09-03T12:17:34.015 +C Expose\ssqlite3_stmt_status()\sto\sJNI. +D 2023-09-03T12:32:09.643 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 0f10efb673d94b2a4b0b76e42cc8951341df6197d8454f08b6db25b1554242c5 -F ext/jni/src/c/sqlite3-jni.h c3d1fa02f34bd5d2d71c9172be7732e59624cbc3639419ae3929512c18e102dc +F ext/jni/src/c/sqlite3-jni.c a9ad3d9d960724eeeb7e93bcef7aa12289e68296f30dd2d77d02f299cac99721 +F ext/jni/src/c/sqlite3-jni.h 473c4b35d9f5ea9d79ac1b3b0ea00cc78e8e0385d87a4cb6d8ae8f0bcde2351c F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 8ed33203f0958c32571112164d79edd22b00bb0de4c0f5108e1a5ebf2534ce20 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 85e48806781b6c0ebb7f262444b00df2933d6e197181623c7a930c0efb0e1a8b F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java caf32da9a15a1202bdb801a036c233864bf676569143057f83d70b5ba2f44ae5 +F ext/jni/src/org/sqlite/jni/Tester1.java 14b3a129755a1a19271bdab9de6f4c58898aa28dfe3c03e7f0d23728254dc0d3 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -2117,8 +2117,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 0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed -R 1c9493f53aa49acbc7601207cf3c352b +P de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf +R ebcdf0ddc07ec0bc930ef3346f428207 U stephan -Z a919ad1706be2f43ac4c9258eceb6670 +Z 84012132b5e2bcd623d210f7c0541b51 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8f07363627..6d6fa4a985 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf \ No newline at end of file +d266acc23ecb7e76c8c68c6e89a76e6f3054f33f0262e60e06b258db5a5e2ccd \ No newline at end of file From 7dfacc9f96e388c5d88677e51e4ecc1c5e5aa66e Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 12:46:09 +0000 Subject: [PATCH 26/36] Expose sqlite3_system_errno() to JNI. FossilOrigin-Name: bac54da29c19ef5e0a76599b5d10b377ecd7b391a651af99526529df16a83c7d --- ext/jni/src/c/sqlite3-jni.c | 3 ++- ext/jni/src/c/sqlite3-jni.h | 8 ++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 3 +++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index c2fe9f8b8d..8773a7ed7d 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -1426,7 +1426,7 @@ static void * NativePointerHolder__get(JNIEnv * env, jobject jNph, ** argument is a Java sqlite3 object, as this operation only has void ** pointers to work with. */ -#define PtrGet_T(T,OBJ) NativePointerHolder_get(OBJ, S3JniNph(T)) +#define PtrGet_T(T,OBJ) (T*)NativePointerHolder_get(OBJ, S3JniNph(T)) #define PtrGet_sqlite3(OBJ) PtrGet_T(sqlite3, OBJ) #define PtrGet_sqlite3_backup(OBJ) PtrGet_T(sqlite3_backup, OBJ) #define PtrGet_sqlite3_context(OBJ) PtrGet_T(sqlite3_context, OBJ) @@ -2087,6 +2087,7 @@ WRAP_MUTF8_VOID(1sourceid, sqlite3_sourceid) WRAP_INT_STMT_INT(1stmt_1explain, sqlite3_stmt_explain) WRAP_INT_STMT(1stmt_1isexplain, sqlite3_stmt_isexplain) WRAP_BOOL_STMT(1stmt_1readonly, sqlite3_stmt_readonly) +WRAP_INT_DB(1system_1errno, sqlite3_system_errno) WRAP_INT_VOID(1threadsafe, sqlite3_threadsafe) WRAP_INT_DB(1total_1changes, sqlite3_total_changes) WRAP_INT64_DB(1total_1changes64, sqlite3_total_changes64) diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 9b01f04702..d000b0a465 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -1827,6 +1827,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strglob JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strlike (JNIEnv *, jclass, jbyteArray, jbyteArray, jint); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_system_errno + * Signature: (Lorg/sqlite/jni/sqlite3;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1system_1errno + (JNIEnv *, jclass, jobject); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_table_column_metadata diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 41cf4988e1..9222c2ad72 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -1482,6 +1482,9 @@ public final class SQLite3Jni { ); } + @Canonical + public static native int sqlite3_system_errno(@NotNull sqlite3 db); + @Canonical public static native int sqlite3_table_column_metadata( @NotNull sqlite3 db, @NotNull String zDbName, diff --git a/manifest b/manifest index 3877b0be95..294ff683d3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_stmt_status()\sto\sJNI. -D 2023-09-03T12:32:09.643 +C Expose\ssqlite3_system_errno()\sto\sJNI. +D 2023-09-03T12:46:09.429 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c a9ad3d9d960724eeeb7e93bcef7aa12289e68296f30dd2d77d02f299cac99721 -F ext/jni/src/c/sqlite3-jni.h 473c4b35d9f5ea9d79ac1b3b0ea00cc78e8e0385d87a4cb6d8ae8f0bcde2351c +F ext/jni/src/c/sqlite3-jni.c 0ae08bc58a1304eaceb3d16bf3c799b717662ab59e66b8ca218a2041f4fc42f4 +F ext/jni/src/c/sqlite3-jni.h 2db486abbdd424a0197797908ea46e455b37876c41266a9630885e1469a897e8 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,7 +262,7 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 85e48806781b6c0ebb7f262444b00df2933d6e197181623c7a930c0efb0e1a8b +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java bc5f5c2affa2126379696fc5e367b0fa02436166c8bd9f966a99559733acf1a9 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab F ext/jni/src/org/sqlite/jni/Tester1.java 14b3a129755a1a19271bdab9de6f4c58898aa28dfe3c03e7f0d23728254dc0d3 @@ -2117,8 +2117,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 de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf -R ebcdf0ddc07ec0bc930ef3346f428207 +P d266acc23ecb7e76c8c68c6e89a76e6f3054f33f0262e60e06b258db5a5e2ccd +R 0f337c85b77ffdd11d583dfb2c7a7040 U stephan -Z 84012132b5e2bcd623d210f7c0541b51 +Z 2f1ca87d5a540c0a7a17c3d282e87afc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6d6fa4a985..d19f34cf7c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d266acc23ecb7e76c8c68c6e89a76e6f3054f33f0262e60e06b258db5a5e2ccd \ No newline at end of file +bac54da29c19ef5e0a76599b5d10b377ecd7b391a651af99526529df16a83c7d \ No newline at end of file From 805e8c96b91fb53fc978d5382d51aa993815a78d Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 14:13:29 +0000 Subject: [PATCH 27/36] Expose the sqlite3_blob_...() APIs to JNI. FossilOrigin-Name: 9a9945c405cfe9b6bf399655f498457da66b06c8b92014510ab9fb83fbb1c7d4 --- ext/jni/src/c/sqlite3-jni.c | 132 +++++++++++++++--- ext/jni/src/c/sqlite3-jni.h | 40 ++++++ ext/jni/src/org/sqlite/jni/OutputPointer.java | 21 +++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 46 ++++++ ext/jni/src/org/sqlite/jni/Tester1.java | 27 ++++ ext/jni/src/org/sqlite/jni/sqlite3_blob.java | 25 ++++ manifest | 21 +-- manifest.uuid | 2 +- 8 files changed, 281 insertions(+), 33 deletions(-) create mode 100644 ext/jni/src/org/sqlite/jni/sqlite3_blob.java diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 8773a7ed7d..720de5c56f 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -336,6 +336,7 @@ struct S3JniNphOp { static const struct { const S3JniNphOp sqlite3; const S3JniNphOp sqlite3_backup; + const S3JniNphOp sqlite3_blob; const S3JniNphOp sqlite3_context; const S3JniNphOp sqlite3_stmt; const S3JniNphOp sqlite3_value; @@ -343,6 +344,7 @@ static const struct { const S3JniNphOp OutputPointer_Int32; const S3JniNphOp OutputPointer_Int64; const S3JniNphOp OutputPointer_sqlite3; + const S3JniNphOp OutputPointer_sqlite3_blob; const S3JniNphOp OutputPointer_sqlite3_stmt; const S3JniNphOp OutputPointer_sqlite3_value; const S3JniNphOp OutputPointer_String; @@ -363,26 +365,29 @@ static const struct { #define RefO(INDEX, KLAZZ, SIG) MkRef(INDEX, KLAZZ, "value", SIG) RefN(0, "sqlite3"), RefN(1, "sqlite3_backup"), - RefN(2, "sqlite3_context"), - RefN(3, "sqlite3_stmt"), - RefN(4, "sqlite3_value"), - RefO(5, "OutputPointer$Bool", "Z"), - RefO(6, "OutputPointer$Int32", "I"), - RefO(7, "OutputPointer$Int64", "J"), - RefO(8, "OutputPointer$sqlite3", + RefN(2, "sqlite3_blob"), + RefN(3, "sqlite3_context"), + RefN(4, "sqlite3_stmt"), + RefN(5, "sqlite3_value"), + RefO(6, "OutputPointer$Bool", "Z"), + RefO(7, "OutputPointer$Int32", "I"), + RefO(8, "OutputPointer$Int64", "J"), + RefO(9, "OutputPointer$sqlite3", "Lorg/sqlite/jni/sqlite3;"), - RefO(9, "OutputPointer$sqlite3_stmt", + RefO(10, "OutputPointer$sqlite3_blob", + "Lorg/sqlite/jni/sqlite3_blob;"), + RefO(11, "OutputPointer$sqlite3_stmt", "Lorg/sqlite/jni/sqlite3_stmt;"), - RefO(10, "OutputPointer$sqlite3_value", + RefO(12, "OutputPointer$sqlite3_value", "Lorg/sqlite/jni/sqlite3_value;"), - RefO(11, "OutputPointer$String", "Ljava/lang/String;"), + RefO(13, "OutputPointer$String", "Ljava/lang/String;"), #ifdef SQLITE_ENABLE_FTS5 - RefO(12, "OutputPointer$ByteArray", "[B"), - RefN(13, "Fts5Context"), - RefN(14, "Fts5ExtensionApi"), - RefN(15, "fts5_api"), - RefN(16, "fts5_tokenizer"), - RefN(17, "Fts5Tokenizer") + RefO(14, "OutputPointer$ByteArray", "[B"), + RefN(15, "Fts5Context"), + RefN(16, "Fts5ExtensionApi"), + RefN(17, "fts5_api"), + RefN(18, "fts5_tokenizer"), + RefN(19, "Fts5Tokenizer") #endif #undef MkRef #undef RefN @@ -1429,6 +1434,7 @@ static void * NativePointerHolder__get(JNIEnv * env, jobject jNph, #define PtrGet_T(T,OBJ) (T*)NativePointerHolder_get(OBJ, S3JniNph(T)) #define PtrGet_sqlite3(OBJ) PtrGet_T(sqlite3, OBJ) #define PtrGet_sqlite3_backup(OBJ) PtrGet_T(sqlite3_backup, OBJ) +#define PtrGet_sqlite3_blob(OBJ) PtrGet_T(sqlite3_blob, OBJ) #define PtrGet_sqlite3_context(OBJ) PtrGet_T(sqlite3_context, OBJ) #define PtrGet_sqlite3_stmt(OBJ) PtrGet_T(sqlite3_stmt, OBJ) #define PtrGet_sqlite3_value(OBJ) PtrGet_T(sqlite3_value, OBJ) @@ -1591,8 +1597,17 @@ static void OutputPointer_set_obj(JNIEnv * const env, ** v. */ static void OutputPointer_set_sqlite3(JNIEnv * const env, jobject const jOut, - jobject jDb){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3), jOut, jDb); + jobject v){ + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3), jOut, v); +} + +/* +** Sets the value property of the OutputPointer.sqlite3_blob jOut object to +** v. +*/ +static void OutputPointer_set_sqlite3_blob(JNIEnv * const env, jobject const jOut, + jobject v){ + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_blob), jOut, v); } /* @@ -1600,8 +1615,8 @@ static void OutputPointer_set_sqlite3(JNIEnv * const env, jobject const jOut, ** v. */ static void OutputPointer_set_sqlite3_stmt(JNIEnv * const env, jobject const jOut, - jobject jStmt){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_stmt), jOut, jStmt); + jobject v){ + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_stmt), jOut, v); } #ifdef SQLITE_ENABLE_PREUPDATE_HOOK @@ -1610,8 +1625,8 @@ static void OutputPointer_set_sqlite3_stmt(JNIEnv * const env, jobject const jOu ** v. */ static void OutputPointer_set_sqlite3_value(JNIEnv * const env, jobject const jOut, - jobject jValue){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), jOut, jValue); + jobject v){ + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), jOut, v); } #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ @@ -1704,6 +1719,9 @@ static inline jobject new_java_sqlite3(JNIEnv * const env, sqlite3 *sv){ static inline jobject new_java_sqlite3_backup(JNIEnv * const env, sqlite3_backup *sv){ return NativePointerHolder_new(env, S3JniNph(sqlite3_backup), sv); } +static inline jobject new_java_sqlite3_blob(JNIEnv * const env, sqlite3_blob *sv){ + return NativePointerHolder_new(env, S3JniNph(sqlite3_blob), sv); +} static inline jobject new_java_sqlite3_context(JNIEnv * const env, sqlite3_context *sv){ return NativePointerHolder_new(env, S3JniNph(sqlite3_context), sv); } @@ -2416,6 +2434,76 @@ S3JniApi(sqlite3_bind_zeroblob(),jint,1bind_1zeroblob64)( return (jint)sqlite3_bind_zeroblob(PtrGet_sqlite3_stmt(jpStmt), (int)ndx, (sqlite3_uint64)n); } +S3JniApi(sqlite3_blob_bytes(),jint,1blob_1bytes)( + JniArgsEnvClass, jobject jBlob +){ + return sqlite3_blob_bytes(PtrGet_sqlite3_blob(jBlob)); +} + +S3JniApi(sqlite3_blob_close(),jint,1blob_1close)( + JniArgsEnvClass, jobject jBlob +){ + sqlite3_blob * const b = PtrGet_sqlite3_blob(jBlob); + jint const rc = b ? (jint)sqlite3_blob_close(b) : SQLITE_MISUSE; + if( b ){ + NativePointerHolder_set(S3JniNph(sqlite3_blob), jBlob, 0); + } + return rc; +} + +S3JniApi(sqlite3_blob_open(),jint,1blob_1open)( + JniArgsEnvClass, jobject jDb, jstring jDbName, jstring jTbl, jstring jCol, + jlong jRowId, jint flags, jobject jOut +){ + sqlite3 * const db = PtrGet_sqlite3(jDb); + sqlite3_blob * pBlob = 0; + char * zDbName = 0, * zTableName = 0, * zColumnName = 0; + int rc; + + if( !db || !jDbName || !jTbl || !jCol ) return SQLITE_MISUSE; + zDbName = s3jni_jstring_to_utf8(jDbName,0); + zTableName = zDbName ? s3jni_jstring_to_utf8(jTbl,0) : 0; + zColumnName = zTableName ? s3jni_jstring_to_utf8(jCol,0) : 0; + rc = zColumnName + ? sqlite3_blob_open(db, zDbName, zTableName, zColumnName, + (sqlite3_int64)jRowId, (int)flags, &pBlob) + : SQLITE_NOMEM; + if( 0==rc ){ + jobject rv = new_java_sqlite3_blob(env, pBlob); + if( rv ){ + OutputPointer_set_sqlite3_blob(env, jOut, rv); + }else{ + sqlite3_blob_close(pBlob); + rc = SQLITE_NOMEM; + } + } + sqlite3_free(zDbName); + sqlite3_free(zTableName); + sqlite3_free(zColumnName); + return rc; +} + +S3JniApi(sqlite3_blob_reopen(),jint,1blob_1reopen)( + JniArgsEnvClass, jobject jBlob, jlong iNewRowId +){ + return (jint)sqlite3_blob_reopen(PtrGet_sqlite3_blob(jBlob), + (sqlite3_int64)iNewRowId); +} + +S3JniApi(sqlite3_blob_write(),jint,1blob_1write)( + JniArgsEnvClass, jobject jBlob, jbyteArray jBa, jint iOffset +){ + sqlite3_blob * const b = PtrGet_sqlite3_blob(jBlob); + jbyte * const pBuf = b ? s3jni_jbyteArray_bytes(jBa) : 0; + const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jBa) : 0; + int rc = SQLITE_MISUSE; + if(b && pBuf){ + rc = sqlite3_blob_write( b, pBuf, nBa, (int)iOffset ); + } + s3jni_jbyteArray_release(jBa, pBuf); + return (jint)rc; +} + /* Central C-to-Java busy handler proxy. */ static int s3jni_busy_handler(void* pState, int n){ S3JniDb * const ps = (S3JniDb *)pState; diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index d000b0a465..91d512205f 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -947,6 +947,46 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1bind_1zeroblob JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1bind_1zeroblob64 (JNIEnv *, jclass, jobject, jint, jlong); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_bytes + * Signature: (Lorg/sqlite/jni/sqlite3_blob;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1bytes + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_close + * Signature: (Lorg/sqlite/jni/sqlite3_blob;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1close + (JNIEnv *, jclass, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_open + * Signature: (Lorg/sqlite/jni/sqlite3;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JILorg/sqlite/jni/OutputPointer/sqlite3_blob;)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1open + (JNIEnv *, jclass, jobject, jstring, jstring, jstring, jlong, jint, jobject); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_reopen + * Signature: (Lorg/sqlite/jni/sqlite3_blob;J)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1reopen + (JNIEnv *, jclass, jobject, jlong); + +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_write + * Signature: (Lorg/sqlite/jni/sqlite3_blob;[BI)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1write + (JNIEnv *, jclass, jobject, jbyteArray, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_busy_handler diff --git a/ext/jni/src/org/sqlite/jni/OutputPointer.java b/ext/jni/src/org/sqlite/jni/OutputPointer.java index f27d977744..c6e48ed72f 100644 --- a/ext/jni/src/org/sqlite/jni/OutputPointer.java +++ b/ext/jni/src/org/sqlite/jni/OutputPointer.java @@ -64,6 +64,27 @@ public final class OutputPointer { } } + /** + Output pointer for sqlite3_blob_open(). These + pointers can only be set by the JNI layer, not by client-level + code. + */ + public static final class sqlite3_blob { + private org.sqlite.jni.sqlite3_blob value; + /** Initializes with a null value. */ + public sqlite3_blob(){value = null;} + /** Sets the current value to null. */ + public void clear(){value = null;} + /** Returns the current value. */ + public final org.sqlite.jni.sqlite3_blob get(){return value;} + /** Equivalent to calling get() then clear(). */ + public final org.sqlite.jni.sqlite3_blob take(){ + final org.sqlite.jni.sqlite3_blob v = value; + value = null; + return v; + } + } + /** Output pointer for use with routines, such as sqlite3_prepare(), which return a statement handle via an output pointer. These diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 9222c2ad72..407b5dfbd6 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -342,6 +342,42 @@ public final class SQLite3Jni { @NotNull sqlite3_stmt stmt, int ndx, long n ); + @Canonical + public static native int sqlite3_blob_bytes(@NotNull sqlite3_blob blob); + + @Canonical + public static native int sqlite3_blob_close(@Nullable sqlite3_blob blob); + + @Canonical + public static native int sqlite3_blob_open( + @NotNull sqlite3 db, @NotNull String dbName, + @NotNull String tableName, @NotNull String columnName, + long iRow, int flags, @NotNull OutputPointer.sqlite3_blob out + ); + + /** + Convenience overload. + */ + public static sqlite3_blob sqlite3_blob_open( + @NotNull sqlite3 db, @NotNull String dbName, + @NotNull String tableName, @NotNull String columnName, + long iRow, int flags ){ + final OutputPointer.sqlite3_blob out = new OutputPointer.sqlite3_blob(); + sqlite3_blob_open(db, dbName, tableName, columnName, iRow, flags, out); + return out.take(); + }; + + @Canonical + public static native int sqlite3_blob_reopen( + @NotNull sqlite3_blob out, long newRowId + ); + + @Canonical + public static native int sqlite3_blob_write( + @NotNull sqlite3_blob out, @NotNull byte[] bytes, + int iOffset + ); + /** As for the C-level function of the same name, with a BusyHandlerCallback instance in place of a callback @@ -1557,6 +1593,16 @@ public final class SQLite3Jni { @NotNull sqlite3 db, @Nullable UpdateHookCallback hook ); + /* + Note that: + + void * sqlite3_user_data(sqlite3_context*) + + Is not relevant in the JNI binding, as its feature is replaced by + the ability to pass an object, including any relevant state, to + sqlite3_create_function(). + */ + @Canonical public static native byte[] sqlite3_value_blob(@NotNull sqlite3_value v); diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index d5db8170c7..409418bf60 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1537,6 +1537,33 @@ public class Tester1 implements Runnable { affirm( i!=0, "There's a very slight chance that 0 is actually correct." ); } + private void testBlobOpen(){ + final sqlite3 db = createNewDb(); + + execSql(db, "CREATE TABLE T(a BLOB);" + +"INSERT INTO t(a) VALUES(cast('DEF' as text));"); + final OutputPointer.sqlite3_blob pOut = new OutputPointer.sqlite3_blob(); + int rc = sqlite3_blob_open(db, "main", "t", "a", + sqlite3_last_insert_rowid(db), 1, pOut); + affirm( 0==rc ); + final sqlite3_blob b = pOut.take(); + affirm( null!=b ); + affirm( 0!=b.getNativePointer() ); + affirm( 3==sqlite3_blob_bytes(b) ); + rc = sqlite3_blob_write( b, new byte[] {100, 101, 102}, 0); + affirm( 0==rc ); + rc = sqlite3_blob_close(b); + affirm( 0==rc ); + affirm( 0==b.getNativePointer() ); + sqlite3_stmt stmt = prepare(db,"SELECT length(a), a FROM t"); + affirm( SQLITE_ROW == sqlite3_step(stmt) ); + affirm( 3 == sqlite3_column_int(stmt,0) ); + affirm( "def".equals(sqlite3_column_text16(stmt,1)) ); + + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + } + /* Copy/paste/rename this to add new tests. */ private void _testTemplate(){ final sqlite3 db = createNewDb(); diff --git a/ext/jni/src/org/sqlite/jni/sqlite3_blob.java b/ext/jni/src/org/sqlite/jni/sqlite3_blob.java new file mode 100644 index 0000000000..e512130256 --- /dev/null +++ b/ext/jni/src/org/sqlite/jni/sqlite3_blob.java @@ -0,0 +1,25 @@ +/* +** 2023-09-03 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file is part of the JNI bindings for the sqlite3 C API. +*/ +package org.sqlite.jni; + +/** + A wrapper for passing C-level (sqlite3_blob*) instances around in + Java. These wrappers do not own their associated pointer, they + simply provide a type-safe way to communicate it between Java and C + via JNI. +*/ +public final class sqlite3_blob extends NativePointerHolder { + // Only invoked from JNI. + private sqlite3_blob(){} +} diff --git a/manifest b/manifest index 294ff683d3..daa9e58d18 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_system_errno()\sto\sJNI. -D 2023-09-03T12:46:09.429 +C Expose\sthe\ssqlite3_blob_...()\sAPIs\sto\sJNI. +D 2023-09-03T14:13:29.255 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 0ae08bc58a1304eaceb3d16bf3c799b717662ab59e66b8ca218a2041f4fc42f4 -F ext/jni/src/c/sqlite3-jni.h 2db486abbdd424a0197797908ea46e455b37876c41266a9630885e1469a897e8 +F ext/jni/src/c/sqlite3-jni.c 2a5a3f6637d34c3d8e8d60eac00b8ca231b0e97ce170d44c60a3afd040301104 +F ext/jni/src/c/sqlite3-jni.h 273e2ab8652d438e98bc891c8a80dcb4f9de82675124f0b090927532d8c5d212 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -256,16 +256,16 @@ F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 6ac342951c5805b48ba1e46dd41df F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d -F ext/jni/src/org/sqlite/jni/OutputPointer.java 1f2319976fff206f5056eafc8a4f48d43abe09d5d1b5287ba9145a95d847cbb7 +F ext/jni/src/org/sqlite/jni/OutputPointer.java 2f57c05672ddc9b38e3f8eed11759896cf0bf01107ffd24d5182b99f6e7254b6 F ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java eccaed8dc9c6289f07ef3fc109891c6be1e7cc6c88723d90174b68706fc21cda F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c57eeedcd8447e9e3b6e5d0f5e5d3eb0f0c5037d48d F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java bc5f5c2affa2126379696fc5e367b0fa02436166c8bd9f966a99559733acf1a9 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5b8890dcee68dda59c737a2e5acf34ae251b088daa1159f0a5cd78a087439239 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 14b3a129755a1a19271bdab9de6f4c58898aa28dfe3c03e7f0d23728254dc0d3 +F ext/jni/src/org/sqlite/jni/Tester1.java 1f38d134b732f0122ff7eace6945fa7093afe264fc158eebf66d193cba6ed294 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -282,6 +282,7 @@ F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369b F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_backup.java d0bb06dd6225e76999ff6b7ab20f2643b1c4d4167431b3a93ea41943e41f094b +F ext/jni/src/org/sqlite/jni/sqlite3_blob.java f28a30134f2e524eb7d5ab87f57f86c90140341a6e8369ee54509ac8bb96fa82 F ext/jni/src/org/sqlite/jni/sqlite3_context.java 66ca95ce904044263a4aff684abe262d56f73e6b06bca6cf650761d79d7779ad F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a @@ -2117,8 +2118,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 d266acc23ecb7e76c8c68c6e89a76e6f3054f33f0262e60e06b258db5a5e2ccd -R 0f337c85b77ffdd11d583dfb2c7a7040 +P bac54da29c19ef5e0a76599b5d10b377ecd7b391a651af99526529df16a83c7d +R 282c1de5bd907fe2a4768bc91d128cea U stephan -Z 2f1ca87d5a540c0a7a17c3d282e87afc +Z eef925f2110921290c9a3b0a29c51189 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d19f34cf7c..f88732c20e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -bac54da29c19ef5e0a76599b5d10b377ecd7b391a651af99526529df16a83c7d \ No newline at end of file +9a9945c405cfe9b6bf399655f498457da66b06c8b92014510ab9fb83fbb1c7d4 \ No newline at end of file From 14412e952678d505ca27a8f89ae4bb85503e398e Mon Sep 17 00:00:00 2001 From: stephan Date: Sun, 3 Sep 2023 14:41:13 +0000 Subject: [PATCH 28/36] Add the missing sqlite3_blob_read() to [9a9945c405cf]. Elaborate on the definition of the @NotNull annotation. FossilOrigin-Name: 85952b4a52a09e9da35754c1a1ec70b1bf277296011a2d37ac536b33437223d7 --- ext/jni/src/c/sqlite3-jni.c | 18 ++++++++++++++ ext/jni/src/c/sqlite3-jni.h | 8 +++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 8 +++++-- ext/jni/src/org/sqlite/jni/Tester1.java | 24 +++++++++++++++---- .../org/sqlite/jni/annotation/NotNull.java | 9 ++++--- manifest | 20 ++++++++-------- manifest.uuid | 2 +- 7 files changed, 68 insertions(+), 21 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 720de5c56f..f7e614f4d2 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2483,6 +2483,24 @@ S3JniApi(sqlite3_blob_open(),jint,1blob_1open)( return rc; } +S3JniApi(sqlite3_blob_read(),jint,1blob_1read)( + JniArgsEnvClass, jobject jBlob, jbyteArray jTgt, jint iOffset +){ + jbyte * const pBa = s3jni_jbyteArray_bytes(jTgt); + int rc = jTgt ? (pBa ? SQLITE_MISUSE : SQLITE_NOMEM) : SQLITE_MISUSE; + if( pBa ){ + jsize const nTgt = (*env)->GetArrayLength(env, jTgt); + rc = sqlite3_blob_read(PtrGet_sqlite3_blob(jBlob), pBa, + (int)nTgt, (int)iOffset); + if( 0==rc ){ + s3jni_jbyteArray_commit(jTgt, pBa); + }else{ + s3jni_jbyteArray_release(jTgt, pBa); + } + } + return rc; +} + S3JniApi(sqlite3_blob_reopen(),jint,1blob_1reopen)( JniArgsEnvClass, jobject jBlob, jlong iNewRowId ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 91d512205f..08de9ab8a6 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -971,6 +971,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1close JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1open (JNIEnv *, jclass, jobject, jstring, jstring, jstring, jlong, jint, jobject); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_blob_read + * Signature: (Lorg/sqlite/jni/sqlite3_blob;[BI)I + */ +JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1blob_1read + (JNIEnv *, jclass, jobject, jbyteArray, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_blob_reopen diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 407b5dfbd6..26b027160a 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -367,6 +367,11 @@ public final class SQLite3Jni { return out.take(); }; + @Canonical + public static native int sqlite3_blob_read( + @NotNull sqlite3_blob b, @NotNull byte[] target, int iOffset + ); + @Canonical public static native int sqlite3_blob_reopen( @NotNull sqlite3_blob out, long newRowId @@ -374,8 +379,7 @@ public final class SQLite3Jni { @Canonical public static native int sqlite3_blob_write( - @NotNull sqlite3_blob out, @NotNull byte[] bytes, - int iOffset + @NotNull sqlite3_blob out, @NotNull byte[] bytes, int iOffset ); /** diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 409418bf60..2987c1b85a 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1541,26 +1541,40 @@ public class Tester1 implements Runnable { final sqlite3 db = createNewDb(); execSql(db, "CREATE TABLE T(a BLOB);" - +"INSERT INTO t(a) VALUES(cast('DEF' as text));"); + +"INSERT INTO t(rowid,a) VALUES(1, 'def'),(2, 'XYZ');" + ); final OutputPointer.sqlite3_blob pOut = new OutputPointer.sqlite3_blob(); int rc = sqlite3_blob_open(db, "main", "t", "a", sqlite3_last_insert_rowid(db), 1, pOut); affirm( 0==rc ); - final sqlite3_blob b = pOut.take(); + sqlite3_blob b = pOut.take(); affirm( null!=b ); affirm( 0!=b.getNativePointer() ); affirm( 3==sqlite3_blob_bytes(b) ); - rc = sqlite3_blob_write( b, new byte[] {100, 101, 102}, 0); + rc = sqlite3_blob_write( b, new byte[] {100, 101, 102 /*"DEF"*/}, 0); affirm( 0==rc ); rc = sqlite3_blob_close(b); affirm( 0==rc ); + rc = sqlite3_blob_close(b); + affirm( 0!=rc ); affirm( 0==b.getNativePointer() ); - sqlite3_stmt stmt = prepare(db,"SELECT length(a), a FROM t"); + sqlite3_stmt stmt = prepare(db,"SELECT length(a), a FROM t ORDER BY a"); affirm( SQLITE_ROW == sqlite3_step(stmt) ); affirm( 3 == sqlite3_column_int(stmt,0) ); affirm( "def".equals(sqlite3_column_text16(stmt,1)) ); - sqlite3_finalize(stmt); + + b = sqlite3_blob_open(db, "main", "t", "a", + sqlite3_last_insert_rowid(db), 1); + affirm( null!=b ); + rc = sqlite3_blob_reopen(b, 2); + affirm( 0==rc ); + final byte[] tgt = new byte[3]; + rc = sqlite3_blob_read(b, tgt, 0); + affirm( 0==rc ); + affirm( 100==tgt[0] && 101==tgt[1] && 102==tgt[2], "DEF" ); + rc = sqlite3_blob_close(b); + affirm( 0==rc ); sqlite3_close_v2(db); } diff --git a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java index 99eae7370a..060846ff39 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java +++ b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java @@ -6,19 +6,22 @@ package org.sqlite.jni.annotation; called into from the C APIs, this annotation communicates that the C API will never pass a null value to the callback. +

Passing a null for any parameter marked with this annoation + specifically invokes undefined behavior.

+

Note that the C-style API does not throw any exceptions on its own because it has a no-throw policy in order to retain its C-style semantics, but it may trigger NullPointerExceptions (or similar) if - passed a null for a parameter flagged with this annotation. + passed a null for a parameter flagged with this annotation.

This annotation is informational only. No policy is in place to programmatically ensure that NotNull is conformed to in client - code. + code.

This annotation is solely for the use by the classes in this package but is made public so that javadoc will link to it from the annotated functions. It is not part of the public API and - client-level code must not rely on it. + client-level code must not rely on it.

*/ @java.lang.annotation.Documented @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) diff --git a/manifest b/manifest index daa9e58d18..e5562b0cb1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\sthe\ssqlite3_blob_...()\sAPIs\sto\sJNI. -D 2023-09-03T14:13:29.255 +C Add\sthe\smissing\ssqlite3_blob_read()\sto\s[9a9945c405cf].\sElaborate\son\sthe\sdefinition\sof\sthe\s@NotNull\sannotation. +D 2023-09-03T14:41:13.037 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 2a5a3f6637d34c3d8e8d60eac00b8ca231b0e97ce170d44c60a3afd040301104 -F ext/jni/src/c/sqlite3-jni.h 273e2ab8652d438e98bc891c8a80dcb4f9de82675124f0b090927532d8c5d212 +F ext/jni/src/c/sqlite3-jni.c 13ad7ddb42fb3733edef89ae0ed39b73ac0ceb2b25b53aac2533321544987e7a +F ext/jni/src/c/sqlite3-jni.h 72e2e16143bebce663e8b62a4878ad97e30de74e40cdd19415a31ee9a859ddd6 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 5b8890dcee68dda59c737a2e5acf34ae251b088daa1159f0a5cd78a087439239 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java b9b45b3434141c51e827483ea88b676cb5287c1376809eb8ebc9931a9a4357d2 F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 1f38d134b732f0122ff7eace6945fa7093afe264fc158eebf66d193cba6ed294 +F ext/jni/src/org/sqlite/jni/Tester1.java 1d59c877ce795916f57c0f741b09666b801b22b5509f725c9b96fc07bc75afcd F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -273,7 +273,7 @@ F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71 F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0f8234d379d266d1b2c21400a057864b538a0ea5 -F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d48ebd7ae6bbb78bd47d54431c85e1521c89b1d3864a2b6eafd9c0e1b2341457 +F ext/jni/src/org/sqlite/jni/annotation/NotNull.java cdfd375b3451333e276631ba049e8a5937695752973cb108313d917a31533423 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 F ext/jni/src/org/sqlite/jni/fts5_api.java bf7009a7fd2d11a77280380e6e2c7f98e377494b3f265e50fc44cbb9a24275d9 @@ -2118,8 +2118,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 bac54da29c19ef5e0a76599b5d10b377ecd7b391a651af99526529df16a83c7d -R 282c1de5bd907fe2a4768bc91d128cea +P 9a9945c405cfe9b6bf399655f498457da66b06c8b92014510ab9fb83fbb1c7d4 +R 84372103f945861eb05bc4b3a5468361 U stephan -Z eef925f2110921290c9a3b0a29c51189 +Z c5aa39a6231129353b30e801e81c87f0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f88732c20e..11cb864f5f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9a9945c405cfe9b6bf399655f498457da66b06c8b92014510ab9fb83fbb1c7d4 \ No newline at end of file +85952b4a52a09e9da35754c1a1ec70b1bf277296011a2d37ac536b33437223d7 \ No newline at end of file From 411d9e7b2ebb45a8e0ce428f55840765739e01ef Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Sep 2023 04:23:31 +0000 Subject: [PATCH 29/36] Expose sqlite3_bind_parameter_name() to JNI. Extend the definition of null for the @NotNull annotation, to consider closed/finalized Java-side handles wrapping C-side resources as null for its purposes. FossilOrigin-Name: fc34e2bfa4a2255f019a2514367e58596837289de49f7fab87279c8b40c7f119 --- ext/jni/src/c/sqlite3-jni.c | 13 ++++++++++++ ext/jni/src/c/sqlite3-jni.h | 8 ++++++++ ext/jni/src/org/sqlite/jni/SQLite3Jni.java | 5 +++++ ext/jni/src/org/sqlite/jni/Tester1.java | 1 + .../org/sqlite/jni/annotation/NotNull.java | 5 +++++ manifest | 20 +++++++++---------- manifest.uuid | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index f7e614f4d2..7c7b57a475 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2401,6 +2401,19 @@ S3JniApi(sqlite3_bind_parameter_index(),jint,1bind_1parameter_1index)( return rc; } +S3JniApi(sqlite3_bind_parameter_name(),jstring,1bind_1parameter_1name)( + JniArgsEnvClass, jobject jpStmt, jint ndx +){ + jstring rv = 0; + const char *z = + sqlite3_bind_parameter_name(PtrGet_sqlite3_stmt(jpStmt), (int)ndx); + + if( z ){ + rv = s3jni_utf8_to_jstring(z, -1); + } + return rv; +} + S3JniApi(sqlite3_bind_text(),jint,1bind_1text)( JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 08de9ab8a6..35231f0fc2 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -915,6 +915,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1bind_1parameter_1 JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1bind_1parameter_1index (JNIEnv *, jclass, jobject, jbyteArray); +/* + * Class: org_sqlite_jni_SQLite3Jni + * Method: sqlite3_bind_parameter_name + * Signature: (Lorg/sqlite/jni/sqlite3_stmt;I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1bind_1parameter_1name + (JNIEnv *, jclass, jobject, jint); + /* * Class: org_sqlite_jni_SQLite3Jni * Method: sqlite3_bind_text diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 26b027160a..eaf2fdd9e7 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -258,6 +258,11 @@ public final class SQLite3Jni { return sqlite3_bind_parameter_index(stmt, utf8); } + @Canonical + public static native String sqlite3_bind_parameter_name( + @NotNull sqlite3_stmt stmt, int index + ); + /** Works like the C-level sqlite3_bind_text() but assumes SQLITE_TRANSIENT for the final C API parameter. The byte array is diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 2987c1b85a..02a4d4a47a 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -350,6 +350,7 @@ public class Tester1 implements Runnable { affirm(1 == sqlite3_bind_parameter_count(stmt)); final int paramNdx = sqlite3_bind_parameter_index(stmt, ":a"); affirm(1 == paramNdx); + affirm( ":a".equals(sqlite3_bind_parameter_name(stmt, paramNdx))); int total1 = 0; long rowid = -1; int changes = sqlite3_changes(db); diff --git a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java index 060846ff39..02ff56896f 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java +++ b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java @@ -6,6 +6,11 @@ package org.sqlite.jni.annotation; called into from the C APIs, this annotation communicates that the C API will never pass a null value to the callback. +

In the case of Java types which map directly to C struct types, + a closed/finalized resource is also considered to be null for + purposes this annotation because the effect C-side is the same as + if null is passed for a NotNull-annotated parameter.

+

Passing a null for any parameter marked with this annoation specifically invokes undefined behavior.

diff --git a/manifest b/manifest index e5562b0cb1..f7934d68f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\smissing\ssqlite3_blob_read()\sto\s[9a9945c405cf].\sElaborate\son\sthe\sdefinition\sof\sthe\s@NotNull\sannotation. -D 2023-09-03T14:41:13.037 +C Expose\ssqlite3_bind_parameter_name()\sto\sJNI.\sExtend\sthe\sdefinition\sof\snull\sfor\sthe\s@NotNull\sannotation,\sto\sconsider\sclosed/finalized\sJava-side\shandles\swrapping\sC-side\sresources\sas\snull\sfor\sits\spurposes. +D 2023-09-04T04:23:31.856 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 13ad7ddb42fb3733edef89ae0ed39b73ac0ceb2b25b53aac2533321544987e7a -F ext/jni/src/c/sqlite3-jni.h 72e2e16143bebce663e8b62a4878ad97e30de74e40cdd19415a31ee9a859ddd6 +F ext/jni/src/c/sqlite3-jni.c 4b6f4295378c198b145d402ca84af1f70fa242d713e1cfb37c0c10ab7d4d5cd0 +F ext/jni/src/c/sqlite3-jni.h ff3f05fa179a0242eb86fea90c1f77d695338876bba49a754700b3c129468735 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86 F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4 F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java b9b45b3434141c51e827483ea88b676cb5287c1376809eb8ebc9931a9a4357d2 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java a1beb9f9953bfaf76824239d8f556c81a3d8ea81f89307817e17d2cb0cbf7c9c F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 1d59c877ce795916f57c0f741b09666b801b22b5509f725c9b96fc07bc75afcd +F ext/jni/src/org/sqlite/jni/Tester1.java e536ad7d647abeab72e060b1b90f80db17f07e20908e7247667b40645595ef99 F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c @@ -273,7 +273,7 @@ F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71 F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0f8234d379d266d1b2c21400a057864b538a0ea5 -F ext/jni/src/org/sqlite/jni/annotation/NotNull.java cdfd375b3451333e276631ba049e8a5937695752973cb108313d917a31533423 +F ext/jni/src/org/sqlite/jni/annotation/NotNull.java 7e7268749fccb8e110876642b31e7d7defdd95193de1c2f5f8ed34a9d6e4620b F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 F ext/jni/src/org/sqlite/jni/fts5_api.java bf7009a7fd2d11a77280380e6e2c7f98e377494b3f265e50fc44cbb9a24275d9 @@ -2118,8 +2118,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 9a9945c405cfe9b6bf399655f498457da66b06c8b92014510ab9fb83fbb1c7d4 -R 84372103f945861eb05bc4b3a5468361 +P 85952b4a52a09e9da35754c1a1ec70b1bf277296011a2d37ac536b33437223d7 +R 7a15b2696dc9747d7a1ea502837a695b U stephan -Z c5aa39a6231129353b30e801e81c87f0 +Z 236a641f15efc93fed4a9f543212d185 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 11cb864f5f..241119d30c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85952b4a52a09e9da35754c1a1ec70b1bf277296011a2d37ac536b33437223d7 \ No newline at end of file +fc34e2bfa4a2255f019a2514367e58596837289de49f7fab87279c8b40c7f119 \ No newline at end of file From 4eaf5883b38496c98fcf786b1f53cfcce9fd4b98 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Sep 2023 05:34:30 +0000 Subject: [PATCH 30/36] Move an internal utility class out of the public Java API. FossilOrigin-Name: 8e1ae3197a62796565b7260b230057bdb3f136edd00a83f8a63532d44d386243 --- ext/jni/GNUmakefile | 1 - ext/jni/src/org/sqlite/jni/Fts5.java | 6 ++--- ext/jni/src/org/sqlite/jni/Tester1.java | 11 ++++++++ ext/jni/src/org/sqlite/jni/ValueHolder.java | 25 ------------------- .../org/sqlite/jni/annotation/NotNull.java | 24 +++++++++++------- manifest | 19 +++++++------- manifest.uuid | 2 +- 7 files changed, 38 insertions(+), 50 deletions(-) delete mode 100644 ext/jni/src/org/sqlite/jni/ValueHolder.java diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 1e0b33be0a..2b48768e4c 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -92,7 +92,6 @@ JAVA_FILES.main := $(patsubst %,$(dir.src.jni)/%,\ TableColumnMetadata.java \ TraceV2Callback.java \ UpdateHookCallback.java \ - ValueHolder.java \ WindowFunction.java \ XDestroyCallback.java \ sqlite3.java \ diff --git a/ext/jni/src/org/sqlite/jni/Fts5.java b/ext/jni/src/org/sqlite/jni/Fts5.java index 3135db96d3..6e61c4149d 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5.java +++ b/ext/jni/src/org/sqlite/jni/Fts5.java @@ -16,10 +16,8 @@ package org.sqlite.jni; /** INCOMPLETE AND COMPLETELY UNTESTED. - A wrapper for communicating C-level (fts5_api*) instances with - Java. These wrappers do not own their associated pointer, they - simply provide a type-safe way to communicate it between Java and C - via JNI. + A utility object for holding FTS5-specific types and constants + which are used by multiple FTS5 classes. */ public final class Fts5 { /* Not used */ diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 02a4d4a47a..01e4ab18d5 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -38,6 +38,17 @@ import java.util.concurrent.Future; @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) @interface SingleThreadOnly{} +/** + A helper class which simply holds a single value. Its current use + is for communicating values out of anonymous classes, as doing so + requires a "final" reference. +*/ +class ValueHolder { + public T value; + public ValueHolder(){} + public ValueHolder(T v){value = v;} +} + public class Tester1 implements Runnable { //! True when running in multi-threaded mode. private static boolean mtMode = false; diff --git a/ext/jni/src/org/sqlite/jni/ValueHolder.java b/ext/jni/src/org/sqlite/jni/ValueHolder.java deleted file mode 100644 index 7f6a463ba5..0000000000 --- a/ext/jni/src/org/sqlite/jni/ValueHolder.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -** 2023-07-21 -** -** The author disclaims copyright to this source code. In place of -** a legal notice, here is a blessing: -** -** May you do good and not evil. -** May you find forgiveness for yourself and forgive others. -** May you share freely, never taking more than you give. -** -************************************************************************* -** This file is part of the JNI bindings for the sqlite3 C API. -*/ -package org.sqlite.jni; - -/** - A helper class which simply holds a single value. Its current use - is for communicating values out of anonymous classes, as doing so - requires a "final" reference. -*/ -public class ValueHolder { - public T value; - public ValueHolder(){} - public ValueHolder(T v){value = v;} -} diff --git a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java index 02ff56896f..49003358db 100644 --- a/ext/jni/src/org/sqlite/jni/annotation/NotNull.java +++ b/ext/jni/src/org/sqlite/jni/annotation/NotNull.java @@ -2,17 +2,23 @@ package org.sqlite.jni.annotation; /** This annotation is for flagging parameters which may not legally be - null. When used in the context of callback methods which are - called into from the C APIs, this annotation communicates that the - C API will never pass a null value to the callback. + null or point to closed/finalized C-side resources. -

In the case of Java types which map directly to C struct types, - a closed/finalized resource is also considered to be null for - purposes this annotation because the effect C-side is the same as - if null is passed for a NotNull-annotated parameter.

+

In the case of Java types which map directly to C struct types + (e.g. {@link org.sqlite.jni.sqlite3}, {@link + org.sqlite.jni.sqlite3_stmt}, and {@link + org.sqlite.jni.sqlite3_context}), a closed/finalized resource is + also considered to be null for purposes this annotation because the + C-side effect of passing such a handle is the same as if null is + passed.

-

Passing a null for any parameter marked with this annoation - specifically invokes undefined behavior.

+

When used in the context of Java interfaces which are called + from the C APIs, this annotation communicates that the C API will + never pass a null value to the callback for that parameter.

+ +

Passing a null, for this annotation's definition of null, for + any parameter marked with this annoation specifically invokes + undefined behavior.

Note that the C-style API does not throw any exceptions on its own because it has a no-throw policy in order to retain its C-style diff --git a/manifest b/manifest index f7934d68f4..007295b3cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\ssqlite3_bind_parameter_name()\sto\sJNI.\sExtend\sthe\sdefinition\sof\snull\sfor\sthe\s@NotNull\sannotation,\sto\sconsider\sclosed/finalized\sJava-side\shandles\swrapping\sC-side\sresources\sas\snull\sfor\sits\spurposes. -D 2023-09-04T04:23:31.856 +C Move\san\sinternal\sutility\sclass\sout\sof\sthe\spublic\sJava\sAPI. +D 2023-09-04T05:34:30.074 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,7 +234,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8 +F ext/jni/GNUmakefile 2ae5e34ad21da48a8c1dd6e9e421d6bbb78716e3a03ad29dd86d9bd530ee3fc0 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa F ext/jni/src/c/sqlite3-jni.c 4b6f4295378c198b145d402ca84af1f70fa242d713e1cfb37c0c10ab7d4d5cd0 @@ -250,7 +250,7 @@ F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b811542952 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 F ext/jni/src/org/sqlite/jni/ConfigLogCallback.java 636ed6b89ed03f15bc2a6f6f47bf7853b8328e5a8269e52e80630708efa703a6 F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 -F ext/jni/src/org/sqlite/jni/Fts5.java 3ebfbd5b95fdb9d7bc40306f2e682abd12e247d9224e92510b8dd103b4f96fe8 +F ext/jni/src/org/sqlite/jni/Fts5.java 09b3bfca6762420fa57a24df0ef797e5b31071a5dd1891d0e22a811b6e520b42 F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 6ac342951c5805b48ba1e46dd41dff3b74c609dc5bf1c26fca5738db36493031 F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 @@ -265,15 +265,14 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java a1beb9f9953bfaf76824239d8f556c81a3d8ea81f89307817e17d2cb0cbf7c9c F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java e536ad7d647abeab72e060b1b90f80db17f07e20908e7247667b40645595ef99 +F ext/jni/src/org/sqlite/jni/Tester1.java 79f64479297329cc98ad6401c506864750f5812449f896b696d6dbfa5af8355a F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c -F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 F ext/jni/src/org/sqlite/jni/XDestroyCallback.java 50c5ca124ef6c6b735a7e136e7a23a557be367e61b56d4aab5777a614ab46cc2 F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0f8234d379d266d1b2c21400a057864b538a0ea5 -F ext/jni/src/org/sqlite/jni/annotation/NotNull.java 7e7268749fccb8e110876642b31e7d7defdd95193de1c2f5f8ed34a9d6e4620b +F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d9b32956cb9fb11d1f8a562e5df70d0599820265285120c63858294dbe2b7711 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 F ext/jni/src/org/sqlite/jni/fts5_api.java bf7009a7fd2d11a77280380e6e2c7f98e377494b3f265e50fc44cbb9a24275d9 @@ -2118,8 +2117,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 85952b4a52a09e9da35754c1a1ec70b1bf277296011a2d37ac536b33437223d7 -R 7a15b2696dc9747d7a1ea502837a695b +P fc34e2bfa4a2255f019a2514367e58596837289de49f7fab87279c8b40c7f119 +R 768a12cfd33f550248c1b9dce66d5e0b U stephan -Z 236a641f15efc93fed4a9f543212d185 +Z 1c5b437e775779fe47dd6a40997032e6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 241119d30c..f84fffe1b1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc34e2bfa4a2255f019a2514367e58596837289de49f7fab87279c8b40c7f119 \ No newline at end of file +8e1ae3197a62796565b7260b230057bdb3f136edd00a83f8a63532d44d386243 \ No newline at end of file From 3aeb58c90ccfdad1f4327cc477acd0cc185ed64f Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Sep 2023 05:58:13 +0000 Subject: [PATCH 31/36] Remove several unnececessary functions. FossilOrigin-Name: 84433c72b0b08e7906ef87758caffe98f95df812945a7aea675bbc20791e33c0 --- ext/jni/src/c/sqlite3-jni.c | 63 ++++++------------------ ext/jni/src/c/sqlite3-jni.h | 2 + ext/jni/src/org/sqlite/jni/fts5_api.java | 3 +- manifest | 16 +++--- manifest.uuid | 2 +- 5 files changed, 27 insertions(+), 59 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 7c7b57a475..9a0ff6338d 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -1592,44 +1592,6 @@ static void OutputPointer_set_obj(JNIEnv * const env, S3JniExceptionIsFatal("Cannot set OutputPointer.T.value"); } -/* -** Sets the value property of the OutputPointer.sqlite3 jOut object to -** v. -*/ -static void OutputPointer_set_sqlite3(JNIEnv * const env, jobject const jOut, - jobject v){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3), jOut, v); -} - -/* -** Sets the value property of the OutputPointer.sqlite3_blob jOut object to -** v. -*/ -static void OutputPointer_set_sqlite3_blob(JNIEnv * const env, jobject const jOut, - jobject v){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_blob), jOut, v); -} - -/* -** Sets the value property of the OutputPointer.sqlite3_stmt jOut object to -** v. -*/ -static void OutputPointer_set_sqlite3_stmt(JNIEnv * const env, jobject const jOut, - jobject v){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_stmt), jOut, v); -} - -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK -/* -** Sets the value property of the OutputPointer.sqlite3_value jOut object to -** v. -*/ -static void OutputPointer_set_sqlite3_value(JNIEnv * const env, jobject const jOut, - jobject v){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), jOut, v); -} -#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ - #ifdef SQLITE_ENABLE_FTS5 #if 0 /* @@ -1680,15 +1642,13 @@ static void S3Jni_jobject_finalizer(void *v){ } } - - /* ** Returns a new Java instance of the class referred to by pRef, which ** MUST be interface-compatible with NativePointerHolder and MUST have ** a no-arg constructor. The NativePointerHolder_set() method is -** passed the new Java object and pNative. Hypothetically returns NULL -** if Java fails to allocate, but the JNI docs are not entirely clear -** on that detail. +** passed the new Java object (which must not be NULL) and pNative +** (which may be NULL). Hypothetically returns NULL if Java fails to +** allocate, but the JNI docs are not entirely clear on that detail. ** ** Always use a static pointer from the S3JniNphOps struct for the ** 2nd argument. @@ -2484,7 +2444,7 @@ S3JniApi(sqlite3_blob_open(),jint,1blob_1open)( if( 0==rc ){ jobject rv = new_java_sqlite3_blob(env, pBlob); if( rv ){ - OutputPointer_set_sqlite3_blob(env, jOut, rv); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_blob), jOut, rv); }else{ sqlite3_blob_close(pBlob); rc = SQLITE_NOMEM; @@ -2529,7 +2489,7 @@ S3JniApi(sqlite3_blob_write(),jint,1blob_1write)( const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jBa) : 0; int rc = SQLITE_MISUSE; if(b && pBuf){ - rc = sqlite3_blob_write( b, pBuf, nBa, (int)iOffset ); + rc = sqlite3_blob_write( b, pBuf, (int)nBa, (int)iOffset ); } s3jni_jbyteArray_release(jBa, pBuf); return (jint)rc; @@ -3620,7 +3580,8 @@ static int s3jni_open_post(JNIEnv * const env, S3JniEnv * const jc, S3JniDb_set_aside(ps); ps = 0; } - OutputPointer_set_sqlite3(env, jOut, ps ? ps->jDb : 0); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3), + jOut, ps ? ps->jDb : 0); return theRc ? theRc : rc; } @@ -3712,7 +3673,9 @@ end: ** what follows... */ assert(zTail ? ((void*)zTail>=(void*)pBuf) : 1); assert(zTail ? (((int)((void*)zTail - (void*)pBuf)) >= 0) : 1); - OutputPointer_set_Int32(env, outTail, (int)(zTail ? (zTail - (const char *)pBuf) : 0)); + OutputPointer_set_Int32( + env, outTail, (int)(zTail ? (zTail - (const char *)pBuf) : 0) + ); } if( pStmt ){ NativePointerHolder_set(S3JniNph(sqlite3_stmt), jStmt, pStmt); @@ -3725,7 +3688,8 @@ end: S3JniUnrefLocal(jStmt); jStmt = 0; } - OutputPointer_set_sqlite3_stmt(env, jOutStmt, jStmt); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_stmt), + jOutStmt, jStmt); return (jint)rc; } S3JniApi(sqlite3_prepare(),jint,1prepare)( @@ -3932,7 +3896,8 @@ static int s3jni_preupdate_newold(JNIEnv * const env, int isNew, jobject jDb, if( 0==rc ){ jobject pWrap = new_java_sqlite3_value(env, pOut); if( pWrap ){ - OutputPointer_set_sqlite3_value(env, jOut, pWrap); + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), + jOut, pWrap); S3JniUnrefLocal(pWrap); }else{ rc = SQLITE_NOMEM; diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 35231f0fc2..f291269717 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -2277,6 +2277,8 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xUserData #ifdef __cplusplus extern "C" { #endif +#undef org_sqlite_jni_fts5_api_iVersion +#define org_sqlite_jni_fts5_api_iVersion 2L /* * Class: org_sqlite_jni_fts5_api * Method: getInstanceForDb diff --git a/ext/jni/src/org/sqlite/jni/fts5_api.java b/ext/jni/src/org/sqlite/jni/fts5_api.java index a0376dfc8f..854a0348b1 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_api.java +++ b/ext/jni/src/org/sqlite/jni/fts5_api.java @@ -25,7 +25,8 @@ import org.sqlite.jni.annotation.*; public final class fts5_api extends NativePointerHolder { /* Only invoked from JNI */ private fts5_api(){} - public final int iVersion = 2; + + public static final int iVersion = 2; /** Returns the fts5_api instance associated with the given db, or diff --git a/manifest b/manifest index 007295b3cb..ea5b7628ae 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\san\sinternal\sutility\sclass\sout\sof\sthe\spublic\sJava\sAPI. -D 2023-09-04T05:34:30.074 +C Remove\sseveral\sunnececessary\sfunctions. +D 2023-09-04T05:58:13.370 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 2ae5e34ad21da48a8c1dd6e9e421d6bbb78716e3a03ad29dd86d9bd530ee3fc0 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 4b6f4295378c198b145d402ca84af1f70fa242d713e1cfb37c0c10ab7d4d5cd0 -F ext/jni/src/c/sqlite3-jni.h ff3f05fa179a0242eb86fea90c1f77d695338876bba49a754700b3c129468735 +F ext/jni/src/c/sqlite3-jni.c 93452c93e4e23884490f0c8ee76a38bc6c9a441800d95ff86aacb0991ab414d0 +F ext/jni/src/c/sqlite3-jni.h 6a6dfa22fc760f3a355cdc42cae07ea06ae3ee6d4fbf60bb11220a250926064c F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -275,7 +275,7 @@ F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0 F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d9b32956cb9fb11d1f8a562e5df70d0599820265285120c63858294dbe2b7711 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 -F ext/jni/src/org/sqlite/jni/fts5_api.java bf7009a7fd2d11a77280380e6e2c7f98e377494b3f265e50fc44cbb9a24275d9 +F ext/jni/src/org/sqlite/jni/fts5_api.java 386ecbcfcd03c24afbca52dc8bdf00791b6f2cbc0dd7be53e354071ada94f7bc F ext/jni/src/org/sqlite/jni/fts5_extension_function.java bec9f17a7e784d57eca99d812a65ecc9dd74c8df62d6d90cc1ecb3e37de14d47 F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 @@ -2117,8 +2117,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 fc34e2bfa4a2255f019a2514367e58596837289de49f7fab87279c8b40c7f119 -R 768a12cfd33f550248c1b9dce66d5e0b +P 8e1ae3197a62796565b7260b230057bdb3f136edd00a83f8a63532d44d386243 +R 5de5f56813f9d2b943c3cc107d561381 U stephan -Z 1c5b437e775779fe47dd6a40997032e6 +Z b5a6e033e7444f24fb64279fc427f971 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f84fffe1b1..dca1c56b19 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8e1ae3197a62796565b7260b230057bdb3f136edd00a83f8a63532d44d386243 \ No newline at end of file +84433c72b0b08e7906ef87758caffe98f95df812945a7aea675bbc20791e33c0 \ No newline at end of file From 0c072b698beb5310e0cb3d343526bd5036adea2a Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 4 Sep 2023 06:15:37 +0000 Subject: [PATCH 32/36] In JNI routines which set an OutputPointer.value, always do so, even on error, for consistency. FossilOrigin-Name: d0df62f0af19a69f7ceb3ad1dceda0d8cc2ca5016a6e2a3a1e36356424c3ca49 --- ext/jni/src/c/sqlite3-jni.c | 14 ++++++-------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 9a0ff6338d..ea8dcd7442 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -2443,12 +2443,11 @@ S3JniApi(sqlite3_blob_open(),jint,1blob_1open)( : SQLITE_NOMEM; if( 0==rc ){ jobject rv = new_java_sqlite3_blob(env, pBlob); - if( rv ){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_blob), jOut, rv); - }else{ + if( !rv ){ sqlite3_blob_close(pBlob); rc = SQLITE_NOMEM; } + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_blob), jOut, rv); } sqlite3_free(zDbName); sqlite3_free(zTableName); @@ -3895,13 +3894,12 @@ static int s3jni_preupdate_newold(JNIEnv * const env, int isNew, jobject jDb, rc = fOrig(pDb, (int)iCol, &pOut); if( 0==rc ){ jobject pWrap = new_java_sqlite3_value(env, pOut); - if( pWrap ){ - OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), - jOut, pWrap); - S3JniUnrefLocal(pWrap); - }else{ + if( !pWrap ){ rc = SQLITE_NOMEM; } + OutputPointer_set_obj(env, S3JniNph(OutputPointer_sqlite3_value), + jOut, pWrap); + S3JniUnrefLocal(pWrap); } } return rc; diff --git a/manifest b/manifest index ea5b7628ae..1b3b64cfe4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sseveral\sunnececessary\sfunctions. -D 2023-09-04T05:58:13.370 +C In\sJNI\sroutines\swhich\sset\san\sOutputPointer.value,\salways\sdo\sso,\seven\son\serror,\sfor\sconsistency. +D 2023-09-04T06:15:37.421 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -237,7 +237,7 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3 F ext/jni/GNUmakefile 2ae5e34ad21da48a8c1dd6e9e421d6bbb78716e3a03ad29dd86d9bd530ee3fc0 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 93452c93e4e23884490f0c8ee76a38bc6c9a441800d95ff86aacb0991ab414d0 +F ext/jni/src/c/sqlite3-jni.c 1b406fc279306db41e32297c194038973bc4c6befafbb83be0bb255debe45ed0 F ext/jni/src/c/sqlite3-jni.h 6a6dfa22fc760f3a355cdc42cae07ea06ae3ee6d4fbf60bb11220a250926064c F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 @@ -2117,8 +2117,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 8e1ae3197a62796565b7260b230057bdb3f136edd00a83f8a63532d44d386243 -R 5de5f56813f9d2b943c3cc107d561381 +P 84433c72b0b08e7906ef87758caffe98f95df812945a7aea675bbc20791e33c0 +R 137bff2b9d70db03844846385ed7bc3f U stephan -Z b5a6e033e7444f24fb64279fc427f971 +Z 9ac4c3726b9a591fa96f8b45cdf4fa42 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index dca1c56b19..d1d0cfd9c5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -84433c72b0b08e7906ef87758caffe98f95df812945a7aea675bbc20791e33c0 \ No newline at end of file +d0df62f0af19a69f7ceb3ad1dceda0d8cc2ca5016a6e2a3a1e36356424c3ca49 \ No newline at end of file From f31b9fcf8617b5eb9c6236c0b60a23417a6829ce Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 6 Sep 2023 06:54:25 +0000 Subject: [PATCH 33/36] Java FTS5 API renaming, for consistency. FossilOrigin-Name: 5e4cc9f386364858c6457c40f13f01e1826a59086aa7f0fa10244ea846f5acfd --- ext/jni/GNUmakefile | 2 +- ext/jni/src/c/sqlite3-jni.c | 2 +- ext/jni/src/c/sqlite3-jni.h | 6 ++--- ext/jni/src/org/sqlite/jni/Fts5.java | 2 +- .../src/org/sqlite/jni/Fts5ExtensionApi.java | 6 ++--- .../src/org/sqlite/jni/fts5_tokenizer.java | 2 +- manifest | 22 +++++++++---------- manifest.uuid | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 2b48768e4c..eb4cbf71d2 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -27,7 +27,7 @@ dir.bld := $(dir.jni)/bld dir.bld.c := $(dir.bld) dir.src.jni := $(dir.src)/org/sqlite/jni dir.src.jni.tester := $(dir.src.jni)/tester -mkdir := mkdir -p +mkdir ?= mkdir -p $(dir.bld.c): $(mkdir) $@ diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index ea8dcd7442..726f88c118 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -4538,7 +4538,7 @@ static int s3jni_trace_impl(unsigned traceflag, void *pC, void *pP, void *pX){ jP = jPUnref = S3JniRefLocal(ps->jDb); break; default: - assert(!"cannot happen - unkown trace flag"); + assert(!"cannot happen - unknown trace flag"); rc = SQLITE_ERROR; } if( 0==rc ){ diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index f291269717..36cb80567d 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -2219,7 +2219,7 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseSize /* * Class: org_sqlite_jni_Fts5ExtensionApi * Method: xQueryPhrase - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/Fts5ExtensionApi/xQueryPhraseCallback;)I + * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/Fts5ExtensionApi/XQueryPhraseCallback;)I */ JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xQueryPhrase (JNIEnv *, jobject, jobject, jint, jobject); @@ -2251,7 +2251,7 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xSetAuxdata /* * Class: org_sqlite_jni_Fts5ExtensionApi * Method: xTokenize - * Signature: (Lorg/sqlite/jni/Fts5Context;[BLorg/sqlite/jni/Fts5/xTokenize_callback;)I + * Signature: (Lorg/sqlite/jni/Fts5Context;[BLorg/sqlite/jni/Fts5/XTokenizeCallback;)I */ JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xTokenize (JNIEnv *, jobject, jobject, jbyteArray, jobject); @@ -2311,7 +2311,7 @@ extern "C" { /* * Class: org_sqlite_jni_fts5_tokenizer * Method: xTokenize - * Signature: (Lorg/sqlite/jni/Fts5Tokenizer;I[BLorg/sqlite/jni/Fts5/xTokenize_callback;)I + * Signature: (Lorg/sqlite/jni/Fts5Tokenizer;I[BLorg/sqlite/jni/Fts5/XTokenizeCallback;)I */ JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_1tokenizer_xTokenize (JNIEnv *, jobject, jobject, jint, jbyteArray, jobject); diff --git a/ext/jni/src/org/sqlite/jni/Fts5.java b/ext/jni/src/org/sqlite/jni/Fts5.java index 6e61c4149d..104f027f9f 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5.java +++ b/ext/jni/src/org/sqlite/jni/Fts5.java @@ -26,7 +26,7 @@ public final class Fts5 { /** Callback type for use with xTokenize() variants */ - public static interface xTokenize_callback { + public static interface XTokenizeCallback { int call(int tFlags, byte[] txt, int iStart, int iEnd); } diff --git a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java index a575ebdb91..b6c97c935a 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java +++ b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java @@ -27,7 +27,7 @@ public final class Fts5ExtensionApi extends NativePointerHolder { public native int xTokenize(@NotNull Fts5Tokenizer t, int tokFlags, @NotNull byte pText[], - @NotNull Fts5.xTokenize_callback callback); + @NotNull Fts5.XTokenizeCallback callback); // int (*xTokenize)(Fts5Tokenizer*, diff --git a/manifest b/manifest index 1b3b64cfe4..73e619873d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sJNI\sroutines\swhich\sset\san\sOutputPointer.value,\salways\sdo\sso,\seven\son\serror,\sfor\sconsistency. -D 2023-09-04T06:15:37.421 +C Java\sFTS5\sAPI\srenaming,\sfor\sconsistency. +D 2023-09-06T06:54:25.034 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,11 +234,11 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 2ae5e34ad21da48a8c1dd6e9e421d6bbb78716e3a03ad29dd86d9bd530ee3fc0 +F ext/jni/GNUmakefile 13a0d923fdbcbc363e5ed067423da3a19f6b25a49ae83ebddb00569f94b81b25 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 1b406fc279306db41e32297c194038973bc4c6befafbb83be0bb255debe45ed0 -F ext/jni/src/c/sqlite3-jni.h 6a6dfa22fc760f3a355cdc42cae07ea06ae3ee6d4fbf60bb11220a250926064c +F ext/jni/src/c/sqlite3-jni.c 98f83a07c6956f51b9e758e1e560ad9826c67c1fe7f256e527293bd9808c4768 +F ext/jni/src/c/sqlite3-jni.h 875992ddf3a8c33d68a49ac26fbe2060f3ee98fb49127f140fed1e69f1da3be6 F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -250,9 +250,9 @@ F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b811542952 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 F ext/jni/src/org/sqlite/jni/ConfigLogCallback.java 636ed6b89ed03f15bc2a6f6f47bf7853b8328e5a8269e52e80630708efa703a6 F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 -F ext/jni/src/org/sqlite/jni/Fts5.java 09b3bfca6762420fa57a24df0ef797e5b31071a5dd1891d0e22a811b6e520b42 +F ext/jni/src/org/sqlite/jni/Fts5.java 0ca3cb814cb92e1ec07ccda72bcdb7eb45615abbc155e515d1cda3ee1404143d F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 -F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 6ac342951c5805b48ba1e46dd41dff3b74c609dc5bf1c26fca5738db36493031 +F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 24c7fb75c4464c2c3a893c31ec23a86a1bf5289fda8901a9cf4a923de42eea52 F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d @@ -277,7 +277,7 @@ F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae87 F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 F ext/jni/src/org/sqlite/jni/fts5_api.java 386ecbcfcd03c24afbca52dc8bdf00791b6f2cbc0dd7be53e354071ada94f7bc F ext/jni/src/org/sqlite/jni/fts5_extension_function.java bec9f17a7e784d57eca99d812a65ecc9dd74c8df62d6d90cc1ecb3e37de14d47 -F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java a92c2e55bda492e4c76d48ddc73369bcc0d5e8727940840f9339e3292ea58fa7 +F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java 1b48d45763c571b70b6a0b419780ec8a4163f97a684e326d6e93eb0cb596fa95 F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_backup.java d0bb06dd6225e76999ff6b7ab20f2643b1c4d4167431b3a93ea41943e41f094b @@ -2117,8 +2117,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 84433c72b0b08e7906ef87758caffe98f95df812945a7aea675bbc20791e33c0 -R 137bff2b9d70db03844846385ed7bc3f +P d0df62f0af19a69f7ceb3ad1dceda0d8cc2ca5016a6e2a3a1e36356424c3ca49 +R 1c9c032947a0621b2a97abc848cee358 U stephan -Z 9ac4c3726b9a591fa96f8b45cdf4fa42 +Z 2634b10b864fb044031f2a08908448d5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d1d0cfd9c5..d37b01c322 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d0df62f0af19a69f7ceb3ad1dceda0d8cc2ca5016a6e2a3a1e36356424c3ca49 \ No newline at end of file +5e4cc9f386364858c6457c40f13f01e1826a59086aa7f0fa10244ea846f5acfd \ No newline at end of file From 7c1588b3ad342c39e311816d8071fdba165a67b2 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 6 Sep 2023 07:39:25 +0000 Subject: [PATCH 34/36] Move Java-side FTS5 bits into the fts5 subpackage to (A) make it easy to optionally bundle it (or not) and (B) set a precedent for puting extension APIs in their own package. FossilOrigin-Name: 4c773e1f331cd5854d4c6e8825197933c0bb6827b7437e56ac0ad650d1ddf55e --- ext/jni/GNUmakefile | 21 +-- ext/jni/src/c/sqlite3-jni.c | 22 +-- ext/jni/src/c/sqlite3-jni.h | 160 +++++++++--------- ext/jni/src/org/sqlite/jni/Tester1.java | 32 ++-- .../src/org/sqlite/jni/{ => fts5}/Fts5.java | 2 +- .../sqlite/jni/{ => fts5}/Fts5Context.java | 3 +- .../jni/{ => fts5}/Fts5ExtensionApi.java | 3 +- .../sqlite/jni/{ => fts5}/Fts5PhraseIter.java | 3 +- .../sqlite/jni/{ => fts5}/Fts5Tokenizer.java | 3 +- .../org/sqlite/jni/{ => fts5}/TesterFts5.java | 37 ++-- .../org/sqlite/jni/{ => fts5}/fts5_api.java | 3 +- .../{ => fts5}/fts5_extension_function.java | 4 +- .../sqlite/jni/{ => fts5}/fts5_tokenizer.java | 5 +- manifest | 36 ++-- manifest.uuid | 2 +- 15 files changed, 168 insertions(+), 168 deletions(-) rename ext/jni/src/org/sqlite/jni/{ => fts5}/Fts5.java (97%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/Fts5Context.java (93%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/Fts5ExtensionApi.java (98%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/Fts5PhraseIter.java (90%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/Fts5Tokenizer.java (92%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/TesterFts5.java (72%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/fts5_api.java (97%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/fts5_extension_function.java (94%) rename ext/jni/src/org/sqlite/jni/{ => fts5}/fts5_tokenizer.java (94%) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index eb4cbf71d2..8997e0c12e 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -103,7 +103,8 @@ JAVA_FILES.unittest := $(patsubst %,$(dir.src.jni)/%,\ Tester1.java \ ) ifeq (1,$(enable.fts5)) - JAVA_FILES.main += $(patsubst %,$(dir.src.jni)/%,\ + dir.src.fts5 := $(dir.src.jni)/fts5 + JAVA_FILES.main += $(patsubst %,$(dir.src.fts5)/%,\ fts5_api.java \ fts5_extension_function.java \ fts5_tokenizer.java \ @@ -216,21 +217,21 @@ sqlite3-jni.h.in := # $(java.with.jni) lists all Java files which contain JNI decls: java.with.jni := define ADD_JNI_H -sqlite3-jni.h.in += $$(dir.bld.c)/org_sqlite_jni_$(1).h -java.with.jni += $$(dir.src.jni)/$(1).java -$$(dir.bld.c)/org_sqlite_jni_$(1).h: $$(dir.src.jni)/$(1).java +sqlite3-jni.h.in += $$(dir.bld.c)/org_sqlite_jni$(3)_$(2).h +java.with.jni += $(1)/$(2).java +$$(info x=$(1)/$(2).java) +$$(dir.bld.c)/org_sqlite_jni$(3)_$(2).h: $(1)/$(2).java endef # Invoke ADD_JNI_H once for each Java file which includes JNI # declarations: -$(eval $(call ADD_JNI_H,SQLite3Jni)) +$(eval $(call ADD_JNI_H,$(dir.src.jni),SQLite3Jni,)) ifeq (1,$(enable.fts5)) - $(eval $(call ADD_JNI_H,Fts5ExtensionApi)) - $(eval $(call ADD_JNI_H,fts5_api)) - $(eval $(call ADD_JNI_H,fts5_tokenizer)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),Fts5ExtensionApi,_fts5)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_api,_fts5)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_tokenizer,_fts5)) endif ifeq (1,$(enable.tester)) - sqlite3-jni.h.in += $(dir.bld.c)/org_sqlite_jni_tester_SQLTester.h - $(dir.bld.c)/org_sqlite_jni_tester_SQLTester.h: $(dir.src.jni.tester)/SQLTester.java + $(eval $(call ADD_JNI_H,$(dir.src.jni.tester),SQLTester,_tester)) endif $(sqlite3-jni.h.in): $(dir.bld.c) diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 726f88c118..0de280ac2a 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -383,11 +383,11 @@ static const struct { RefO(13, "OutputPointer$String", "Ljava/lang/String;"), #ifdef SQLITE_ENABLE_FTS5 RefO(14, "OutputPointer$ByteArray", "[B"), - RefN(15, "Fts5Context"), - RefN(16, "Fts5ExtensionApi"), - RefN(17, "fts5_api"), - RefN(18, "fts5_tokenizer"), - RefN(19, "Fts5Tokenizer") + RefN(15, "fts5/Fts5Context"), + RefN(16, "fts5/Fts5ExtensionApi"), + RefN(17, "fts5/fts5_api"), + RefN(18, "fts5/fts5_tokenizer"), + RefN(19, "fts5/Fts5Tokenizer") #endif #undef MkRef #undef RefN @@ -4793,11 +4793,11 @@ JniDecl(void,1jni_1internal_1details)(JniArgsEnvClass){ /* Creates a verbose JNI Fts5 function name. */ #define JniFuncNameFtsXA(Suffix) \ - Java_org_sqlite_jni_Fts5ExtensionApi_ ## Suffix + Java_org_sqlite_jni_fts5_Fts5ExtensionApi_ ## Suffix #define JniFuncNameFtsApi(Suffix) \ - Java_org_sqlite_jni_fts5_1api_ ## Suffix + Java_org_sqlite_jni_fts5_fts5_1api_ ## Suffix #define JniFuncNameFtsTok(Suffix) \ - Java_org_sqlite_jni_fts5_tokenizer_ ## Suffix + Java_org_sqlite_jni_fts5_fts5_tokenizer_ ## Suffix #define JniDeclFtsXA(ReturnType,Suffix) \ JNIEXPORT ReturnType JNICALL \ @@ -4855,8 +4855,8 @@ static Fts5JniAux * Fts5JniAux_alloc(JNIEnv * const env, jobject jObj){ s->jObj = S3JniRefGlobal(jObj); klazz = (*env)->GetObjectClass(env, jObj); s->jmid = (*env)->GetMethodID(env, klazz, "call", - "(Lorg/sqlite/jni/Fts5ExtensionApi;" - "Lorg/sqlite/jni/Fts5Context;" + "(Lorg/sqlite/jni/fts5/Fts5ExtensionApi;" + "Lorg/sqlite/jni/fts5/Fts5Context;" "Lorg/sqlite/jni/sqlite3_context;" "[Lorg/sqlite/jni/sqlite3_value;)V"); S3JniUnrefLocal(klazz); @@ -5651,7 +5651,7 @@ Java_org_sqlite_jni_SQLite3Jni_init(JniArgsEnvClass){ } #ifdef SQLITE_ENABLE_FTS5 - klazz = (*env)->FindClass(env, "org/sqlite/jni/Fts5PhraseIter"); + klazz = (*env)->FindClass(env, "org/sqlite/jni/fts5/Fts5PhraseIter"); S3JniExceptionIsFatal("Error getting reference to org.sqlite.jni.Fts5PhraseIter."); SJG.fts5.jPhraseIter.fidA = (*env)->GetFieldID(env, klazz, "a", "J"); S3JniExceptionIsFatal("Cannot get Fts5PhraseIter.a field."); diff --git a/ext/jni/src/c/sqlite3-jni.h b/ext/jni/src/c/sqlite3-jni.h index 36cb80567d..179c9c5cfb 100644 --- a/ext/jni/src/c/sqlite3-jni.h +++ b/ext/jni/src/c/sqlite3-jni.h @@ -2097,171 +2097,171 @@ JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1jni_1internal_1de #endif /* DO NOT EDIT THIS FILE - it is machine generated */ #include -/* Header for class org_sqlite_jni_Fts5ExtensionApi */ +/* Header for class org_sqlite_jni_fts5_Fts5ExtensionApi */ -#ifndef _Included_org_sqlite_jni_Fts5ExtensionApi -#define _Included_org_sqlite_jni_Fts5ExtensionApi +#ifndef _Included_org_sqlite_jni_fts5_Fts5ExtensionApi +#define _Included_org_sqlite_jni_fts5_Fts5ExtensionApi #ifdef __cplusplus extern "C" { #endif /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: getInstance - * Signature: ()Lorg/sqlite/jni/Fts5ExtensionApi; + * Signature: ()Lorg/sqlite/jni/fts5/Fts5ExtensionApi; */ -JNIEXPORT jobject JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_getInstance +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_getInstance (JNIEnv *, jclass); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xColumnCount - * Signature: (Lorg/sqlite/jni/Fts5Context;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xColumnCount +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xColumnCount (JNIEnv *, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xColumnSize - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int32;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int32;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xColumnSize +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xColumnSize (JNIEnv *, jobject, jobject, jint, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xColumnText - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/OutputPointer/String;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/OutputPointer/String;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xColumnText +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xColumnText (JNIEnv *, jobject, jobject, jint, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xColumnTotalSize - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int64;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int64;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xColumnTotalSize +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xColumnTotalSize (JNIEnv *, jobject, jobject, jint, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xGetAuxdata - * Signature: (Lorg/sqlite/jni/Fts5Context;Z)Ljava/lang/Object; + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Z)Ljava/lang/Object; */ -JNIEXPORT jobject JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xGetAuxdata +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xGetAuxdata (JNIEnv *, jobject, jobject, jboolean); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xInst - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xInst +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xInst (JNIEnv *, jobject, jobject, jint, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xInstCount - * Signature: (Lorg/sqlite/jni/Fts5Context;Lorg/sqlite/jni/OutputPointer/Int32;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Lorg/sqlite/jni/OutputPointer/Int32;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xInstCount +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xInstCount (JNIEnv *, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseCount - * Signature: (Lorg/sqlite/jni/Fts5Context;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseCount +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseCount (JNIEnv *, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseFirst - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/fts5/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseFirst +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseFirst (JNIEnv *, jobject, jobject, jint, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseFirstColumn - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/fts5/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseFirstColumn +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseFirstColumn (JNIEnv *, jobject, jobject, jint, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseNext - * Signature: (Lorg/sqlite/jni/Fts5Context;Lorg/sqlite/jni/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)V + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Lorg/sqlite/jni/fts5/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;Lorg/sqlite/jni/OutputPointer/Int32;)V */ -JNIEXPORT void JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseNext +JNIEXPORT void JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseNext (JNIEnv *, jobject, jobject, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseNextColumn - * Signature: (Lorg/sqlite/jni/Fts5Context;Lorg/sqlite/jni/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;)V + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Lorg/sqlite/jni/fts5/Fts5PhraseIter;Lorg/sqlite/jni/OutputPointer/Int32;)V */ -JNIEXPORT void JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseNextColumn +JNIEXPORT void JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseNextColumn (JNIEnv *, jobject, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xPhraseSize - * Signature: (Lorg/sqlite/jni/Fts5Context;I)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;I)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xPhraseSize +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xPhraseSize (JNIEnv *, jobject, jobject, jint); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xQueryPhrase - * Signature: (Lorg/sqlite/jni/Fts5Context;ILorg/sqlite/jni/Fts5ExtensionApi/XQueryPhraseCallback;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;ILorg/sqlite/jni/fts5/Fts5ExtensionApi/XQueryPhraseCallback;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xQueryPhrase +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xQueryPhrase (JNIEnv *, jobject, jobject, jint, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xRowCount - * Signature: (Lorg/sqlite/jni/Fts5Context;Lorg/sqlite/jni/OutputPointer/Int64;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Lorg/sqlite/jni/OutputPointer/Int64;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xRowCount +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xRowCount (JNIEnv *, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xRowid - * Signature: (Lorg/sqlite/jni/Fts5Context;)J + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;)J */ -JNIEXPORT jlong JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xRowid +JNIEXPORT jlong JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xRowid (JNIEnv *, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xSetAuxdata - * Signature: (Lorg/sqlite/jni/Fts5Context;Ljava/lang/Object;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;Ljava/lang/Object;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xSetAuxdata +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xSetAuxdata (JNIEnv *, jobject, jobject, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xTokenize - * Signature: (Lorg/sqlite/jni/Fts5Context;[BLorg/sqlite/jni/Fts5/XTokenizeCallback;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;[BLorg/sqlite/jni/fts5/Fts5/XTokenizeCallback;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xTokenize +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xTokenize (JNIEnv *, jobject, jobject, jbyteArray, jobject); /* - * Class: org_sqlite_jni_Fts5ExtensionApi + * Class: org_sqlite_jni_fts5_Fts5ExtensionApi * Method: xUserData - * Signature: (Lorg/sqlite/jni/Fts5Context;)Ljava/lang/Object; + * Signature: (Lorg/sqlite/jni/fts5/Fts5Context;)Ljava/lang/Object; */ -JNIEXPORT jobject JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xUserData +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_Fts5ExtensionApi_xUserData (JNIEnv *, jobject, jobject); #ifdef __cplusplus @@ -2270,29 +2270,29 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_Fts5ExtensionApi_xUserData #endif /* DO NOT EDIT THIS FILE - it is machine generated */ #include -/* Header for class org_sqlite_jni_fts5_api */ +/* Header for class org_sqlite_jni_fts5_fts5_api */ -#ifndef _Included_org_sqlite_jni_fts5_api -#define _Included_org_sqlite_jni_fts5_api +#ifndef _Included_org_sqlite_jni_fts5_fts5_api +#define _Included_org_sqlite_jni_fts5_fts5_api #ifdef __cplusplus extern "C" { #endif -#undef org_sqlite_jni_fts5_api_iVersion -#define org_sqlite_jni_fts5_api_iVersion 2L +#undef org_sqlite_jni_fts5_fts5_api_iVersion +#define org_sqlite_jni_fts5_fts5_api_iVersion 2L /* - * Class: org_sqlite_jni_fts5_api + * Class: org_sqlite_jni_fts5_fts5_api * Method: getInstanceForDb - * Signature: (Lorg/sqlite/jni/sqlite3;)Lorg/sqlite/jni/fts5_api; + * Signature: (Lorg/sqlite/jni/sqlite3;)Lorg/sqlite/jni/fts5/fts5_api; */ -JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_1api_getInstanceForDb +JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_fts5_1api_getInstanceForDb (JNIEnv *, jclass, jobject); /* - * Class: org_sqlite_jni_fts5_api + * Class: org_sqlite_jni_fts5_fts5_api * Method: xCreateFunction - * Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/sqlite/jni/fts5_extension_function;)I + * Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/sqlite/jni/fts5/fts5_extension_function;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_1api_xCreateFunction +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_fts5_1api_xCreateFunction (JNIEnv *, jobject, jstring, jobject, jobject); #ifdef __cplusplus @@ -2301,19 +2301,19 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_1api_xCreateFunction #endif /* DO NOT EDIT THIS FILE - it is machine generated */ #include -/* Header for class org_sqlite_jni_fts5_tokenizer */ +/* Header for class org_sqlite_jni_fts5_fts5_tokenizer */ -#ifndef _Included_org_sqlite_jni_fts5_tokenizer -#define _Included_org_sqlite_jni_fts5_tokenizer +#ifndef _Included_org_sqlite_jni_fts5_fts5_tokenizer +#define _Included_org_sqlite_jni_fts5_fts5_tokenizer #ifdef __cplusplus extern "C" { #endif /* - * Class: org_sqlite_jni_fts5_tokenizer + * Class: org_sqlite_jni_fts5_fts5_tokenizer * Method: xTokenize - * Signature: (Lorg/sqlite/jni/Fts5Tokenizer;I[BLorg/sqlite/jni/Fts5/XTokenizeCallback;)I + * Signature: (Lorg/sqlite/jni/fts5/Fts5Tokenizer;I[BLorg/sqlite/jni/fts5/Fts5/XTokenizeCallback;)I */ -JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_1tokenizer_xTokenize +JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_fts5_1tokenizer_xTokenize (JNIEnv *, jobject, jobject, jint, jbyteArray, jobject); #ifdef __cplusplus diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 01e4ab18d5..5b007077bd 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -79,33 +79,33 @@ public class Tester1 implements Runnable { static final Metrics metrics = new Metrics(); - public synchronized static void outln(){ + public static synchronized void outln(){ if( !quietMode ){ System.out.println(""); } } - public synchronized static void outPrefix(){ + public static synchronized void outPrefix(){ if( !quietMode ){ System.out.print(Thread.currentThread().getName()+": "); } } - public synchronized static void outln(Object val){ + public static synchronized void outln(Object val){ if( !quietMode ){ outPrefix(); System.out.println(val); } } - public synchronized static void out(Object val){ + public static synchronized void out(Object val){ if( !quietMode ){ System.out.print(val); } } @SuppressWarnings("unchecked") - public synchronized static void out(Object... vals){ + public static synchronized void out(Object... vals){ if( !quietMode ){ outPrefix(); for(Object v : vals) out(v); @@ -113,20 +113,21 @@ public class Tester1 implements Runnable { } @SuppressWarnings("unchecked") - public synchronized static void outln(Object... vals){ + public static synchronized void outln(Object... vals){ if( !quietMode ){ out(vals); out("\n"); } } static volatile int affirmCount = 0; - public synchronized static void affirm(Boolean v, String comment){ + public static synchronized int affirm(Boolean v, String comment){ ++affirmCount; if( false ) assert( v /* prefer assert over exception if it's enabled because the JNI layer sometimes has to suppress exceptions, so they might be squelched on their way back to the top. */); if( !v ) throw new RuntimeException(comment); + return affirmCount; } public static void affirm(Boolean v){ @@ -138,7 +139,7 @@ public class Tester1 implements Runnable { affirm(sqlite3_libversion_number() == SQLITE_VERSION_NUMBER); } - static sqlite3 createNewDb(){ + public static sqlite3 createNewDb(){ final OutputPointer.sqlite3 out = new OutputPointer.sqlite3(); int rc = sqlite3_open(":memory:", out); ++metrics.dbOpen; @@ -156,11 +157,11 @@ public class Tester1 implements Runnable { return db; } - static void execSql(sqlite3 db, String[] sql){ + public static void execSql(sqlite3 db, String[] sql){ execSql(db, String.join("", sql)); } - static int execSql(sqlite3 db, boolean throwOnError, String sql){ + public static int execSql(sqlite3 db, boolean throwOnError, String sql){ OutputPointer.Int32 oTail = new OutputPointer.Int32(); final byte[] sqlUtf8 = sql.getBytes(StandardCharsets.UTF_8); int pos = 0, n = 1; @@ -201,11 +202,11 @@ public class Tester1 implements Runnable { return rc; } - static void execSql(sqlite3 db, String sql){ + public static void execSql(sqlite3 db, String sql){ execSql(db, true, sql); } - static sqlite3_stmt prepare(sqlite3 db, boolean throwOnError, String sql){ + public static sqlite3_stmt prepare(sqlite3 db, boolean throwOnError, String sql){ final OutputPointer.sqlite3_stmt outStmt = new OutputPointer.sqlite3_stmt(); int rc = sqlite3_prepare_v2(db, sql, outStmt); if( throwOnError ){ @@ -219,7 +220,7 @@ public class Tester1 implements Runnable { return rv; } - static sqlite3_stmt prepare(sqlite3 db, String sql){ + public static sqlite3_stmt prepare(sqlite3 db, String sql){ return prepare(db, true, sql); } @@ -1275,10 +1276,13 @@ public class Tester1 implements Runnable { } Exception err = null; try { - Class t = Class.forName("org.sqlite.jni.TesterFts5"); + Class t = Class.forName("org.sqlite.jni.fts5.TesterFts5"); java.lang.reflect.Constructor ctor = t.getConstructor(); ctor.setAccessible(true); + final long timeStart = System.currentTimeMillis(); ctor.newInstance() /* will run all tests */; + final long timeEnd = System.currentTimeMillis(); + outln("FTS5 Tests done in ",(timeEnd - timeStart),"ms"); }catch(ClassNotFoundException e){ outln("FTS5 classes not loaded."); err = e; diff --git a/ext/jni/src/org/sqlite/jni/Fts5.java b/ext/jni/src/org/sqlite/jni/fts5/Fts5.java similarity index 97% rename from ext/jni/src/org/sqlite/jni/Fts5.java rename to ext/jni/src/org/sqlite/jni/fts5/Fts5.java index 104f027f9f..2e5678f1ee 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5.java +++ b/ext/jni/src/org/sqlite/jni/fts5/Fts5.java @@ -11,7 +11,7 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; /** INCOMPLETE AND COMPLETELY UNTESTED. diff --git a/ext/jni/src/org/sqlite/jni/Fts5Context.java b/ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java similarity index 93% rename from ext/jni/src/org/sqlite/jni/Fts5Context.java rename to ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java index e78f67d556..a5b937ceb8 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5Context.java +++ b/ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java @@ -11,7 +11,8 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; +import org.sqlite.jni.*; /** A wrapper for communicating C-level (Fts5Context*) instances with diff --git a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java b/ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java similarity index 98% rename from ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java rename to ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java index b6c97c935a..559f42392d 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java +++ b/ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java @@ -11,8 +11,9 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; import java.nio.charset.StandardCharsets; +import org.sqlite.jni.*; import org.sqlite.jni.annotation.*; /** diff --git a/ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java b/ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java similarity index 90% rename from ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java rename to ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java index eb4e05fdf8..0f8f3e551b 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java +++ b/ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java @@ -11,7 +11,8 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; +import org.sqlite.jni.NativePointerHolder; /** A wrapper for C-level Fts5PhraseIter. They are only modified and diff --git a/ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java b/ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java similarity index 92% rename from ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java rename to ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java index 0d266a13d8..1992438448 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java +++ b/ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java @@ -11,7 +11,8 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; +import org.sqlite.jni.NativePointerHolder; /** INCOMPLETE AND COMPLETELY UNTESTED. diff --git a/ext/jni/src/org/sqlite/jni/TesterFts5.java b/ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java similarity index 72% rename from ext/jni/src/org/sqlite/jni/TesterFts5.java rename to ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java index 5cbaed22c0..5c4742c72e 100644 --- a/ext/jni/src/org/sqlite/jni/TesterFts5.java +++ b/ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java @@ -11,9 +11,10 @@ ************************************************************************* ** This file contains a set of tests for the sqlite3 JNI bindings. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; import static org.sqlite.jni.SQLite3Jni.*; import static org.sqlite.jni.Tester1.*; +import org.sqlite.jni.*; public class TesterFts5 { @@ -35,8 +36,7 @@ public class TesterFts5 { }); final String pUserData = "This is pUserData"; - ValueHolder xDestroyCalled = new ValueHolder<>(false); - ValueHolder xFuncCount = new ValueHolder<>(0); + final int outputs[] = {0, 0}; final fts5_extension_function func = new fts5_extension_function(){ @Override public void call(Fts5ExtensionApi ext, Fts5Context fCx, sqlite3_context pCx, sqlite3_value argv[]){ @@ -58,42 +58,29 @@ public class TesterFts5 { rc = ext.xColumnTotalSize(fCx, i, colTotalSz); affirm( 0==rc ); } - ++xFuncCount.value; + ++outputs[0]; } public void xDestroy(){ - xDestroyCalled.value = true; + outputs[1] = 1; } }; int rc = fApi.xCreateFunction("myaux", pUserData, func); affirm( 0==rc ); - affirm( 0==xFuncCount.value ); + affirm( 0==outputs[0] ); execSql(db, "select myaux(ft,a,b) from ft;"); - affirm( 2==xFuncCount.value ); - affirm( !xDestroyCalled.value ); + affirm( 2==outputs[0] ); + affirm( 0==outputs[1] ); sqlite3_close_v2(db); - affirm( xDestroyCalled.value ); + affirm( 1==outputs[1] ); } - private void runTests(){ + private static synchronized void runTests(){ test1(); } - public TesterFts5(boolean verbose){ - if(verbose){ - synchronized(Tester1.class) { - final long timeStart = System.currentTimeMillis(); - final int oldAffirmCount = Tester1.affirmCount; - runTests(); - final int affirmCount = Tester1.affirmCount - oldAffirmCount; - final long timeEnd = System.currentTimeMillis(); - outln("FTS5 Tests done. Assertions checked = ",affirmCount, - ", Total time = ",(timeEnd - timeStart),"ms"); - } - }else{ - runTests(); - } + public TesterFts5(){ + runTests(); } - public TesterFts5(){ this(true); } } diff --git a/ext/jni/src/org/sqlite/jni/fts5_api.java b/ext/jni/src/org/sqlite/jni/fts5/fts5_api.java similarity index 97% rename from ext/jni/src/org/sqlite/jni/fts5_api.java rename to ext/jni/src/org/sqlite/jni/fts5/fts5_api.java index 854a0348b1..699941cade 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_api.java +++ b/ext/jni/src/org/sqlite/jni/fts5/fts5_api.java @@ -11,8 +11,9 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; import org.sqlite.jni.annotation.*; +import org.sqlite.jni.*; /** INCOMPLETE AND COMPLETELY UNTESTED. diff --git a/ext/jni/src/org/sqlite/jni/fts5_extension_function.java b/ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java similarity index 94% rename from ext/jni/src/org/sqlite/jni/fts5_extension_function.java rename to ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java index 9247003168..7ed353ac0b 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_extension_function.java +++ b/ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java @@ -11,7 +11,9 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; +package org.sqlite.jni.fts5; +import org.sqlite.jni.sqlite3_context; +import org.sqlite.jni.sqlite3_value; /** JNI-level wrapper for C's fts5_extension_function type. diff --git a/ext/jni/src/org/sqlite/jni/fts5_tokenizer.java b/ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java similarity index 94% rename from ext/jni/src/org/sqlite/jni/fts5_tokenizer.java rename to ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java index cd94dfa28c..dd5f78bd14 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_tokenizer.java +++ b/ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java @@ -11,8 +11,9 @@ ************************************************************************* ** This file is part of the JNI bindings for the sqlite3 C API. */ -package org.sqlite.jni; -import org.sqlite.jni.annotation.*; +package org.sqlite.jni.fts5; +import org.sqlite.jni.NativePointerHolder; +import org.sqlite.jni.annotation.NotNull; /** INCOMPLETE AND COMPLETELY UNTESTED. diff --git a/manifest b/manifest index 73e619873d..a99ecf9cfb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Java\sFTS5\sAPI\srenaming,\sfor\sconsistency. -D 2023-09-06T06:54:25.034 +C Move\sJava-side\sFTS5\sbits\sinto\sthe\sfts5\ssubpackage\sto\s(A)\smake\sit\seasy\sto\soptionally\sbundle\sit\s(or\snot)\sand\s(B)\sset\sa\sprecedent\sfor\sputing\sextension\sAPIs\sin\stheir\sown\spackage. +D 2023-09-06T07:39:25.264 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,11 +234,11 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 13a0d923fdbcbc363e5ed067423da3a19f6b25a49ae83ebddb00569f94b81b25 +F ext/jni/GNUmakefile 6881323b2e2753a73c3f1b04f4248bcbfc427751e8380e3d876f0916193a350b F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa -F ext/jni/src/c/sqlite3-jni.c 98f83a07c6956f51b9e758e1e560ad9826c67c1fe7f256e527293bd9808c4768 -F ext/jni/src/c/sqlite3-jni.h 875992ddf3a8c33d68a49ac26fbe2060f3ee98fb49127f140fed1e69f1da3be6 +F ext/jni/src/c/sqlite3-jni.c 438a0141b7be7e8081f23254efe4cb313170aeb0f12fc5dd2c5a42612111bfad +F ext/jni/src/c/sqlite3-jni.h 7880247be848310facc549d3296b620e3f971b4d2e6b1ec5a942f5f295d079fa F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436 F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38 @@ -250,11 +250,6 @@ F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 07df5fa161a0b811542952 F ext/jni/src/org/sqlite/jni/CommitHookCallback.java 77cf8bb4f5548113e9792978f3f8a454614f420fa0ad73939421cbff4e7776f2 F ext/jni/src/org/sqlite/jni/ConfigLogCallback.java 636ed6b89ed03f15bc2a6f6f47bf7853b8328e5a8269e52e80630708efa703a6 F ext/jni/src/org/sqlite/jni/ConfigSqllogCallback.java e3656909eab7ed0f7e457c5b82df160ca22dd5e954c0a306ec1fca61b0d266b4 -F ext/jni/src/org/sqlite/jni/Fts5.java 0ca3cb814cb92e1ec07ccda72bcdb7eb45615abbc155e515d1cda3ee1404143d -F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 -F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 24c7fb75c4464c2c3a893c31ec23a86a1bf5289fda8901a9cf4a923de42eea52 -F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 -F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 564087036449a16df148dcf0a067408bd251170bf23286c655f46b5f973e8b2d F ext/jni/src/org/sqlite/jni/OutputPointer.java 2f57c05672ddc9b38e3f8eed11759896cf0bf01107ffd24d5182b99f6e7254b6 F ext/jni/src/org/sqlite/jni/PreupdateHookCallback.java eccaed8dc9c6289f07ef3fc109891c6be1e7cc6c88723d90174b68706fc21cda @@ -265,8 +260,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java a1beb9f9953bfaf76824239d8f556c81a3d8ea81f89307817e17d2cb0cbf7c9c F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 79f64479297329cc98ad6401c506864750f5812449f896b696d6dbfa5af8355a -F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59 +F ext/jni/src/org/sqlite/jni/Tester1.java 0ead670d13b3a4e9579ccd21f5c49e43f64195db5d13facc3a10843be828b6a5 F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 @@ -275,9 +269,15 @@ F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0 F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d9b32956cb9fb11d1f8a562e5df70d0599820265285120c63858294dbe2b7711 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 -F ext/jni/src/org/sqlite/jni/fts5_api.java 386ecbcfcd03c24afbca52dc8bdf00791b6f2cbc0dd7be53e354071ada94f7bc -F ext/jni/src/org/sqlite/jni/fts5_extension_function.java bec9f17a7e784d57eca99d812a65ecc9dd74c8df62d6d90cc1ecb3e37de14d47 -F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java 1b48d45763c571b70b6a0b419780ec8a4163f97a684e326d6e93eb0cb596fa95 +F ext/jni/src/org/sqlite/jni/fts5/Fts5.java 3268fc61a15da5682e4e2130adbb1ae5385393c2f8a2ed408af806894b4a0625 w ext/jni/src/org/sqlite/jni/Fts5.java +F ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java 7058da97059b8e156c17561a47ecd7faa0fc3e2d8c2588b9a28dbff8d06202dd w ext/jni/src/org/sqlite/jni/Fts5Context.java +F ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java 3c337e5690c4de7f0d5478f53ca7ba326e776330eb511e607bd252a35b84d8f7 w ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java +F ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java 2a7f3d76a1206e6a43d4c4ed9609b294d5431cc7d8fb875d8419f76efa6e56dc w ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java +F ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java cc9a53846a168a215238af224c31cef0e8379780e36e8a5e743b00c08145cf19 w ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java +F ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java b5a805c2ecff5c89179133fd2a6ede90b8598796e3940afae4590c7b503d3917 w ext/jni/src/org/sqlite/jni/TesterFts5.java +F ext/jni/src/org/sqlite/jni/fts5/fts5_api.java 6071bf76c2c6a0f035b99adc76715b0324f540a441452b4ff6b94d9360a6a83d w ext/jni/src/org/sqlite/jni/fts5_api.java +F ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java 1fe0f5692c1d67475d12b067f0469949073446f18c56eba5ee5da6ddd06db9b9 w ext/jni/src/org/sqlite/jni/fts5_extension_function.java +F ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java 4b56f407977f08e456ea0c956fb657b4cd96ec4635cc4f7a1b7ef10cb2a21d7d w ext/jni/src/org/sqlite/jni/fts5_tokenizer.java F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_backup.java d0bb06dd6225e76999ff6b7ab20f2643b1c4d4167431b3a93ea41943e41f094b @@ -2117,8 +2117,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 d0df62f0af19a69f7ceb3ad1dceda0d8cc2ca5016a6e2a3a1e36356424c3ca49 -R 1c9c032947a0621b2a97abc848cee358 +P 5e4cc9f386364858c6457c40f13f01e1826a59086aa7f0fa10244ea846f5acfd +R 4f26d26cc2f0342d32c1a3b10bbbb150 U stephan -Z 2634b10b864fb044031f2a08908448d5 +Z 067320356ea8328be5c8395e90434c8f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d37b01c322..e82919303b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e4cc9f386364858c6457c40f13f01e1826a59086aa7f0fa10244ea846f5acfd \ No newline at end of file +4c773e1f331cd5854d4c6e8825197933c0bb6827b7437e56ac0ad650d1ddf55e \ No newline at end of file From 8ea10ea520ac063ac0c512c40f175876dcb9e320 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 9 Sep 2023 07:52:05 +0000 Subject: [PATCH 35/36] Disable FTS5 in the JNI build by default until it can be thoroughly tested. This is mainly so that the public-facing javadoc does not include it. FossilOrigin-Name: 6f25f02b70f561864264a71a85cb5efa05550743371fd655804033ea08d00f33 --- ext/jni/GNUmakefile | 12 +++++++--- ext/jni/src/org/sqlite/jni/Tester1.java | 2 +- manifest | 32 ++++++++++++------------- manifest.uuid | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 8997e0c12e..36fa43332d 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -51,8 +51,10 @@ SQLTester.class := $(SQLTester.java:.java=.class) ######################################################################## # The future of FTS5 customization in this API is as yet unclear. -# It would be a real doozy to bind to JNI. -enable.fts5 ?= 1 +# The pieces are all in place, and are all thin proxies so not much +# complexity, but some semantic changes were required in porting +# which are largely untested. +enable.fts5 ?= 0 # If enable.tester is 0, the org/sqlite/jni/tester/* bits are elided. enable.tester ?= $(if $(wildcard $(dir.src.jni.tester)/SQLTester.java),1,0) @@ -368,10 +370,14 @@ run-jar: $(package.jar) $(package.dll) # javadoc... dir.doc := $(dir.jni)/javadoc doc.index := $(dir.doc)/index.html +javadoc.exclude := -exclude org.sqlite.jni.tester +ifneq (1,$(enable.fts5)) + javadoc.exclude += -exclude org.sqlite.jni.fts5 +endif $(doc.index): $(JAVA_FILES.main) $(MAKEFILE) @if [ -d $(dir.doc) ]; then rm -fr $(dir.doc)/*; fi $(bin.javadoc) -cp $(classpath) -d $(dir.doc) -quiet \ - -subpackages org.sqlite.jni -exclude org.sqlite.jni.tester + -subpackages org.sqlite.jni $(javadoc.exclude) @echo "javadoc output is in $@" .PHONY: doc javadoc docserve diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index 5b007077bd..93a3174415 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1282,7 +1282,7 @@ public class Tester1 implements Runnable { final long timeStart = System.currentTimeMillis(); ctor.newInstance() /* will run all tests */; final long timeEnd = System.currentTimeMillis(); - outln("FTS5 Tests done in ",(timeEnd - timeStart),"ms"); + outln("FTS5 Tests done in ",(timeEnd - timeStart),"ms"); }catch(ClassNotFoundException e){ outln("FTS5 classes not loaded."); err = e; diff --git a/manifest b/manifest index a99ecf9cfb..4b175c8c08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sJava-side\sFTS5\sbits\sinto\sthe\sfts5\ssubpackage\sto\s(A)\smake\sit\seasy\sto\soptionally\sbundle\sit\s(or\snot)\sand\s(B)\sset\sa\sprecedent\sfor\sputing\sextension\sAPIs\sin\stheir\sown\spackage. -D 2023-09-06T07:39:25.264 +C Disable\sFTS5\sin\sthe\sJNI\sbuild\sby\sdefault\suntil\sit\scan\sbe\sthoroughly\stested.\sThis\sis\smainly\sso\sthat\sthe\spublic-facing\sjavadoc\sdoes\snot\sinclude\sit. +D 2023-09-09T07:52:05.442 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,7 +234,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 6881323b2e2753a73c3f1b04f4248bcbfc427751e8380e3d876f0916193a350b +F ext/jni/GNUmakefile 5747f8527812d6cfeb87e454e21a491b202779e5166f05ff8b83193eb1611a17 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa F ext/jni/src/c/sqlite3-jni.c 438a0141b7be7e8081f23254efe4cb313170aeb0f12fc5dd2c5a42612111bfad @@ -260,7 +260,7 @@ F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b F ext/jni/src/org/sqlite/jni/SQLite3Jni.java a1beb9f9953bfaf76824239d8f556c81a3d8ea81f89307817e17d2cb0cbf7c9c F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab -F ext/jni/src/org/sqlite/jni/Tester1.java 0ead670d13b3a4e9579ccd21f5c49e43f64195db5d13facc3a10843be828b6a5 +F ext/jni/src/org/sqlite/jni/Tester1.java a14f34e0404179b2920c20bca79ae178c71130e7c53aabe9a9e5c717850d2dfd F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0 F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c F ext/jni/src/org/sqlite/jni/WindowFunction.java 488980f4dbb6bdd7067d6cb9c43e4075475e51c54d9b74a5834422654b126246 @@ -269,15 +269,15 @@ F ext/jni/src/org/sqlite/jni/annotation/Canonical.java 2767daa5b3893b96729db80a0 F ext/jni/src/org/sqlite/jni/annotation/NotNull.java d9b32956cb9fb11d1f8a562e5df70d0599820265285120c63858294dbe2b7711 F ext/jni/src/org/sqlite/jni/annotation/Nullable.java 6f962a98c9a5c6e9d21c50ae8716b16bdfdc934a191608cbb7e12ea588ddb6af F ext/jni/src/org/sqlite/jni/annotation/package-info.java f66bfb621c6494e67c03ed38a9e26a3bd6af99b9f9f6ef79556bcec30a025a22 -F ext/jni/src/org/sqlite/jni/fts5/Fts5.java 3268fc61a15da5682e4e2130adbb1ae5385393c2f8a2ed408af806894b4a0625 w ext/jni/src/org/sqlite/jni/Fts5.java -F ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java 7058da97059b8e156c17561a47ecd7faa0fc3e2d8c2588b9a28dbff8d06202dd w ext/jni/src/org/sqlite/jni/Fts5Context.java -F ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java 3c337e5690c4de7f0d5478f53ca7ba326e776330eb511e607bd252a35b84d8f7 w ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java -F ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java 2a7f3d76a1206e6a43d4c4ed9609b294d5431cc7d8fb875d8419f76efa6e56dc w ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java -F ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java cc9a53846a168a215238af224c31cef0e8379780e36e8a5e743b00c08145cf19 w ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java -F ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java b5a805c2ecff5c89179133fd2a6ede90b8598796e3940afae4590c7b503d3917 w ext/jni/src/org/sqlite/jni/TesterFts5.java -F ext/jni/src/org/sqlite/jni/fts5/fts5_api.java 6071bf76c2c6a0f035b99adc76715b0324f540a441452b4ff6b94d9360a6a83d w ext/jni/src/org/sqlite/jni/fts5_api.java -F ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java 1fe0f5692c1d67475d12b067f0469949073446f18c56eba5ee5da6ddd06db9b9 w ext/jni/src/org/sqlite/jni/fts5_extension_function.java -F ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java 4b56f407977f08e456ea0c956fb657b4cd96ec4635cc4f7a1b7ef10cb2a21d7d w ext/jni/src/org/sqlite/jni/fts5_tokenizer.java +F ext/jni/src/org/sqlite/jni/fts5/Fts5.java 3268fc61a15da5682e4e2130adbb1ae5385393c2f8a2ed408af806894b4a0625 +F ext/jni/src/org/sqlite/jni/fts5/Fts5Context.java 7058da97059b8e156c17561a47ecd7faa0fc3e2d8c2588b9a28dbff8d06202dd +F ext/jni/src/org/sqlite/jni/fts5/Fts5ExtensionApi.java 3c337e5690c4de7f0d5478f53ca7ba326e776330eb511e607bd252a35b84d8f7 +F ext/jni/src/org/sqlite/jni/fts5/Fts5PhraseIter.java 2a7f3d76a1206e6a43d4c4ed9609b294d5431cc7d8fb875d8419f76efa6e56dc +F ext/jni/src/org/sqlite/jni/fts5/Fts5Tokenizer.java cc9a53846a168a215238af224c31cef0e8379780e36e8a5e743b00c08145cf19 +F ext/jni/src/org/sqlite/jni/fts5/TesterFts5.java b5a805c2ecff5c89179133fd2a6ede90b8598796e3940afae4590c7b503d3917 +F ext/jni/src/org/sqlite/jni/fts5/fts5_api.java 6071bf76c2c6a0f035b99adc76715b0324f540a441452b4ff6b94d9360a6a83d +F ext/jni/src/org/sqlite/jni/fts5/fts5_extension_function.java 1fe0f5692c1d67475d12b067f0469949073446f18c56eba5ee5da6ddd06db9b9 +F ext/jni/src/org/sqlite/jni/fts5/fts5_tokenizer.java 4b56f407977f08e456ea0c956fb657b4cd96ec4635cc4f7a1b7ef10cb2a21d7d F ext/jni/src/org/sqlite/jni/package-info.java a3946db2504de747a1993c4f6e8ce604bec5a8e5a134b292c3b07527bc321a99 F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc F ext/jni/src/org/sqlite/jni/sqlite3_backup.java d0bb06dd6225e76999ff6b7ab20f2643b1c4d4167431b3a93ea41943e41f094b @@ -2117,8 +2117,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 5e4cc9f386364858c6457c40f13f01e1826a59086aa7f0fa10244ea846f5acfd -R 4f26d26cc2f0342d32c1a3b10bbbb150 +P 4c773e1f331cd5854d4c6e8825197933c0bb6827b7437e56ac0ad650d1ddf55e +R fea65675bc6031bd63acb193611317be U stephan -Z 067320356ea8328be5c8395e90434c8f +Z 0e1bc36bc0c5e207b09e65fd958851e4 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e82919303b..11cf3a484c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c773e1f331cd5854d4c6e8825197933c0bb6827b7437e56ac0ad650d1ddf55e \ No newline at end of file +6f25f02b70f561864264a71a85cb5efa05550743371fd655804033ea08d00f33 \ No newline at end of file From 8f825a7a1b2792f6ec1b7aa4115714a284fc1fa6 Mon Sep 17 00:00:00 2001 From: stephan Date: Sat, 9 Sep 2023 11:20:35 +0000 Subject: [PATCH 36/36] In the JNI build, emit a reminder to not check in the javac-generated sqlite3-jni.h when FTS5 is disabled because changes in that feature flag result in unnecessary and large diffs in checked-in generated code. FossilOrigin-Name: caceb52fb58f924e7cbbebac05e7fd7822b7f6f56a3f834392d2be801bf04633 --- ext/jni/GNUmakefile | 22 +++++++++++++++------- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ext/jni/GNUmakefile b/ext/jni/GNUmakefile index 36fa43332d..ce9df06d49 100644 --- a/ext/jni/GNUmakefile +++ b/ext/jni/GNUmakefile @@ -27,6 +27,7 @@ dir.bld := $(dir.jni)/bld dir.bld.c := $(dir.bld) dir.src.jni := $(dir.src)/org/sqlite/jni dir.src.jni.tester := $(dir.src.jni)/tester +dir.src.fts5 := $(dir.src.jni)/fts5 mkdir ?= mkdir -p $(dir.bld.c): $(mkdir) $@ @@ -54,6 +55,11 @@ SQLTester.class := $(SQLTester.java:.java=.class) # The pieces are all in place, and are all thin proxies so not much # complexity, but some semantic changes were required in porting # which are largely untested. +# +# Reminder: this flag influences the contents of $(sqlite3-jni.h), +# which is checked in. Please do not check in changes to that file in +# which the fts5 APIs have been stripped unless that feature is +# intended to be stripped for good. enable.fts5 ?= 0 # If enable.tester is 0, the org/sqlite/jni/tester/* bits are elided. enable.tester ?= $(if $(wildcard $(dir.src.jni.tester)/SQLTester.java),1,0) @@ -105,7 +111,6 @@ JAVA_FILES.unittest := $(patsubst %,$(dir.src.jni)/%,\ Tester1.java \ ) ifeq (1,$(enable.fts5)) - dir.src.fts5 := $(dir.src.jni)/fts5 JAVA_FILES.main += $(patsubst %,$(dir.src.fts5)/%,\ fts5_api.java \ fts5_extension_function.java \ @@ -221,16 +226,15 @@ java.with.jni := define ADD_JNI_H sqlite3-jni.h.in += $$(dir.bld.c)/org_sqlite_jni$(3)_$(2).h java.with.jni += $(1)/$(2).java -$$(info x=$(1)/$(2).java) $$(dir.bld.c)/org_sqlite_jni$(3)_$(2).h: $(1)/$(2).java endef # Invoke ADD_JNI_H once for each Java file which includes JNI # declarations: $(eval $(call ADD_JNI_H,$(dir.src.jni),SQLite3Jni,)) -ifeq (1,$(enable.fts5)) - $(eval $(call ADD_JNI_H,$(dir.src.fts5),Fts5ExtensionApi,_fts5)) - $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_api,_fts5)) - $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_tokenizer,_fts5)) +ifeq (,$(enable.fts5)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),Fts5ExtensionApi,_fts5)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_api,_fts5)) + $(eval $(call ADD_JNI_H,$(dir.src.fts5),fts5_tokenizer,_fts5)) endif ifeq (1,$(enable.tester)) $(eval $(call ADD_JNI_H,$(dir.src.jni.tester),SQLTester,_tester)) @@ -259,13 +263,17 @@ ifeq (1,$(enable.tester)) endif $(sqlite3-jni.h): $(sqlite3-jni.h.in) $(MAKEFILE) @cat $(sqlite3-jni.h.in) > $@.tmp - @if cmp $@ $@.tmp; then \ + @if cmp $@ $@.tmp >/dev/null; then \ rm -f $@.tmp; \ echo "$@ not modified"; \ else \ mv $@.tmp $@; \ echo "Updated $@"; \ fi + @if [ x1 != x$(enable.fts5) ]; then \ + echo "*** REMINDER:"; \ + echo "*** enable.fts5=0, so please do not check in changes to $@."; \ + fi $(package.dll): $(sqlite3-jni.h) $(sqlite3.c) $(sqlite3.h) $(package.dll): $(sqlite3-jni.c) $(MAKEFILE) diff --git a/manifest b/manifest index 4b175c8c08..96e075e3e3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sFTS5\sin\sthe\sJNI\sbuild\sby\sdefault\suntil\sit\scan\sbe\sthoroughly\stested.\sThis\sis\smainly\sso\sthat\sthe\spublic-facing\sjavadoc\sdoes\snot\sinclude\sit. -D 2023-09-09T07:52:05.442 +C In\sthe\sJNI\sbuild,\semit\sa\sreminder\sto\snot\scheck\sin\sthe\sjavac-generated\ssqlite3-jni.h\swhen\sFTS5\sis\sdisabled\sbecause\schanges\sin\sthat\sfeature\sflag\sresult\sin\sunnecessary\sand\slarge\sdiffs\sin\schecked-in\sgenerated\scode. +D 2023-09-09T11:20:35.287 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -234,7 +234,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 -F ext/jni/GNUmakefile 5747f8527812d6cfeb87e454e21a491b202779e5166f05ff8b83193eb1611a17 +F ext/jni/GNUmakefile 4c17706c4cfb228ae15b8ad102d03c0d2c73e238283beb78bf16f2e169f8b5d8 F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9 F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa F ext/jni/src/c/sqlite3-jni.c 438a0141b7be7e8081f23254efe4cb313170aeb0f12fc5dd2c5a42612111bfad @@ -2117,8 +2117,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 4c773e1f331cd5854d4c6e8825197933c0bb6827b7437e56ac0ad650d1ddf55e -R fea65675bc6031bd63acb193611317be +P 6f25f02b70f561864264a71a85cb5efa05550743371fd655804033ea08d00f33 +R f22f4a812c24f83688caa4bfc7503f7a U stephan -Z 0e1bc36bc0c5e207b09e65fd958851e4 +Z 971962c4cee26a6c821e73047cd57ddc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 11cf3a484c..bc48f5e526 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f25f02b70f561864264a71a85cb5efa05550743371fd655804033ea08d00f33 \ No newline at end of file +caceb52fb58f924e7cbbebac05e7fd7822b7f6f56a3f834392d2be801bf04633 \ No newline at end of file