From: stephan Date: Sun, 30 Jul 2023 09:45:54 +0000 (+0000) Subject: Incremental checkin to minimize the diff while narrowing in on an assertion caused... X-Git-Tag: version-3.43.0~47^2~129 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c113744d151b38a9b8fabbb119233ed0555ad41;p=thirdparty%2Fsqlite.git Incremental checkin to minimize the diff while narrowing in on an assertion caused by refactoring. FossilOrigin-Name: 2d7a91b1396d87852f1153ab7af7385514a9537cb64ba3bbd0faba2d28704214 --- diff --git a/ext/jni/README.md b/ext/jni/README.md index d62eddf6a7..b77f79a3f3 100644 --- a/ext/jni/README.md +++ b/ext/jni/README.md @@ -93,9 +93,9 @@ conversion in Java, and there is no JNI C API for that conversion Known consequences and limitations of this discrepancy include: -- Database and table names must not contain characters which differ - in MUTF-8 and UTF-8, or certain APIs will mis-translate them on - their way between languages. +- Names of databases, tables, and collations must not contain + characters which differ in MUTF-8 and UTF-8, or certain APIs will + mis-translate them on their way between languages. [modutf8]: https://docs.oracle.com/javase/8/docs/api/java/io/DataInput.html#modified-utf-8 diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 21c768e5d6..66384ef673 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -366,6 +366,7 @@ typedef struct PerDbStateJni PerDbStateJni; struct PerDbStateJni { JNIEnv *env; sqlite3 * pDb; + jobject jDb /* the object which was passed to sqlite3_open(_v2)() */; PerDbStateJni * pNext; PerDbStateJni * pPrev; JniHookState trace; @@ -484,117 +485,6 @@ static int BusyHandlerJni_init(JNIEnv * const env, BusyHandlerJni * const s, return 0; } -/** - Extracts the new PerDbStateJni instance from the free-list, or - allocates one if needed, associats it with pDb, and returns. - Returns NULL on OOM. -*/ -static PerDbStateJni * PerDbStateJni_alloc(JNIEnv *env, sqlite3 *pDb){ - PerDbStateJni * rv; - assert( pDb ); - if(S3Global.perDb.aFree){ - rv = S3Global.perDb.aFree; - S3Global.perDb.aFree = rv->pNext; - if(rv->pNext){ - assert(rv->pNext->pPrev == rv); - assert(rv->pNext == rv->pNext->pPrev); - rv->pNext->pPrev = 0; - rv->pNext = 0; - } - }else{ - rv = s3jni_malloc(env, sizeof(PerDbStateJni)); - if(rv){ - memset(rv, 0, sizeof(PerDbStateJni)); - } - } - if(rv){ - rv->pNext = S3Global.perDb.aUsed; - S3Global.perDb.aUsed = rv; - if(rv->pNext){ - assert(!rv->pNext->pPrev); - rv->pNext->pPrev = rv; - } - rv->pDb = pDb; - rv->env = env; - } - return rv; -} - -/** - Clears s's state and moves it to the free-list. -*/ -FIXME_THREADING -static void PerDbStateJni_set_aside(PerDbStateJni * const s){ - if(s){ - JNIEnv * const env = s->env; - assert(s->pDb && "Else this object is already in the free-list."); - if(s->pNext) s->pNext->pPrev = s->pPrev; - if(s->pPrev) s->pPrev->pNext = s->pNext; - else if(S3Global.perDb.aUsed == s){ - assert(!s->pPrev); - S3Global.perDb.aUsed = s->pNext; - } - UNREF_G(s->trace.jObj); - UNREF_G(s->progress.jObj); - UNREF_G(s->commitHook.jObj); - UNREF_G(s->rollbackHook.jObj); - BusyHandlerJni_clear(&s->busyHandler); - memset(s, 0, sizeof(PerDbStateJni)); - s->pNext = S3Global.perDb.aFree; - S3Global.perDb.aFree = s; - } -} - -static void PerDbStateJni_dump(PerDbStateJni *s){ - MARKER(("PerDbStateJni->env @ %p\n", s->env)); - MARKER(("PerDbStateJni->pDb @ %p\n", s->pDb)); - MARKER(("PerDbStateJni->trace.jObj @ %p\n", s->trace.jObj)); - MARKER(("PerDbStateJni->progress.jObj @ %p\n", s->progress.jObj)); - MARKER(("PerDbStateJni->commitHook.jObj @ %p\n", s->commitHook.jObj)); - MARKER(("PerDbStateJni->rollbackHook.jObj @ %p\n", s->rollbackHook.jObj)); - MARKER(("PerDbStateJni->busyHandler.env @ %p\n", s->busyHandler.env)); - MARKER(("PerDbStateJni->busyHandler.jObj @ %p\n", s->busyHandler.jObj)); - MARKER(("PerDbStateJni->env @ %p\n", s->env)); -} - -/** - Returns the PerDbStateJni object for the given db. If allocIfNeeded is - true then a new instance will be allocated if no mapping currently - exists, else NULL is returned if no mapping is found. - -*/ -FIXME_THREADING -static PerDbStateJni * PerDbStateJni_for_db(JNIEnv *env, sqlite3 *pDb, int allocIfNeeded){ - PerDbStateJni * s = S3Global.perDb.aUsed; - for( ; s; s = s->pNext){ - if(s->pDb == pDb) return s; - } - if(allocIfNeeded) s = PerDbStateJni_alloc(env, pDb); - return s; -} - -/** - Cleans up and frees all state in S3Global.perDb. -*/ -FIXME_THREADING -static void PerDbStateJni_free_all(void){ - PerDbStateJni * pS = S3Global.perDb.aUsed; - PerDbStateJni * pSNext = 0; - for( ; pS; pS = pSNext ){ - pSNext = pS->pNext; - PerDbStateJni_set_aside(pS); - assert(pSNext ? !pSNext->pPrev : 1); - } - assert( 0==S3Global.perDb.aUsed ); - pS = S3Global.perDb.aFree; - S3Global.perDb.aFree = 0; - pSNext = 0; - for( ; pS; pS = pSNext ){ - pSNext = pS->pNext; - s3jni_free(pSNext); - } -} - /** Fetches the S3Global.envCache row for the given env, allocing a row if needed. When a row is allocated, its state is initialized @@ -751,6 +641,118 @@ static void * getNativePointer(JNIEnv * env, jobject pObj, const char *zClassNam } } +/** + Extracts the new PerDbStateJni instance from the free-list, or + allocates one if needed, associats it with pDb, and returns. + Returns NULL on OOM. +*/ +static PerDbStateJni * PerDbStateJni_alloc(JNIEnv *env, sqlite3 *pDb){ + PerDbStateJni * rv; + assert( pDb ); + if(S3Global.perDb.aFree){ + rv = S3Global.perDb.aFree; + S3Global.perDb.aFree = rv->pNext; + if(rv->pNext){ + assert(rv->pNext->pPrev == rv); + assert(rv->pNext == rv->pNext->pPrev); + rv->pNext->pPrev = 0; + rv->pNext = 0; + } + }else{ + rv = s3jni_malloc(env, sizeof(PerDbStateJni)); + if(rv){ + memset(rv, 0, sizeof(PerDbStateJni)); + } + } + if(rv){ + rv->pNext = S3Global.perDb.aUsed; + S3Global.perDb.aUsed = rv; + if(rv->pNext){ + assert(!rv->pNext->pPrev); + rv->pNext->pPrev = rv; + } + rv->pDb = pDb; + rv->env = env; + } + return rv; +} + +/** + Clears s's state and moves it to the free-list. +*/ +FIXME_THREADING +static void PerDbStateJni_set_aside(PerDbStateJni * const s){ + if(s){ + JNIEnv * const env = s->env; + assert(s->pDb && "Else this object is already in the free-list."); + if(s->pNext) s->pNext->pPrev = s->pPrev; + if(s->pPrev) s->pPrev->pNext = s->pNext; + else if(S3Global.perDb.aUsed == s){ + assert(!s->pPrev); + S3Global.perDb.aUsed = s->pNext; + } + UNREF_G(s->trace.jObj); + UNREF_G(s->progress.jObj); + UNREF_G(s->commitHook.jObj); + UNREF_G(s->rollbackHook.jObj); + UNREF_G(s->jDb); + BusyHandlerJni_clear(&s->busyHandler); + memset(s, 0, sizeof(PerDbStateJni)); + s->pNext = S3Global.perDb.aFree; + S3Global.perDb.aFree = s; + } +} + +static void PerDbStateJni_dump(PerDbStateJni *s){ + MARKER(("PerDbStateJni->env @ %p\n", s->env)); + MARKER(("PerDbStateJni->pDb @ %p\n", s->pDb)); + MARKER(("PerDbStateJni->trace.jObj @ %p\n", s->trace.jObj)); + MARKER(("PerDbStateJni->progress.jObj @ %p\n", s->progress.jObj)); + MARKER(("PerDbStateJni->commitHook.jObj @ %p\n", s->commitHook.jObj)); + MARKER(("PerDbStateJni->rollbackHook.jObj @ %p\n", s->rollbackHook.jObj)); + MARKER(("PerDbStateJni->busyHandler.env @ %p\n", s->busyHandler.env)); + MARKER(("PerDbStateJni->busyHandler.jObj @ %p\n", s->busyHandler.jObj)); + MARKER(("PerDbStateJni->env @ %p\n", s->env)); +} + +/** + Returns the PerDbStateJni object for the given db. If allocIfNeeded is + true then a new instance will be allocated if no mapping currently + exists, else NULL is returned if no mapping is found. + +*/ +FIXME_THREADING +static PerDbStateJni * PerDbStateJni_for_db(JNIEnv *env, sqlite3 *pDb, int allocIfNeeded){ + PerDbStateJni * s = S3Global.perDb.aUsed; + for( ; s; s = s->pNext){ + if(s->pDb == pDb) return s; + } + if(allocIfNeeded) s = PerDbStateJni_alloc(env, pDb); + return s; +} + +/** + Cleans up and frees all state in S3Global.perDb. +*/ +FIXME_THREADING +static void PerDbStateJni_free_all(void){ + PerDbStateJni * pS = S3Global.perDb.aUsed; + PerDbStateJni * pSNext = 0; + for( ; pS; pS = pSNext ){ + pSNext = pS->pNext; + PerDbStateJni_set_aside(pS); + assert(pSNext ? !pSNext->pPrev : 1); + } + assert( 0==S3Global.perDb.aUsed ); + pS = S3Global.perDb.aFree; + S3Global.perDb.aFree = 0; + pSNext = 0; + for( ; pS; pS = pSNext ){ + pSNext = pS->pNext; + s3jni_free(pSNext); + } +} + /** Requires that jCx be a Java-side sqlite3_context wrapper for pCx. This function calls sqlite3_aggregate_context() to allocate a tiny diff --git a/ext/jni/src/org/sqlite/jni/CollationNeeded.java b/ext/jni/src/org/sqlite/jni/CollationNeeded.java new file mode 100644 index 0000000000..a9f64dc91d --- /dev/null +++ b/ext/jni/src/org/sqlite/jni/CollationNeeded.java @@ -0,0 +1,32 @@ +/* +** 2023-07-30 +** +** 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; + +/** + Callback proxy for use with sqlite3_collation_needed(). +*/ +public interface CollationNeeded { + /** + Works as documented for the sqlite3_create_collation() callback. + Must not throw. + + Achtung: the first argument to this function is not guaranteed to + be the same object upon which ealier DB operations have been + performed, e.g. not the one passed to sqlite3_collation_needed(), + but it will refer to the same underlying C-level database + pointer. This quirk is a side effect of how per-db state is + managed in the JNI layer. + */ + int xCollationNeeded(sqlite3 db, int eTextRep, String collationName); +} diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 3e9fcab17f..c32128284e 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -254,13 +254,6 @@ public final class SQLite3Jni { int eTextRep, @NotNull Collation col); - //! Convenience overload which assumes SQLITE_UTF8 encoding. - public static int sqlite3_create_collation(@NotNull sqlite3 db, - @NotNull String name, - @NotNull Collation col){ - return sqlite3_create_collation(db, name, SQLITE_UTF8, col); - } - public static native int sqlite3_create_function(@NotNull sqlite3 db, @NotNull String functionName, int nArg, int eTextRep, diff --git a/manifest b/manifest index b22827fcbc..131b57da31 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Consolidate\ssome\swarnings\sfor\sjava\scallbacks\swhich\smust\snot\sthrow\sbut\sdo. -D 2023-07-30T08:12:15.621 +C Incremental\scheckin\sto\sminimize\sthe\sdiff\swhile\snarrowing\sin\son\san\sassertion\scaused\sby\srefactoring. +D 2023-07-30T09:45:54.025 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -231,18 +231,19 @@ F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f4 F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/jni/GNUmakefile 56a014dbff9516774d895ec1ae9df0ed442765b556f79a0fc0b5bc438217200d -F ext/jni/README.md ffbf87660efb7428d2b8aa644da1ddb4a3f4ac414936a9a44ce34a3899e12520 -F ext/jni/src/c/sqlite3-jni.c 22ea3fef5e6376e4dcc94690f89034ebcb60a743608f56a57db5e561d9c166ac +F ext/jni/README.md c0e6e80935e7761acead89b69c87765b23a6bcb2858c321c3d05681fd338292a +F ext/jni/src/c/sqlite3-jni.c 5b5631520dd2e3ae6890bcbbee2aad3d7b5c404e96ae826b661e1105d2d2a69d F ext/jni/src/c/sqlite3-jni.h 85345dd3c970b539f1de4e6ad59c245fa6e80ca775a498ab1ed3d67f8615ce34 F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c F ext/jni/src/org/sqlite/jni/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1 +F ext/jni/src/org/sqlite/jni/CollationNeeded.java 15ca4e92b669c6412594120a9379459cd3e6e9e8ffba18c8698d879ce1142c91 F ext/jni/src/org/sqlite/jni/CommitHook.java 87c6a8e5138c61a8eeff018fe16d23f29219150239746032687f245938baca1a F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 70dc7bc41f80352ff3d4331e2e24f45fcd23353b3641e2f68a81bd8262215861 F ext/jni/src/org/sqlite/jni/OutputPointer.java 08a752b58a33696c5eaf0eb9361a0966b188dec40f4a3613eb133123951f6c5f F ext/jni/src/org/sqlite/jni/ProgressHandler.java 5979450e996416d28543f1d42634d308439565a99332a8bd84e424af667116cc F ext/jni/src/org/sqlite/jni/RollbackHook.java b04c8abcc6ade44a8a57129e33765793f69df0ba909e49ba18d73f4268d92564 F ext/jni/src/org/sqlite/jni/SQLFunction.java 663a4e479ec65bfbf893586439e12d30b8237898064a22ab64f5658b57315f37 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 50577e5d727ca3f53b2991988a2a0203b9ead199af60814b89f34edf98aa8d5a +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e64bae3357cc16f9416926539e2aa08fbb5a35022a828a158cfdd3e310575324 F ext/jni/src/org/sqlite/jni/Tester1.java 2d43b851db4189e54527e7fb4d50493c8efaa6c0781d0f5cc7f249c95b48ce3b F ext/jni/src/org/sqlite/jni/Tracer.java c2fe1eba4a76581b93b375a7b95ab1919e5ae60accfb06d6beb067b033e9bae1 F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d @@ -2070,8 +2071,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a5bbaa9017839f8d8b92bfb44472d4c60fa3037bfae7846dc8350262c1332cde -R 69bedfdee9cbb57a819c3589052e05da +P 5e592ed2dfc89225fff3a1c76509adc799a238282413984e0c4b32af18525d18 +R a4ee8dd84c4c810bd2a0b503fc8278d5 U stephan -Z feadd29e0fce2b9e30dbc845dba21259 +Z f4150e59d6c4033aef1bd32347c40f57 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8880ba10c1..be036f7c53 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5e592ed2dfc89225fff3a1c76509adc799a238282413984e0c4b32af18525d18 \ No newline at end of file +2d7a91b1396d87852f1153ab7af7385514a9537cb64ba3bbd0faba2d28704214 \ No newline at end of file