Bind sqlite3_strlike/strglob() to JNI.

FossilOrigin-Name: eb5440f71be32812f6310756b8e30958002e8e8e41a7eb16f081058ff733b47c
This commit is contained in:
stephan 2023-08-08 10:58:16 +00:00
parent aeae7904a5
commit c693bd59f7
5 changed files with 70 additions and 12 deletions

View File

@ -543,6 +543,11 @@ static struct {
#endif
} S3JniGlobal;
#define OOM_CHECK(VAR) if(!(VAR)) s3jni_oom(env)
static void s3jni_oom(JNIEnv * const env){
(*env)->FatalError(env, "Out of memory.") /* does not return */;
}
/**
sqlite3_malloc() proxy which fails fatally on OOM. This should
only be used for routines which manage global state and have no
@ -551,9 +556,7 @@ static struct {
*/
static void * s3jni_malloc(JNIEnv * const env, size_t n){
void * const rv = sqlite3_malloc(n);
if(n && !rv){
(*env)->FatalError(env, "Out of memory.") /* does not return */;
}
if(n && !rv) s3jni_oom(env);
return rv;
}
@ -3056,6 +3059,27 @@ JDECL(void,1set_1last_1insert_1rowid)(JENV_CSELF, jobject jpDb, jlong rowId){
(sqlite3_int64)rowId);
}
static int s3jni_strlike_glob(int isLike, JNIEnv *const env,
jbyteArray baG, jbyteArray baT){
int rc = 0;
jbyte * const pG = JBA_TOC(baG);
jbyte * const pT = pG ? JBA_TOC(baT) : 0;
OOM_CHECK(pT);
rc = sqlite3_strglob((const char *)pG, (const char *)pT);
JBA_RELEASE(baG, pG);
JBA_RELEASE(baT, pT);
return rc;
}
JDECL(int,1strglob)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
return s3jni_strlike_glob(0, env, baG, baT);
}
JDECL(int,1strlike)(JENV_CSELF, jbyteArray baG, jbyteArray baT){
return s3jni_strlike_glob(1, env, baG, baT);
}
JDECL(jint,1shutdown)(JENV_CSELF){
S3JniGlobal_S3JniEnvCache_clear();
/* Do not clear S3JniGlobal.jvm: it's legal to call

View File

@ -1459,6 +1459,22 @@ JNIEXPORT jstring JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1sourceid
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1step
(JNIEnv *, jclass, jobject);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_strglob
* Signature: ([B[B)I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strglob
(JNIEnv *, jclass, jbyteArray, jbyteArray);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_strlike
* Signature: ([B[B)I
*/
JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1strlike
(JNIEnv *, jclass, jbyteArray, jbyteArray);
/*
* Class: org_sqlite_jni_SQLite3Jni
* Method: sqlite3_threadsafe

View File

@ -850,6 +850,24 @@ public final class SQLite3Jni {
public static native int sqlite3_step(@NotNull sqlite3_stmt stmt);
private static native int sqlite3_strglob(@NotNull byte[] glob, @NotNull byte[] txt);
public static int sqlite3_strglob(@NotNull String glob, @NotNull String txt){
return sqlite3_strglob(
glob.getBytes(StandardCharsets.UTF_8),
txt.getBytes(StandardCharsets.UTF_8)
);
}
private static native int sqlite3_strlike(@NotNull byte[] glob, @NotNull byte[] txt);
public static int sqlite3_strlike(@NotNull String glob, @NotNull String txt){
return sqlite3_strlike(
glob.getBytes(StandardCharsets.UTF_8),
txt.getBytes(StandardCharsets.UTF_8)
);
}
public static native int sqlite3_threadsafe();
public static native int sqlite3_total_changes(@NotNull sqlite3 db);

View File

@ -1,5 +1,5 @@
C SQLTester:\sadd\sprint\scommand\sand\simprove\sargument\serror\sreporting\sinfrastructure.
D 2023-08-08T09:45:33.280
C Bind\ssqlite3_strlike/strglob()\sto\sJNI.
D 2023-08-08T10:58:16.862
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -232,8 +232,8 @@ F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
F ext/jni/GNUmakefile 2b800c74db98b64b63ec1da48dc4a27738f88951f0ca43011288abf80c1b5e80
F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d
F ext/jni/src/c/sqlite3-jni.c e6463b3fc8ef000d9a5dd1649fe96a4cfc5aac21a43276424cf28d72548c5921
F ext/jni/src/c/sqlite3-jni.h 6c06cdb1e43ce56544dfbe3335a46174dae15d03337d06e55aa7256f85d2ce1b
F ext/jni/src/c/sqlite3-jni.c eb105982266523f4cd9c5007c3cc713855aca520a0f24fce138e4ecfd573fc20
F ext/jni/src/c/sqlite3-jni.h bc3ecd3f6e479fd45b80214f6256584cc599336ae222822fa1e603c22ff1fb19
F ext/jni/src/org/sqlite/jni/Authorizer.java 1308988f7f40579ea0e4deeaec3c6be971630566bd021c31367fe3f5140db892
F ext/jni/src/org/sqlite/jni/AutoExtension.java 3409ad8954d6466bf772e6be9379e0e337312b446b668287062845755a16844d
F ext/jni/src/org/sqlite/jni/BusyHandler.java 1b1d3e5c86cd796a0580c81b6af6550ad943baa25e47ada0dcca3aff3ebe978c
@ -251,7 +251,7 @@ F ext/jni/src/org/sqlite/jni/OutputPointer.java ebdd33d48064c3302d0d4a6dd345562a
F ext/jni/src/org/sqlite/jni/ProgressHandler.java 6f62053a828a572de809828b1ee495380677e87daa29a1c57a0e2c06b0a131dc
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 21b828cb61984977c7b2a0cbd803f0c15dd79ff524ab94d3ce52648c011b2c9c
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 3681e6ea94973ce1f7facd6887853a4ae5657a9274dd06279b586dbf77f36c2d
F ext/jni/src/org/sqlite/jni/Tester1.java 57404879fbea78f0b405b7643abb03dad0a6ce6cea9ec0c4ef55ea40267be565
F ext/jni/src/org/sqlite/jni/TesterFts5.java cf2d687baafffdeba219b77cf611fd47a0556248820ea794ae3e8259bfbdc5ee
F ext/jni/src/org/sqlite/jni/Tracer.java a5cece9f947b0af27669b8baec300b6dd7ff859c3e6a6e4a1bd8b50f9714775d
@ -2089,8 +2089,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 5be50fd5887e5378f7d66405bff3a44117a826a17e5f1a18c5129d1109ecdae2
R 8128e06f40a69e4ebe18ddcc9febcc5a
P 1b6e84f6aa5c7626a308b5e8efe5c3d83ec8e7eaa803f047576b7c65333c2d44
R 7802ddad819423a1071e483ed129b94a
U stephan
Z d82fef86e57475799cbc6287645847ba
Z f01d533536a4e5fdaf6eae004d864cb3
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
1b6e84f6aa5c7626a308b5e8efe5c3d83ec8e7eaa803f047576b7c65333c2d44
eb5440f71be32812f6310756b8e30958002e8e8e41a7eb16f081058ff733b47c