From: stephan Date: Mon, 7 Aug 2023 00:29:38 +0000 (+0000) Subject: Minor internal cleanups and additional test metrics. X-Git-Tag: version-3.43.0~47^2~82 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=005baf67d5f3bddef1d9fc9bd74e48d0206da40e;p=thirdparty%2Fsqlite.git Minor internal cleanups and additional test metrics. FossilOrigin-Name: fa0a6b6e8e6c711585bca30357e465f7a2f08a1c7159ecf23031af1e5158b89d --- diff --git a/ext/jni/src/c/sqlite3-jni.c b/ext/jni/src/c/sqlite3-jni.c index 054b04484f..71e0ab8cf1 100644 --- a/ext/jni/src/c/sqlite3-jni.c +++ b/ext/jni/src/c/sqlite3-jni.c @@ -1103,6 +1103,7 @@ static PerDbStateJni * PerDbStateJni_alloc(JNIEnv * const env, sqlite3 *pDb, return rv; } +#if 0 static void PerDbStateJni_dump(PerDbStateJni *s){ MARKER(("PerDbStateJni->env @ %p\n", s->env)); MARKER(("PerDbStateJni->pDb @ %p\n", s->pDb)); @@ -1113,6 +1114,7 @@ static void PerDbStateJni_dump(PerDbStateJni *s){ MARKER(("PerDbStateJni->busyHandler.jObj @ %p\n", s->busyHandler.jObj)); MARKER(("PerDbStateJni->env @ %p\n", s->env)); } +#endif /** Returns the PerDbStateJni object for the given db. If allocIfNeeded is @@ -1554,7 +1556,8 @@ typedef void (*udf_xFinal_f)(sqlite3_context*); /** State for binding Java-side UDFs. */ -typedef struct { +typedef struct UDFState UDFState; +struct UDFState { JNIEnv * env; /* env registered from */; jobject jObj /* SQLFunction instance */; jclass klazz /* jObj's class */; @@ -1566,7 +1569,7 @@ typedef struct { jmethodID jmidxFinal; jmethodID jmidxValue; jmethodID jmidxInverse; -} UDFState; +}; static UDFState * UDFState_alloc(JNIEnv * const env, jobject jObj){ UDFState * const s = sqlite3_malloc(sizeof(UDFState)); @@ -2019,18 +2022,13 @@ static jint s3jni_close_db(JNIEnv * const env, jobject jDb, int version){ int rc = 0; PerDbStateJni * ps = 0; assert(version == 1 || version == 2); - if(0){ - PerDbStateJni * s = S3Global.perDb.aUsed; - for( ; s; s = s->pNext){ - PerDbStateJni_dump(s); - } - } ps = PerDbStateJni_for_db(env, jDb, 0, 0); - if(!ps) return rc; - rc = 1==version ? (jint)sqlite3_close(ps->pDb) : (jint)sqlite3_close_v2(ps->pDb); - if(ps) PerDbStateJni_set_aside(ps) - /* MUST come after close() because of ps->trace. */; - NativePointerHolder_set(env, jDb, 0, S3ClassNames.sqlite3); + if(ps){ + rc = 1==version ? (jint)sqlite3_close(ps->pDb) : (jint)sqlite3_close_v2(ps->pDb); + PerDbStateJni_set_aside(ps) + /* MUST come after close() because of ps->trace. */; + NativePointerHolder_set(env, jDb, 0, S3ClassNames.sqlite3); + } return (jint)rc; } @@ -2053,15 +2051,18 @@ static unsigned int s3jni_utf16_strlen(void const * z){ return i; } +/** + sqlite3_collation_needed16() hook impl. + */ static void s3jni_collation_needed_impl16(void *pState, sqlite3 *pDb, int eTextRep, const void * z16Name){ PerDbStateJni * const ps = pState; JNIEnv * const env = ps->env; unsigned int const nName = s3jni_utf16_strlen(z16Name); - jstring jName; - jName = (*env)->NewString(env, (jchar const *)z16Name, nName); - IFTHREW { + jstring jName = (*env)->NewString(env, (jchar const *)z16Name, nName); + IFTHREW{ s3jni_db_error(ps->pDb, SQLITE_NOMEM, 0); + EXCEPTION_CLEAR; }else{ (*env)->CallVoidMethod(env, ps->collationNeeded.jObj, ps->collationNeeded.midCallback, @@ -2082,7 +2083,8 @@ JDECL(jint,1collation_1needed)(JENV_CSELF, jobject jDb, jobject jHook){ jmethodID xCallback; JniHookState * const pHook = &ps->collationNeeded; int rc; - if(!ps) return SQLITE_MISUSE; + + if( !ps ) return SQLITE_MISUSE; pOld = pHook->jObj; if(pOld && jHook && (*env)->IsSameObject(env, pOld, jHook)){ @@ -3291,13 +3293,15 @@ JDECL(void,1do_1something_1for_1developer)(JENV_CSELF){ puts("sizeofs:"); #define SO(T) printf("\tsizeof(" #T ") = %u\n", (unsigned)sizeof(T)) SO(void*); - SO(JniHookState); SO(JNIEnvCache); + SO(JniHookState); SO(PerDbStateJni); - SO(S3Global); SO(S3ClassNames); printf("\t(^^^ %u NativePointerHolder subclasses)\n", (unsigned)(sizeof(S3ClassNames) / sizeof(const char *))); + SO(S3Global); + SO(S3JniAutoExtension); + SO(UDFState); printf("Cache info:\n"); printf("\tNativePointerHolder cache: %u misses, %u hits\n", S3Global.metrics.nphCacheMisses, diff --git a/ext/jni/src/org/sqlite/jni/AutoExtension.java b/ext/jni/src/org/sqlite/jni/AutoExtension.java index 9816a967c2..3a58b6589f 100644 --- a/ext/jni/src/org/sqlite/jni/AutoExtension.java +++ b/ext/jni/src/org/sqlite/jni/AutoExtension.java @@ -21,9 +21,9 @@ public interface AutoExtension { Must function as described for the sqlite3_auto_extension(), with the caveat that the signature is more limited. - As an exception to the callbacks-must-not-throw rule, - AutoExtensions may do so and the exception's error - message will be set as the db's error string. + As an exception (as it were) to the callbacks-must-not-throw + rule, AutoExtensions may do so and the exception's error message + will be set as the db's error string. */ int xEntryPoint(sqlite3 db); } diff --git a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java index 303ab96662..6a72dd8739 100644 --- a/ext/jni/src/org/sqlite/jni/SQLite3Jni.java +++ b/ext/jni/src/org/sqlite/jni/SQLite3Jni.java @@ -475,6 +475,11 @@ public final class SQLite3Jni { heed. Passing the object to sqlite3_close() or sqlite3_close_v2() will clear that pointer mapping. + Recall that even if opening fails, the output pointer might be + non-null. Any error message about the failure will be in that + object and it is up to the caller to sqlite3_close() that + db handle. + Pedantic note: though any number of Java-level sqlite3 objects may refer to/wrap a single C-level (sqlite3*), the JNI internals take a reference to the object which is passed to sqlite3_open() diff --git a/ext/jni/src/org/sqlite/jni/Tester1.java b/ext/jni/src/org/sqlite/jni/Tester1.java index f956554a4a..b6058d0c77 100644 --- a/ext/jni/src/org/sqlite/jni/Tester1.java +++ b/ext/jni/src/org/sqlite/jni/Tester1.java @@ -1076,6 +1076,26 @@ public class Tester1 { outln("Tests done. Metrics:"); outln("\tAssertions checked: "+affirmCount); outln("\tDatabases opened: "+metrics.dbOpen); + + int nMethods = 0; + int nNatives = 0; + final java.lang.reflect.Method[] declaredMethods = + SQLite3Jni.class.getDeclaredMethods(); + for(java.lang.reflect.Method m : declaredMethods){ + int mod = m.getModifiers(); + if( 0!=(mod & java.lang.reflect.Modifier.STATIC) ){ + final String name = m.getName(); + if(name.startsWith("sqlite3_")){ + ++nMethods; + if( 0!=(mod & java.lang.reflect.Modifier.NATIVE) ){ + ++nNatives; + } + } + } + } + outln("\tSQLite3Jni sqlite3_*() methods: "+ + nNatives+" native methods and "+ + (nMethods - nNatives)+" Java impls"); outln("\tTotal time = " +((timeEnd - timeStart)/1000000.0)+"ms"); } diff --git a/manifest b/manifest index 0e7118626b..51c83aa0b0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bind\sthe\sauto-extension\sAPIs\sto\sJNI. -D 2023-08-07T00:06:31.250 +C Minor\sinternal\scleanups\sand\sadditional\stest\smetrics. +D 2023-08-07T00:29:38.785 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -232,10 +232,10 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/jni/GNUmakefile 61d9bbc179a49523a142928455b3297779b9c40f25783ecf1538279e426cbc99 F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d -F ext/jni/src/c/sqlite3-jni.c 406f3fe36661b3628d108a912246b48cafd7fcc1f8b30a563ce6806addb30d71 +F ext/jni/src/c/sqlite3-jni.c a59464adb77c0d2c539483b4d09b8c547dc97c73cf7f26b4934602c8cd4da28d F ext/jni/src/c/sqlite3-jni.h 68d219dd351676e819deb38926ebcee0fda141403ce4efa60c3d8bd77993d220 F ext/jni/src/org/sqlite/jni/Authorizer.java 1308988f7f40579ea0e4deeaec3c6be971630566bd021c31367fe3f5140db892 -F ext/jni/src/org/sqlite/jni/AutoExtension.java aac84ec21c93306ff5c6ff3b0130de5b76f265dfbc8f7cd158d62cfb8384ff57 +F ext/jni/src/org/sqlite/jni/AutoExtension.java 3409ad8954d6466bf772e6be9379e0e337312b446b668287062845755a16844d 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 ebc7cd96d46a70daa76016a308e80f70a3f21d3282787c8d139aa840fdcb1bd7 @@ -251,8 +251,8 @@ F ext/jni/src/org/sqlite/jni/OutputPointer.java 053ea7dbc1234dd70b8948009a52a3f1 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 09ce81c1c637e31c3a830d4c859cce95d65f5e02ff45f8bd1985b3479381bc46 -F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 9af0e0ea79db59d5c4dac13f70031dd5069223d8198f7324f8c1c25e60451e8c -F ext/jni/src/org/sqlite/jni/Tester1.java 63fc2f58b3a5abdad8bd41ff4a1b2572c24fa9246c17a3fcab07dc6adf06ff35 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e43d17ef7601d6294fa5ba7e15a2be2bcb819b41f4fe0ac069ce45e324b5a928 +F ext/jni/src/org/sqlite/jni/Tester1.java 762c866e3c401f8de2551e8bdc5252f5943693fe6bbbace82c3af984c190a0fd F ext/jni/src/org/sqlite/jni/TesterFts5.java cf2d687baafffdeba219b77cf611fd47a0556248820ea794ae3e8259bfbdc5ee F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d F ext/jni/src/org/sqlite/jni/UpdateHook.java e58645a1727f8a9bbe72dc072ec5b40d9f9362cb0aa24acfe93f49ff56a9016d @@ -2083,8 +2083,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 34da294ab558880e81eebd7d261bc590551d5a7d2855e844695cef6394647ea7 -R 8af70828073a693d0f965376a6f73a57 +P 746a5fa079ad80b3c59411202ee601e0b5c50e79e5994d5e464fa06d3c276324 +R 07d630346a076501319c1423eea49390 U stephan -Z 18db46b387e0d752e217b2db93c72ada +Z bdddfbdfa46e3004c7cc7a21bdb63878 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e8b32b32ff..a91b36d746 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -746a5fa079ad80b3c59411202ee601e0b5c50e79e5994d5e464fa06d3c276324 \ No newline at end of file +fa0a6b6e8e6c711585bca30357e465f7a2f08a1c7159ecf23031af1e5158b89d \ No newline at end of file