1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Remove the Java BusyHandler.xDestroy() method - it should not have had one. Eliminate the last of the potentially-significant MUTF-8 cases.

FossilOrigin-Name: c852f1ebbde273c3d28fe5aff0bf73cfc06b41dd371a94d7520536dc7a1dbcc1
This commit is contained in:
stephan
2023-08-26 10:51:19 +00:00
parent 6f8f587d2f
commit d9cf47e377
5 changed files with 39 additions and 57 deletions

View File

@ -997,7 +997,7 @@ static void S3JniDb_set_aside_unlocked(JNIEnv * env, S3JniDb * const s){
sqlite3_free( s->zMainDbName );
#define UNHOOK(MEMBER,XDESTROY) S3JniHook_unref(env, &s->hooks.MEMBER, XDESTROY)
UNHOOK(auth, 0);
UNHOOK(busyHandler, 1);
UNHOOK(busyHandler, 0);
UNHOOK(collation, 1);
UNHOOK(collationNeeded, 0);
UNHOOK(commit, 0);
@ -2121,7 +2121,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)(
return 0;
}
jclass klazz;
S3JniHook_unref(env, pHook, 1);
S3JniHook_unref(env, pHook, 0);
pHook->jObj = S3JniRefGlobal(jBusy);
klazz = (*env)->GetObjectClass(env, jBusy);
pHook->midCallback = (*env)->GetMethodID(env, klazz, "call", "(I)I");
@ -2131,7 +2131,7 @@ S3JniApi(sqlite3_busy_handler(),jint,1busy_1handler)(
rc = SQLITE_ERROR;
}
}else{
S3JniHook_unref(env, pHook, 1);
S3JniHook_unref(env, pHook, 0);
}
if( 0==rc ){
rc = jBusy
@ -2146,11 +2146,14 @@ S3JniApi(sqlite3_busy_timeout(),jint,1busy_1timeout)(
JniArgsEnvClass, jobject jDb, jint ms
){
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0);
int rc = SQLITE_MISUSE;
if( ps ){
S3JniHook_unref(env, &ps->hooks.busyHandler, 1);
return sqlite3_busy_timeout(ps->pDb, (int)ms);
S3JniMutex_S3JniDb_enter;
S3JniHook_unref(env, &ps->hooks.busyHandler, 0);
rc = sqlite3_busy_timeout(ps->pDb, (int)ms);
S3JniMutex_S3JniDb_leave;
}
return SQLITE_MISUSE;
return rc;
}
S3JniApi(sqlite3_cancel_auto_extension(),jboolean,1cancel_1auto_1extension)(
@ -2551,7 +2554,6 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(),
)(JniArgsEnvClass, jobject jDb, jstring name, jint eTextRep,
jobject oCollation){
int rc;
const char *zName;
jclass klazz;
S3JniDb * const ps = S3JniDb_for_db(env, jDb, 0);
jmethodID midCallback;
@ -2565,17 +2567,21 @@ S3JniApi(sqlite3_create_collation() sqlite3_create_collation_v2(),
rc = s3jni_db_error(ps->pDb, SQLITE_ERROR,
"Could not get xCompare() method for object.");
}else{
zName = s3jni_jstring_to_mutf8(name);
rc = sqlite3_create_collation_v2(ps->pDb, zName, (int)eTextRep,
ps, CollationState_xCompare,
CollationState_xDestroy);
s3jni_mutf8_release(name, zName);
if( 0==rc ){
char * const zName = s3jni_jstring_to_utf8(env, name, 0);
if( zName ){
S3JniMutex_S3JniDb_enter;
S3JniHook_unref( env, &ps->hooks.collation, 1 );
ps->hooks.collation.midCallback = midCallback;
ps->hooks.collation.jObj = S3JniRefGlobal(oCollation);
rc = sqlite3_create_collation_v2(ps->pDb, zName, (int)eTextRep,
ps, CollationState_xCompare,
CollationState_xDestroy);
sqlite3_free(zName);
if( 0==rc ){
S3JniHook_unref( env, &ps->hooks.collation, 1 );
ps->hooks.collation.midCallback = midCallback;
ps->hooks.collation.jObj = S3JniRefGlobal(oCollation);
}
S3JniMutex_S3JniDb_leave;
}else{
rc = SQLITE_NOMEM;
}
}
return (jint)rc;
@ -2627,9 +2633,9 @@ S3JniApi(sqlite3_create_function() sqlite3_create_function_v2() sqlite3_create_w
xFunc, xStep, xFinal, S3JniUdf_finalizer);
}
error_cleanup:
/* Reminder: on sqlite3_create_function() error, s will be
** destroyed via create_function(). */
sqlite3_free(zFuncName);
/* on sqlite3_create_function() error, s will be destroyed via
** create_function(), so we're not leaking s. */
return (jint)rc;
}
@ -4228,11 +4234,11 @@ JniDeclFtsApi(jint,xCreateFunction)(JniArgsEnvObj, jstring jName,
jobject jUserData, jobject jFunc){
fts5_api * const pApi = PtrGet_fts5_api(jSelf);
int rc;
char const * zName;
char * zName;
Fts5JniAux * pAux;
assert(pApi);
zName = s3jni_jstring_to_mutf8(jName);
zName = s3jni_jstring_to_utf8(env, jName, 0);
if(!zName) return SQLITE_NOMEM;
pAux = Fts5JniAux_alloc(env, jFunc);
if( pAux ){
@ -4244,10 +4250,10 @@ JniDeclFtsApi(jint,xCreateFunction)(JniArgsEnvObj, jstring jName,
}
if( 0==rc ){
pAux->jUserData = jUserData ? S3JniRefGlobal(jUserData) : 0;
pAux->zFuncName = sqlite3_mprintf("%s", zName)
/* OOM here is non-fatal. Ignore it. */;
pAux->zFuncName = zName;
}else{
sqlite3_free(zName);
}
s3jni_mutf8_release(jName, zName);
return (jint)rc;
}

View File

@ -17,8 +17,7 @@ package org.sqlite.jni;
/**
Callback for use with sqlite3_busy_handler()
*/
public abstract class BusyHandlerCallback
implements SQLite3CallbackProxy, XDestroyCallback {
public abstract class BusyHandlerCallback implements SQLite3CallbackProxy {
/**
Must function as documented for the C-level
sqlite3_busy_handler() callback argument, minus the (void*)
@ -28,20 +27,4 @@ public abstract class BusyHandlerCallback
retain the C-style API semantics of the JNI bindings.
*/
public abstract int call(int n);
/**
Optionally override to perform any cleanup when this busy
handler is destroyed. It is destroyed when:
- The associated db is passed to sqlite3_close() or
sqlite3_close_v2().
- sqlite3_busy_handler() is called to replace the handler,
whether it's passed a null handler or any other instance of
this class.
- sqlite3_busy_timeout() is called, which implicitly installs
a busy handler.
*/
public void xDestroy(){}
}

View File

@ -940,31 +940,24 @@ public class Tester1 implements Runnable {
rc = sqlite3_db_config(db1, SQLITE_DBCONFIG_MAINDBNAME, "foo");
affirm( sqlite3_db_filename(db1, "foo").endsWith(dbName) );
final ValueHolder<Boolean> xDestroyed = new ValueHolder<>(false);
final ValueHolder<Integer> xBusyCalled = new ValueHolder<>(0);
BusyHandlerCallback handler = new BusyHandlerCallback(){
@Override public int call(int n){
//outln("busy handler #"+n);
return n > 2 ? 0 : ++xBusyCalled.value;
}
@Override public void xDestroy(){
xDestroyed.value = true;
}
};
rc = sqlite3_busy_handler(db2, handler);
affirm(0 == rc);
// Force a locked condition...
execSql(db1, "BEGIN EXCLUSIVE");
affirm(!xDestroyed.value);
rc = sqlite3_prepare_v2(db2, "SELECT * from t", outStmt);
affirm( SQLITE_BUSY == rc);
assert( null == outStmt.get() );
affirm( 3 == xBusyCalled.value );
sqlite3_close_v2(db1);
affirm(!xDestroyed.value);
sqlite3_close_v2(db2);
affirm(xDestroyed.value);
try{
final java.io.File f = new java.io.File(dbName);
f.delete();