From: stephan Date: Thu, 10 Aug 2023 21:50:52 +0000 (+0000) Subject: Mark _all_ JNI binding funcs as synchronized so that Java can lock them and protect... X-Git-Tag: version-3.43.0~47^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0423e0fc1cee8eded300f1f615c7b110bfba0b0;p=thirdparty%2Fsqlite.git Mark _all_ JNI binding funcs as synchronized so that Java can lock them and protect our global-state access. The alternative is writing a mountain of C-side code to do the same thing. FossilOrigin-Name: afe190a940441de9bef8835c2dc6d278f861a772c3b7c7a2d399b2eabd4872e3 --- diff --git a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java index 758ea717f0..ac041e3001 100644 --- a/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java +++ b/ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java @@ -35,52 +35,52 @@ public final class Fts5ExtensionApi extends NativePointerHolder, and Window) for details. */ - public static native int sqlite3_create_function( + public static synchronized native int sqlite3_create_function( @NotNull sqlite3 db, @NotNull String functionName, int nArg, int eTextRep, @NotNull SQLFunction func ); - public static native int sqlite3_data_count( + public static synchronized native int sqlite3_data_count( @NotNull sqlite3_stmt stmt ); - public static native String sqlite3_db_filename( + public static synchronized native String sqlite3_db_filename( @NotNull sqlite3 db, @NotNull String dbName ); @@ -511,7 +511,7 @@ public final class SQLite3Jni { variadic arguments. Returns SQLITE_MISUSE if op is not one of the SQLITE_DBCONFIG_... options which uses this call form. */ - public static native int sqlite3_db_config( + public static synchronized native int sqlite3_db_config( @NotNull sqlite3 db, int op, int onOff, @Nullable OutputPointer.Int32 out ); @@ -522,36 +522,36 @@ public final class SQLite3Jni { SQLITE_DBCONFIG_MAINDBNAME, but that set of options may be extended in future versions. */ - public static native int sqlite3_db_config( - @NotNull sqlite3 db, int op, @NotNull String mainDbName + public static synchronized native int sqlite3_db_config( + @NotNull sqlite3 db, int op, @NotNull String val ); - public static native int sqlite3_errcode(@NotNull sqlite3 db); + public static synchronized native int sqlite3_errcode(@NotNull sqlite3 db); - public static native int sqlite3_extended_errcode(@NotNull sqlite3 db); + public static synchronized native int sqlite3_extended_errcode(@NotNull sqlite3 db); - public static native boolean sqlite3_extended_result_codes( + public static synchronized native boolean sqlite3_extended_result_codes( @NotNull sqlite3 db, boolean onoff ); - public static native String sqlite3_errmsg(@NotNull sqlite3 db); + public static synchronized native String sqlite3_errmsg(@NotNull sqlite3 db); - public static native String sqlite3_errstr(int resultCode); + public static synchronized native String sqlite3_errstr(int resultCode); /** Note that the offset values assume UTF-8-encoded SQL. */ - public static native int sqlite3_error_offset(@NotNull sqlite3 db); + public static synchronized native int sqlite3_error_offset(@NotNull sqlite3 db); - public static native int sqlite3_finalize(@NotNull sqlite3_stmt stmt); + public static synchronized native int sqlite3_finalize(@NotNull sqlite3_stmt stmt); - public static native int sqlite3_initialize(); + public static synchronized native int sqlite3_initialize(); - public static native long sqlite3_last_insert_rowid(@NotNull sqlite3 db); + public static synchronized native long sqlite3_last_insert_rowid(@NotNull sqlite3 db); - public static native String sqlite3_libversion(); + public static synchronized native String sqlite3_libversion(); - public static native int sqlite3_libversion_number(); + public static synchronized native int sqlite3_libversion_number(); /** Works like its C counterpart and makes the native pointer of the @@ -572,11 +572,11 @@ public final class SQLite3Jni { or sqlite3_open_v2() so that they have a predictible object to pass to, e.g., the sqlite3_collation_needed() callback. */ - public static native synchronized int sqlite3_open( + public static synchronized native int sqlite3_open( @Nullable String filename, @NotNull OutputPointer.sqlite3 ppDb ); - public static native synchronized int sqlite3_open_v2( + public static synchronized native int sqlite3_open_v2( @Nullable String filename, @NotNull OutputPointer.sqlite3 ppDb, int flags, @Nullable String zVfs ); @@ -600,7 +600,7 @@ public final class SQLite3Jni { necessary, however, and overloads are provided which gloss over that. */ - private static native int sqlite3_prepare( + private static synchronized native int sqlite3_prepare( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, int maxBytes, @NotNull OutputPointer.sqlite3_stmt outStmt, @Nullable OutputPointer.Int32 pTailOffset @@ -629,7 +629,7 @@ public final class SQLite3Jni { return sqlite3_prepare(db, utf8, utf8.length, outStmt, null); } - private static native int sqlite3_prepare_v2( + private static synchronized native int sqlite3_prepare_v2( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, int maxBytes, @NotNull OutputPointer.sqlite3_stmt outStmt, @Nullable OutputPointer.Int32 pTailOffset @@ -658,7 +658,7 @@ public final class SQLite3Jni { return sqlite3_prepare_v2(db, utf8, utf8.length, outStmt, null); } - private static native int sqlite3_prepare_v3( + private static synchronized native int sqlite3_prepare_v3( @NotNull sqlite3 db, @NotNull byte[] sqlUtf8, int maxBytes, int prepFlags, @NotNull OutputPointer.sqlite3_stmt outStmt, @Nullable OutputPointer.Int32 pTailOffset @@ -687,13 +687,13 @@ public final class SQLite3Jni { return sqlite3_prepare_v3(db, utf8, utf8.length, prepFlags, outStmt, null); } - public static native void sqlite3_progress_handler( + public static synchronized native void sqlite3_progress_handler( @NotNull sqlite3 db, int n, @Nullable ProgressHandler h ); //TODO??? void *sqlite3_preupdate_hook(...) and friends - public static native int sqlite3_reset(@NotNull sqlite3_stmt stmt); + public static synchronized native int sqlite3_reset(@NotNull sqlite3_stmt stmt); /** Works like the C API except that it has no side effects if auto @@ -701,7 +701,7 @@ public final class SQLite3Jni { */ public static synchronized native void sqlite3_reset_auto_extension(); - public static native void sqlite3_result_double( + public static synchronized native void sqlite3_result_double( @NotNull sqlite3_context cx, double v ); @@ -712,7 +712,7 @@ public final class SQLite3Jni { results in the C-level sqlite3_result_error() being called with a complaint about the invalid argument. */ - private static native void sqlite3_result_error( + private static synchronized native void sqlite3_result_error( @NotNull sqlite3_context cx, @Nullable byte[] msg, int eTextRep ); @@ -755,27 +755,27 @@ public final class SQLite3Jni { sqlite3_result_error16(cx, e.getMessage()); } - public static native void sqlite3_result_error_toobig( + public static synchronized native void sqlite3_result_error_toobig( @NotNull sqlite3_context cx ); - public static native void sqlite3_result_error_nomem( + public static synchronized native void sqlite3_result_error_nomem( @NotNull sqlite3_context cx ); - public static native void sqlite3_result_error_code( + public static synchronized native void sqlite3_result_error_code( @NotNull sqlite3_context cx, int c ); - public static native void sqlite3_result_null( + public static synchronized native void sqlite3_result_null( @NotNull sqlite3_context cx ); - public static native void sqlite3_result_int( + public static synchronized native void sqlite3_result_int( @NotNull sqlite3_context cx, int v ); - public static native void sqlite3_result_int64( + public static synchronized native void sqlite3_result_int64( @NotNull sqlite3_context cx, long v ); @@ -795,7 +795,7 @@ public final class SQLite3Jni { Note that there is no sqlite3_bind_java_object() counterpart. */ - public static native void sqlite3_result_java_object( + public static synchronized native void sqlite3_result_java_object( @NotNull sqlite3_context cx, @NotNull Object o ); @@ -853,19 +853,19 @@ public final class SQLite3Jni { sqlite3_result_text(cx, v); } - public static native void sqlite3_result_value( + public static synchronized native void sqlite3_result_value( @NotNull sqlite3_context cx, @NotNull sqlite3_value v ); - public static native void sqlite3_result_zeroblob( + public static synchronized native void sqlite3_result_zeroblob( @NotNull sqlite3_context cx, int n ); - public static native int sqlite3_result_zeroblob64( + public static synchronized native int sqlite3_result_zeroblob64( @NotNull sqlite3_context cx, long n ); - private static native void sqlite3_result_blob( + private static synchronized native void sqlite3_result_blob( @NotNull sqlite3_context cx, @Nullable byte[] blob, int maxLen ); @@ -885,7 +885,7 @@ public final class SQLite3Jni { If maxLen is larger than blob.length, it is truncated to that value. If it is negative, results are undefined. */ - private static native void sqlite3_result_blob64( + private static synchronized native void sqlite3_result_blob64( @NotNull sqlite3_context cx, @Nullable byte[] blob, long maxLen ); @@ -895,7 +895,7 @@ public final class SQLite3Jni { sqlite3_result_blob64(cx, blob, (long)(null==blob ? 0 : blob.length)); } - private static native void sqlite3_result_text( + private static synchronized native void sqlite3_result_text( @NotNull sqlite3_context cx, @Nullable byte[] text, int maxLen ); @@ -929,7 +929,7 @@ public final class SQLite3Jni { text.length, it is silently truncated to text.length. If it is negative, results are undefined. */ - private static native void sqlite3_result_text64( + private static synchronized native void sqlite3_result_text64( @NotNull sqlite3_context cx, @Nullable byte[] text, long maxLength, int encoding ); @@ -985,30 +985,30 @@ public final class SQLite3Jni { sqlite3_result_text64(cx, b, b.length, SQLITE_UTF16BE); } - public static native RollbackHook sqlite3_rollback_hook( + public static synchronized native RollbackHook sqlite3_rollback_hook( @NotNull sqlite3 db, @Nullable RollbackHook hook ); //! Sets or unsets (if auth is null) the current authorizer. - public static native int sqlite3_set_authorizer( + public static synchronized native int sqlite3_set_authorizer( @NotNull sqlite3 db, @Nullable Authorizer auth ); - public static native void sqlite3_set_last_insert_rowid( + public static synchronized native void sqlite3_set_last_insert_rowid( @NotNull sqlite3 db, long rowid ); - public static native int sqlite3_sleep(int ms); + public static synchronized native int sqlite3_sleep(int ms); - public static native String sqlite3_sourceid(); + public static synchronized native String sqlite3_sourceid(); - public static native int sqlite3_step(@NotNull sqlite3_stmt stmt); + public static synchronized native int sqlite3_step(@NotNull sqlite3_stmt stmt); /** Internal impl of the public sqlite3_strglob() method. Neither argument may be NULL and both _MUST_ be NUL-terminated. */ - private static native int sqlite3_strglob( + private static synchronized native int sqlite3_strglob( @NotNull byte[] glob, @NotNull byte[] txt ); @@ -1025,7 +1025,7 @@ public final class SQLite3Jni { Internal impl of the public sqlite3_strlike() method. Neither argument may be NULL and both _MUST_ be NUL-terminated. */ - private static native int sqlite3_strlike( + private static synchronized native int sqlite3_strlike( @NotNull byte[] glob, @NotNull byte[] txt, int escChar ); @@ -1039,11 +1039,11 @@ public final class SQLite3Jni { ); } - public static native int sqlite3_threadsafe(); + public static synchronized native int sqlite3_threadsafe(); - public static native int sqlite3_total_changes(@NotNull sqlite3 db); + public static synchronized native int sqlite3_total_changes(@NotNull sqlite3 db); - public static native long sqlite3_total_changes64(@NotNull sqlite3 db); + public static synchronized native long sqlite3_total_changes64(@NotNull sqlite3 db); /** Works like C's sqlite3_trace_v2() except that the 3rd argument to that @@ -1055,33 +1055,33 @@ public final class SQLite3Jni { mapping state fails and SQLITE_ERROR if the given callback object cannot be processed propertly (i.e. an internal error). */ - public static native int sqlite3_trace_v2( + public static synchronized native int sqlite3_trace_v2( @NotNull sqlite3 db, int traceMask, @Nullable Tracer tracer ); - public static native UpdateHook sqlite3_update_hook( + public static synchronized native UpdateHook sqlite3_update_hook( sqlite3 db, UpdateHook hook ); - public static native byte[] sqlite3_value_blob(@NotNull sqlite3_value v); + public static synchronized native byte[] sqlite3_value_blob(@NotNull sqlite3_value v); - public static native int sqlite3_value_bytes(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_bytes(@NotNull sqlite3_value v); - public static native int sqlite3_value_bytes16(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_bytes16(@NotNull sqlite3_value v); - public static native double sqlite3_value_double(@NotNull sqlite3_value v); + public static synchronized native double sqlite3_value_double(@NotNull sqlite3_value v); - public static native sqlite3_value sqlite3_value_dupe( + public static synchronized native sqlite3_value sqlite3_value_dupe( @NotNull sqlite3_value v ); - public static native int sqlite3_value_encoding(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_encoding(@NotNull sqlite3_value v); - public static native void sqlite3_value_free(@Nullable sqlite3_value v); + public static synchronized native void sqlite3_value_free(@Nullable sqlite3_value v); - public static native int sqlite3_value_int(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_int(@NotNull sqlite3_value v); - public static native long sqlite3_value_int64(@NotNull sqlite3_value v); + public static synchronized native long sqlite3_value_int64(@NotNull sqlite3_value v); /** If the given value was set using sqlite3_result_java_value() then @@ -1090,7 +1090,7 @@ public final class SQLite3Jni { It is up to the caller to inspect the object to determine its type, and cast it if necessary. */ - public static native Object sqlite3_value_java_object( + public static synchronized native Object sqlite3_value_java_object( @NotNull sqlite3_value v ); @@ -1111,41 +1111,41 @@ public final class SQLite3Jni { See sqlite3_value_text_utf8() for how to extract text in standard UTF-8. */ - public static native String sqlite3_value_text(@NotNull sqlite3_value v); + public static synchronized native String sqlite3_value_text(@NotNull sqlite3_value v); /** The sqlite3_value counterpart of sqlite3_column_text_utf8(). */ - public static native byte[] sqlite3_value_text_utf8(@NotNull sqlite3_value v); + public static synchronized native byte[] sqlite3_value_text_utf8(@NotNull sqlite3_value v); - public static native byte[] sqlite3_value_text16(@NotNull sqlite3_value v); + public static synchronized native byte[] sqlite3_value_text16(@NotNull sqlite3_value v); - public static native byte[] sqlite3_value_text16le(@NotNull sqlite3_value v); + public static synchronized native byte[] sqlite3_value_text16le(@NotNull sqlite3_value v); - public static native byte[] sqlite3_value_text16be(@NotNull sqlite3_value v); + public static synchronized native byte[] sqlite3_value_text16be(@NotNull sqlite3_value v); - public static native int sqlite3_value_type(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_type(@NotNull sqlite3_value v); - public static native int sqlite3_value_numeric_type(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_numeric_type(@NotNull sqlite3_value v); - public static native int sqlite3_value_nochange(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_nochange(@NotNull sqlite3_value v); - public static native int sqlite3_value_frombind(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_frombind(@NotNull sqlite3_value v); - public static native int sqlite3_value_subtype(@NotNull sqlite3_value v); + public static synchronized native int sqlite3_value_subtype(@NotNull sqlite3_value v); /** Cleans up all per-JNIEnv and per-db state managed by the library then calls the C-native sqlite3_shutdown(). */ - public static native int sqlite3_shutdown(); + public static synchronized native int sqlite3_shutdown(); /** This is NOT part of the public API. It exists solely as a place to hook in arbitrary C-side code during development and testing of this library. */ - static native void sqlite3_do_something_for_developer(); + static synchronized native void sqlite3_do_something_for_developer(); ////////////////////////////////////////////////////////////////////// // SQLITE_... constants follow... diff --git a/ext/jni/src/org/sqlite/jni/fts5_api.java b/ext/jni/src/org/sqlite/jni/fts5_api.java index 4df8a748e2..43b3d62ded 100644 --- a/ext/jni/src/org/sqlite/jni/fts5_api.java +++ b/ext/jni/src/org/sqlite/jni/fts5_api.java @@ -57,7 +57,7 @@ public final class fts5_api extends NativePointerHolder { // void (*xDestroy)(void*) // ); - public native int xCreateFunction(@NotNull String name, + public synchronized native int xCreateFunction(@NotNull String name, @Nullable Object userData, @NotNull fts5_extension_function xFunction); diff --git a/manifest b/manifest index c3653aa4ac..4016d95687 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\saround\sjdk8\sand\sjdk19\smangling\sthe\sC\sname\sof\ssqlite3_db_config()\sdifferently.\sCorrect\sthe\svariadic\sarg\shandling\sof\sthe\sJNI-side\ssubset\sof\ssqlite3_db_config()\soptions. -D 2023-08-10T21:29:59.469 +C Mark\s_all_\sJNI\sbinding\sfuncs\sas\ssynchronized\sso\sthat\sJava\scan\slock\sthem\sand\sprotect\sour\sglobal-state\saccess.\sThe\salternative\sis\swriting\sa\smountain\sof\sC-side\scode\sto\sdo\sthe\ssame\sthing. +D 2023-08-10T21:50:52.042 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -244,7 +244,7 @@ F ext/jni/src/org/sqlite/jni/CollationNeeded.java ad67843b6dd1c06b6b0a1dc72887b7 F ext/jni/src/org/sqlite/jni/CommitHook.java 87c6a8e5138c61a8eeff018fe16d23f29219150239746032687f245938baca1a F ext/jni/src/org/sqlite/jni/Fts5.java 13844685231e8b4840a706db3bed84d5dfcf15be0ae7e809eac40420dba24901 F ext/jni/src/org/sqlite/jni/Fts5Context.java 0a5a02047a6a1dd3e4a38b0e542a8dd2de365033ba30e6ae019a676305959890 -F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java c908e5fdf6f5d15e388144fcd8160a3f46c18dade749f1b747122d2d37f2e726 +F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 01f890105c6b7edbbad1c0f5635f783cea62c4b2ae694a71e76514a936ee03ec F ext/jni/src/org/sqlite/jni/Fts5Function.java 65cde7151e441fee012250a5e03277de7babcd11a0c308a832b7940574259bcc F ext/jni/src/org/sqlite/jni/Fts5PhraseIter.java 6642beda341c0b1b46af4e2d7f6f9ab03a7aede43277b2c92859176d6bce3be9 F ext/jni/src/org/sqlite/jni/Fts5Tokenizer.java 91489893596b6528c0df5cd7180bd5b55809c26e2b797fb321dfcdbc1298c060 @@ -254,13 +254,13 @@ F ext/jni/src/org/sqlite/jni/ProgressHandler.java 6f62053a828a572de809828b1ee495 F ext/jni/src/org/sqlite/jni/ResultCode.java 7cdf993f2037ab7bd244c9a34dbaef2ace3beb5da5d7e7fda5c6f67634ceb647 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 038401cac290a0641a0db33aada8941314f81c03f583a7fb18c88d24917a1757 +F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 836822ecf2f346d2218609fa68ddb3b595361663890493271635726e776cb57b F ext/jni/src/org/sqlite/jni/Tester1.java c45ab1895774851dec30824157d4c390f49e17729588c02cd88172854ee97e74 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 F ext/jni/src/org/sqlite/jni/ValueHolder.java f022873abaabf64f3dd71ab0d6037c6e71cece3b8819fa10bf26a5461dc973ee -F ext/jni/src/org/sqlite/jni/fts5_api.java 8c6b32455d7f85ee3f7f3e71c148bb3c2106f1d5484017daddfd560dd69d4f66 +F ext/jni/src/org/sqlite/jni/fts5_api.java 5198be71c162e3e0cb1f4962a7cdf0d7596e8af53f70c4af6db24aab8d53d9ba F ext/jni/src/org/sqlite/jni/fts5_extension_function.java ac825035d7d83fc7fd960347abfa6803e1614334a21533302041823ad5fc894c F ext/jni/src/org/sqlite/jni/fts5_tokenizer.java e530b36e6437fcc500e95d5d75fbffe272bdea20d2fac6be2e1336c578fba98b F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c388ec3bc1de547f098a0217158fc @@ -2090,8 +2090,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 d6a4d212ceba662470d8957b6a8d7075d18a84bd0d3e13ce7adcab03604fc3b7 -R f64708a8113a281fcc5d61dfd9215f40 +P 746894c3c043c47f8b4c231de8921df81c5d0634260d299359bea73132dc7867 +R e1ccd8a6a6627664a18e71218906f2ad U stephan -Z 8c35114ab07dc03c5df44ce3aa4b9338 +Z 898733fffb725ecf1391b4a8e291674e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bd45f5cb0f..8bcfadfae9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -746894c3c043c47f8b4c231de8921df81c5d0634260d299359bea73132dc7867 \ No newline at end of file +afe190a940441de9bef8835c2dc6d278f861a772c3b7c7a2d399b2eabd4872e3 \ No newline at end of file