1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-26 09:41:10 +03:00

Consolidate triplicated xDestroy()-calling code. Remove some unnecessary casts.

FossilOrigin-Name: 24c0763d0e025187c74002ffee11fd48d3cd7b40e01469d28484bb67f701884b
This commit is contained in:
stephan
2023-07-31 07:15:25 +00:00
parent 09947d0aad
commit 9c1c6da930
3 changed files with 49 additions and 52 deletions

View File

@ -454,17 +454,22 @@ static int s3jni_db_error(sqlite3*db, int err_code, const char *zMsg){
} }
/** /**
Clears s's state, releasing any Java references. Before doing so, Extracts the (void xDestroy()) method from the given jclass and
it calls s's xDestroy() method, ignoring the lack of that method or applies it to jobj. If jobs is NULL, this is a no-op. If klazz is
any exceptions it throws. This is a no-op of s has no current NULL then it's derived from jobj. The lack of an xDestroy() method
state. is silently ignored and any exceptions thrown by the method trigger
a warning to stdout or stderr and then the exception is suppressed.
*/ */
static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){ static void s3jni_call_xDestroy(JNIEnv *env, jobject jobj, jclass klazz){
if(s->base.jObj){ if(jobj){
const jmethodID method = jmethodID method;
(*env)->GetMethodID(env, s->klazz, "xDestroy", "()V"); if(!klazz){
klazz = (*env)->GetObjectClass(env, jobj);
assert(klazz);
}
method = (*env)->GetMethodID(env, klazz, "xDestroy", "()V");
if(method){ if(method){
(*env)->CallVoidMethod(env, s->base.jObj, method); (*env)->CallVoidMethod(env, jobj, method);
IFTHREW{ IFTHREW{
EXCEPTION_WARN_CALLBACK_THREW; EXCEPTION_WARN_CALLBACK_THREW;
EXCEPTION_CLEAR; EXCEPTION_CLEAR;
@ -472,6 +477,19 @@ static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){
}else{ }else{
EXCEPTION_CLEAR; EXCEPTION_CLEAR;
} }
}
}
/**
Clears s's state, releasing any Java references. Before doing so,
it calls s's xDestroy() method, ignoring the lack of that method or
any exceptions it throws. This is a no-op of s has no current
state.
*/
static void BusyHandlerJni_clear(JNIEnv *env, BusyHandlerJni * const s){
if(s->base.jObj){
s3jni_call_xDestroy(env, s->base.jObj, s->klazz);
UNREF_G(s->base.jObj); UNREF_G(s->base.jObj);
UNREF_G(s->klazz); UNREF_G(s->klazz);
memset(s, 0, sizeof(BusyHandlerJni)); memset(s, 0, sizeof(BusyHandlerJni));
@ -909,19 +927,19 @@ static CollationState * CollationState_alloc(void){
return rc; return rc;
} }
static void CollationState_free(CollationState * cs){ static void CollationState_free(CollationState * const cs){
JNIEnv * const env = cs->env; JNIEnv * const env = cs->env;
if(env){ if(env){
//MARKER(("Collation cleanup...\n")); //MARKER(("Collation cleanup...\n"));
if(cs->oCollation) UNREF_G(cs->oCollation); UNREF_G(cs->oCollation);
if(cs->klazz) UNREF_G(cs->klazz); UNREF_G(cs->klazz);
} }
sqlite3_free(cs); sqlite3_free(cs);
} }
static int collation_xCompare_proxy(void *pArg, int nLhs, const void *lhs, static int CollationState_xCompare(void *pArg, int nLhs, const void *lhs,
int nRhs, const void *rhs){ int nRhs, const void *rhs){
CollationState * const cs = (CollationState*)pArg; CollationState * const cs = pArg;
JNIEnv * env = cs->env; JNIEnv * env = cs->env;
jint rc; jint rc;
jbyteArray jbaLhs = (*env)->NewByteArray(env, (jint)nLhs); jbyteArray jbaLhs = (*env)->NewByteArray(env, (jint)nLhs);
@ -937,20 +955,10 @@ static int collation_xCompare_proxy(void *pArg, int nLhs, const void *lhs,
return (int)rc; return (int)rc;
} }
static void collation_xDestroy_proxy(void *pArg){ /* Collation finalizer for use by the sqlite3 internals. */
CollationState * const cs = (CollationState*)pArg; static void CollationState_xDestroy(void *pArg){
if(cs->oCollation){ CollationState * const cs = pArg;
JNIEnv * const env = cs->env; s3jni_call_xDestroy(cs->env, cs->oCollation, cs->klazz);
const jmethodID method = (*env)->GetMethodID(env, cs->klazz, "xDestroy",
"()V");
//MARKER(("Calling Collation.xDestroy()...\n"));
(*env)->CallVoidMethod(env, cs->oCollation, method);
IFTHREW {
EXCEPTION_WARN_CALLBACK_THREW;
EXCEPTION_CLEAR;
}
//MARKER(("Returned from Collation.xDestroy().\n"));
}
CollationState_free(cs); CollationState_free(cs);
} }
@ -1132,19 +1140,8 @@ static UDFState * UDFState_alloc(JNIEnv *env, jobject jObj){
static void UDFState_free(UDFState * s){ static void UDFState_free(UDFState * s){
JNIEnv * const env = s->env; JNIEnv * const env = s->env;
if(env){ if(env){
//MARKER(("Collation cleanup...\n")); //MARKER(("UDF cleanup...\n"));
if(s->jObj){ s3jni_call_xDestroy(env, s->jObj, s->klazz);
const jmethodID method =
(*env)->GetMethodID(env, s->klazz, "xDestroy", "()V");
if(method){
//MARKER(("aCalling SQLFunction.xDestroy()...\n"));
(*env)->CallVoidMethod(env, s->jObj, method);
EXCEPTION_IGNORE;
//MARKER(("Returned from SQLFunction.xDestroy().\n"));
}else{
(*env)->ExceptionClear(env);
}
}
UNREF_G(s->jObj); UNREF_G(s->jObj);
UNREF_G(s->klazz); UNREF_G(s->klazz);
} }
@ -1734,10 +1731,10 @@ JDECL(jint,1create_1collation)(JENV_JSELF, jobject jpDb,
"([B[B)I"); "([B[B)I");
zName = JSTR_TOC(name); zName = JSTR_TOC(name);
rc = sqlite3_create_collation_v2(PtrGet_sqlite3(jpDb), zName, (int)eTextRep, rc = sqlite3_create_collation_v2(PtrGet_sqlite3(jpDb), zName, (int)eTextRep,
cs, collation_xCompare_proxy, cs, CollationState_xCompare,
collation_xDestroy_proxy); CollationState_xDestroy);
JSTR_RELEASE(name, zName); JSTR_RELEASE(name, zName);
if(0 != rc) collation_xDestroy_proxy(cs); if(0 != rc) CollationState_xDestroy(cs);
return (jint)rc; return (jint)rc;
} }

View File

@ -1,5 +1,5 @@
C Internal\sJNI\sAPI\srenaming. C Consolidate\striplicated\sxDestroy()-calling\scode.\sRemove\ssome\sunnecessary\scasts.
D 2023-07-30T18:41:25.803 D 2023-07-31T07:15:25.615
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -232,7 +232,7 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8 F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
F ext/jni/GNUmakefile 56a014dbff9516774d895ec1ae9df0ed442765b556f79a0fc0b5bc438217200d F ext/jni/GNUmakefile 56a014dbff9516774d895ec1ae9df0ed442765b556f79a0fc0b5bc438217200d
F ext/jni/README.md c0e6e80935e7761acead89b69c87765b23a6bcb2858c321c3d05681fd338292a F ext/jni/README.md c0e6e80935e7761acead89b69c87765b23a6bcb2858c321c3d05681fd338292a
F ext/jni/src/c/sqlite3-jni.c e1dc9820a9a68fad2d06e15022e4288817a29ca83bf804e3926985115f1f1a1d F ext/jni/src/c/sqlite3-jni.c 2d61ba074e851ad010307fd901581030a3f234771c266306ff9ccf33ae1a5542
F ext/jni/src/c/sqlite3-jni.h 28def286ee305c1c89a43ac5918a6862d985d0534f7ccbbd74df4885d3918b73 F ext/jni/src/c/sqlite3-jni.h 28def286ee305c1c89a43ac5918a6862d985d0534f7ccbbd74df4885d3918b73
F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c 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/Collation.java 8dffbb00938007ad0967b2ab424d3c908413af1bbd3d212b9c9899910f1218d1
@ -2071,8 +2071,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 120983a570d6de055cef9d916096de3410897ea9f46d23ea6eff1f9b549e423a P fcfc070673cef2f657f4737f096678439ed7c011fb2e5391e0721f82f5d8af51
R 6a2910fdd19645a78e675ea1b5f3006c R cfdb6b4bc4a7852f0b4b2fc4d64b3f33
U stephan U stephan
Z 307d46c1a84b2aab03be2e0da79180c9 Z 7456fbe378da7eba9d869800225a0ec8
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
fcfc070673cef2f657f4737f096678439ed7c011fb2e5391e0721f82f5d8af51 24c0763d0e025187c74002ffee11fd48d3cd7b40e01469d28484bb67f701884b