JNI internal refactoring and cleanups.
FossilOrigin-Name: 7397973a2f191d75b149cf73a6d7ee1798820c1cd37d83af14e565067ede1b04
This commit is contained in:
parent
695d0b698a
commit
fdeb2c8121
@ -66,6 +66,7 @@ JAVA_FILES := $(patsubst %,$(dir.src.jni)/%,\
|
||||
ifeq (1,$(enable.fts5))
|
||||
JAVA_FILES += $(patsubst %,$(dir.src.jni)/%,\
|
||||
fts5_api.java \
|
||||
fts5_extension_function.java \
|
||||
fts5_tokenizer.java \
|
||||
Fts5.java \
|
||||
Fts5Context.java \
|
||||
|
@ -320,12 +320,18 @@ enum {
|
||||
*/
|
||||
typedef struct NphCacheLine NphCacheLine;
|
||||
struct NphCacheLine {
|
||||
const char * zClassName /* "full/class/Name". Must be a static string
|
||||
from the S3ClassNames struct. */;
|
||||
jclass klazz /* global ref to concrete NativePointerHolder class */;
|
||||
jmethodID midCtor /* klazz's constructor */;
|
||||
jfieldID fidValue /* NativePointerHolder.nativePointer and OutputPointer.X.value */;
|
||||
jfieldID fidSetAgg /* sqlite3_context::aggregateContext */;
|
||||
const char * zClassName /* "full/class/Name". Must be a static
|
||||
string pointer from the S3ClassNames
|
||||
struct. */;
|
||||
jclass klazz /* global ref to the concrete
|
||||
NativePointerHolder subclass represented by
|
||||
zClassName */;
|
||||
jmethodID midCtor /* klazz's no-arg constructor. Used by
|
||||
new_NativePointerHolder_object(). */;
|
||||
jfieldID fidValue /* NativePointerHolder.nativePointer and
|
||||
OutputPointer.X.value */;
|
||||
jfieldID fidSetAgg /* sqlite3_context::aggregateContext. Used only
|
||||
by the sqlite3_context binding. */;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -959,11 +965,18 @@ static int udf_setAggregateContext(JNIEnv * env, jobject jCx,
|
||||
}
|
||||
|
||||
/**
|
||||
Common init for setOutputInt32() and friends.
|
||||
Common init for setOutputInt32() and friends. zClassName must be a
|
||||
pointer from S3ClassNames. jOut must be an instance of that
|
||||
class. Fetches the jfieldID for jOut's [value] property, which must
|
||||
be of the type represented by the JNI type signature zTypeSig, and
|
||||
stores it in pFieldId. Fails fatally if the property is not found,
|
||||
as that presents a serious internal misuse.
|
||||
|
||||
Property lookups are cached on a per-class basis.
|
||||
*/
|
||||
static void setupOutputPointer(JNIEnv * env, const char *zClassName,
|
||||
const char *zTypeSig,
|
||||
jobject jOut, jfieldID * pSetter){
|
||||
jobject jOut, jfieldID * pFieldId){
|
||||
jfieldID setter = 0;
|
||||
struct NphCacheLine * const cacheLine =
|
||||
S3Global_nph_cache(env, zClassName);
|
||||
@ -978,10 +991,11 @@ static void setupOutputPointer(JNIEnv * env, const char *zClassName,
|
||||
cacheLine->fidValue = setter;
|
||||
}
|
||||
}
|
||||
*pSetter = setter;
|
||||
*pFieldId = setter;
|
||||
}
|
||||
|
||||
/* Sets a native int32 value in OutputPointer.Int32 object jOut. */
|
||||
/* Sets the value property of the OutputPointer.Int32 jOut object
|
||||
to v. */
|
||||
static void setOutputInt32(JNIEnv * env, jobject jOut, int v){
|
||||
jfieldID setter = 0;
|
||||
setupOutputPointer(env, S3ClassNames.OutputPointer_Int32, "I", jOut, &setter);
|
||||
@ -990,13 +1004,16 @@ static void setOutputInt32(JNIEnv * env, jobject jOut, int v){
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
/* Sets a native int64 value in OutputPointer.Int64 object jOut. */
|
||||
/* Sets the value property of the OutputPointer.Int64 jOut object
|
||||
to v. */
|
||||
static void setOutputInt64(JNIEnv * env, jobject jOut, jlong v){
|
||||
jfieldID setter = 0;
|
||||
setupOutputPointer(env, S3ClassNames.OutputPointer_Int64, "J", jOut, &setter);
|
||||
(*env)->SetLongField(env, jOut, setter, v);
|
||||
EXCEPTION_IS_FATAL("Cannot set OutputPointer.Int64.value");
|
||||
}
|
||||
/* Sets the value property of the OutputPointer.ByteArray jOut object
|
||||
to v. */
|
||||
static void setOutputByteArray(JNIEnv * env, jobject jOut, jbyteArray v){
|
||||
jfieldID setter = 0;
|
||||
setupOutputPointer(env, S3ClassNames.OutputPointer_ByteArray, "[B",
|
||||
@ -1005,7 +1022,8 @@ static void setOutputByteArray(JNIEnv * env, jobject jOut, jbyteArray v){
|
||||
EXCEPTION_IS_FATAL("Cannot set OutputPointer.ByteArray.value");
|
||||
}
|
||||
#if 0
|
||||
/* Sets a String value in OutputPointer.String object jOut. */
|
||||
/* Sets the value property of the OutputPointer.String jOut object
|
||||
to v. */
|
||||
static void setOutputString(JNIEnv * env, jobject jOut, jstring v){
|
||||
jfieldID setter = 0;
|
||||
setupOutputPointer(env, S3ClassNames.OutputPointer_String, "Ljava/lang/String",
|
||||
@ -1013,6 +1031,7 @@ static void setOutputString(JNIEnv * env, jobject jOut, jstring v){
|
||||
(*env)->SetObjectField(env, jOut, setter, v);
|
||||
EXCEPTION_IS_FATAL("Cannot set OutputPointer.String.value");
|
||||
}
|
||||
//! Bad: uses MUTF-8 encoding.
|
||||
static void setOutputString2(JNIEnv * env, jobject jOut, const char * zStr){
|
||||
jstring const jStr = (*env)->NewStringUTF(env, zStr);
|
||||
if(jStr){
|
||||
@ -1176,15 +1195,15 @@ static jobject new_NativePointerHolder_object(JNIEnv * const env, const char *zC
|
||||
return rv;
|
||||
}
|
||||
|
||||
static jobject new_sqlite3_value_wrapper(JNIEnv * const env, sqlite3_value *sv){
|
||||
static inline jobject new_sqlite3_value_wrapper(JNIEnv * const env, sqlite3_value *sv){
|
||||
return new_NativePointerHolder_object(env, S3ClassNames.sqlite3_value, sv);
|
||||
}
|
||||
|
||||
static jobject new_sqlite3_context_wrapper(JNIEnv * const env, sqlite3_context *sv){
|
||||
static inline jobject new_sqlite3_context_wrapper(JNIEnv * const env, sqlite3_context *sv){
|
||||
return new_NativePointerHolder_object(env, S3ClassNames.sqlite3_context, sv);
|
||||
}
|
||||
|
||||
static jobject new_sqlite3_stmt_wrapper(JNIEnv * const env, sqlite3_stmt *sv){
|
||||
static inline jobject new_sqlite3_stmt_wrapper(JNIEnv * const env, sqlite3_stmt *sv){
|
||||
return new_NativePointerHolder_object(env, S3ClassNames.sqlite3_stmt, sv);
|
||||
}
|
||||
|
||||
@ -1714,7 +1733,7 @@ JDECL(jlong,1column_1int64)(JENV_JSELF, jobject jpStmt,
|
||||
Java String of exactly half that length, returning NULL if !p or
|
||||
(*env)->NewString() fails.
|
||||
*/
|
||||
static jstring s3jni_text_to_jstring(JNIEnv * const env, const void * const p, int nP){
|
||||
static jstring s3jni_text16_to_jstring(JNIEnv * const env, const void * const p, int nP){
|
||||
return p
|
||||
? (*env)->NewString(env, (const jchar *)p, (jsize)(nP/2))
|
||||
: NULL;
|
||||
@ -1737,7 +1756,7 @@ JDECL(jstring,1column_1text)(JENV_JSELF, jobject jpStmt,
|
||||
sqlite3_stmt * const stmt = PtrGet_sqlite3_stmt(jpStmt);
|
||||
const int n = sqlite3_column_bytes16(stmt, (int)ndx);
|
||||
const void * const p = sqlite3_column_text16(stmt, (int)ndx);
|
||||
return s3jni_text_to_jstring(env, p, n);
|
||||
return s3jni_text16_to_jstring(env, p, n);
|
||||
}
|
||||
|
||||
JDECL(jbyteArray,1column_1text_1utf8)(JENV_JSELF, jobject jpStmt,
|
||||
@ -1838,10 +1857,10 @@ JDECL(jstring,1compileoption_1get)(JENV_JSELF, jint n){
|
||||
}
|
||||
|
||||
JDECL(jboolean,1compileoption_1used)(JENV_JSELF, jstring name){
|
||||
const char *zUtf8 = (*env)->GetStringUTFChars(env, name, NULL);
|
||||
const char *zUtf8 = JSTR_TOC(name);
|
||||
const jboolean rc =
|
||||
0==sqlite3_compileoption_used(zUtf8) ? JNI_FALSE : JNI_TRUE;
|
||||
(*env)->ReleaseStringUTFChars(env, name, zUtf8);
|
||||
JSTR_RELEASE(name, zUtf8);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1899,11 +1918,13 @@ static jint create_function(JNIEnv * env, jobject jDb, jstring jFuncName,
|
||||
else if( UDF_UNKNOWN_TYPE==s->type ){
|
||||
rc = s3jni_db_error(pDb, SQLITE_MISUSE,
|
||||
"Cannot unambiguously determine function type.");
|
||||
UDFState_free(s);
|
||||
goto error_cleanup;
|
||||
}
|
||||
zFuncName = JSTR_TOC(jFuncName);
|
||||
if(!zFuncName){
|
||||
rc = SQLITE_NOMEM;
|
||||
UDFState_free(s);
|
||||
goto error_cleanup;
|
||||
}
|
||||
if( UDF_WINDOW == s->type ){
|
||||
@ -1925,13 +1946,10 @@ static jint create_function(JNIEnv * env, jobject jDb, jstring jFuncName,
|
||||
xFunc, xStep, xFinal, UDFState_finalizer);
|
||||
}
|
||||
if( 0==rc ){
|
||||
s->zFuncName = sqlite3_mprintf("%s", zFuncName);
|
||||
if( !s->zFuncName ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
}
|
||||
if( 0!=rc ){
|
||||
UDFState_free(s);
|
||||
s->zFuncName = sqlite3_mprintf("%s", zFuncName)
|
||||
/* OOM here is non-fatal. Ignore it. Handling it would require
|
||||
re-calling the appropriate create_function() func with 0
|
||||
for all xAbc args so that s would be finalized. */;
|
||||
}
|
||||
error_cleanup:
|
||||
JSTR_RELEASE(jFuncName, zFuncName);
|
||||
@ -2568,7 +2586,7 @@ JDECL(jstring,1value_1text)(JENV_JSELF, jobject jpSVal){
|
||||
sqlite3_value * const sv = PtrGet_sqlite3_value(jpSVal);
|
||||
int const n = sqlite3_value_bytes16(sv);
|
||||
const void * const p = sqlite3_value_text16(sv);
|
||||
return s3jni_text_to_jstring(env, p, n);
|
||||
return s3jni_text16_to_jstring(env, p, n);
|
||||
}
|
||||
|
||||
JDECL(jbyteArray,1value_1text_1utf8)(JENV_JSELF, jobject jpSVal){
|
||||
@ -2619,6 +2637,14 @@ JDECL(jbyteArray,1value_1text16be)(JENV_JSELF, jobject jpSVal){
|
||||
|
||||
JDECL(void,1do_1something_1for_1developer)(JENV_JSELF){
|
||||
MARKER(("\nVarious bits of internal info:\n"));
|
||||
puts("FTS5 is "
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
"available"
|
||||
#else
|
||||
"unavailable"
|
||||
#endif
|
||||
"."
|
||||
);
|
||||
puts("sizeofs:");
|
||||
#define SO(T) printf("\tsizeof(" #T ") = %u\n", (unsigned)sizeof(T))
|
||||
SO(void*);
|
||||
@ -2626,6 +2652,9 @@ JDECL(void,1do_1something_1for_1developer)(JENV_JSELF){
|
||||
SO(PerDbStateJni);
|
||||
SO(S3Global);
|
||||
SO(JNIEnvCache);
|
||||
SO(S3ClassNames);
|
||||
printf("\t(^^^ %u NativePointerHolder subclasses)\n",
|
||||
(unsigned)(sizeof(S3ClassNames) / sizeof(const char *)));
|
||||
printf("Cache info:\n");
|
||||
printf("\tNativePointerHolder cache: %u misses, %u hits\n",
|
||||
S3Global.metrics.nphCacheMisses,
|
||||
@ -2669,6 +2698,7 @@ JDECL(void,1do_1something_1for_1developer)(JENV_JSELF){
|
||||
#define PtrGet_fts5_tokenizer(OBJ) getNativePointer(env,OBJ,S3ClassNames.fts5_tokenizer)
|
||||
#define PtrGet_Fts5Context(OBJ) getNativePointer(env,OBJ,S3ClassNames.Fts5Context)
|
||||
#define PtrGet_Fts5Tokenizer(OBJ) getNativePointer(env,OBJ,S3ClassNames.Fts5Tokenizer)
|
||||
#define Fts5ExtDecl Fts5ExtensionApi const * const fext = s3jni_ftsext()
|
||||
|
||||
/**
|
||||
State for binding Java-side FTS5 auxiliary functions.
|
||||
@ -2730,12 +2760,11 @@ static Fts5JniAux * Fts5JniAux_alloc(JNIEnv * const env, jobject jObj){
|
||||
static inline Fts5ExtensionApi const * s3jni_ftsext(void){
|
||||
return &sFts5Api/*singleton from sqlite3.c*/;
|
||||
}
|
||||
#define Fts5ExtDecl Fts5ExtensionApi const * const fext = s3jni_ftsext()
|
||||
|
||||
static jobject new_Fts5Context_wrapper(JNIEnv * const env, Fts5Context *sv){
|
||||
static inline jobject new_Fts5Context_wrapper(JNIEnv * const env, Fts5Context *sv){
|
||||
return new_NativePointerHolder_object(env, S3ClassNames.Fts5Context, sv);
|
||||
}
|
||||
static jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){
|
||||
static inline jobject new_fts5_api_wrapper(JNIEnv * const env, fts5_api *sv){
|
||||
return new_NativePointerHolder_object(env, S3ClassNames.fts5_api, sv);
|
||||
}
|
||||
|
||||
@ -3291,41 +3320,53 @@ JDECLFtsXA(jobject,xUserData)(JENV_JSELF,jobject jFcx){
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_sqlite_jni_SQLite3Jni_init(JNIEnv * const env, jclass self, jobject sJni){
|
||||
enum JType {
|
||||
JTYPE_INT,
|
||||
JTYPE_BOOL
|
||||
};
|
||||
typedef struct {
|
||||
const char *zName;
|
||||
enum JType jtype;
|
||||
int value;
|
||||
} LimitEntry;
|
||||
const LimitEntry aLimits[] = {
|
||||
{"SQLITE_MAX_ALLOCATION_SIZE", SQLITE_MAX_ALLOCATION_SIZE},
|
||||
{"SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH},
|
||||
{"SQLITE_MAX_LENGTH", SQLITE_MAX_LENGTH},
|
||||
{"SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH},
|
||||
{"SQLITE_MAX_SQL_LENGTH", SQLITE_MAX_SQL_LENGTH},
|
||||
{"SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN},
|
||||
{"SQLITE_MAX_COLUMN", SQLITE_MAX_COLUMN},
|
||||
{"SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH},
|
||||
{"SQLITE_MAX_EXPR_DEPTH", SQLITE_MAX_EXPR_DEPTH},
|
||||
{"SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT},
|
||||
{"SQLITE_MAX_COMPOUND_SELECT", SQLITE_MAX_COMPOUND_SELECT},
|
||||
{"SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP},
|
||||
{"SQLITE_MAX_VDBE_OP", SQLITE_MAX_VDBE_OP},
|
||||
{"SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG},
|
||||
{"SQLITE_MAX_FUNCTION_ARG", SQLITE_MAX_FUNCTION_ARG},
|
||||
{"SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED},
|
||||
{"SQLITE_MAX_ATTACHED", SQLITE_MAX_ATTACHED},
|
||||
{"SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH},
|
||||
{"SQLITE_MAX_LIKE_PATTERN_LENGTH", SQLITE_MAX_LIKE_PATTERN_LENGTH},
|
||||
{"SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER},
|
||||
{"SQLITE_MAX_VARIABLE_NUMBER", SQLITE_MAX_VARIABLE_NUMBER},
|
||||
{"SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH},
|
||||
{"SQLITE_MAX_TRIGGER_DEPTH", SQLITE_MAX_TRIGGER_DEPTH},
|
||||
{"SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS},
|
||||
{"SQLITE_MAX_WORKER_THREADS", SQLITE_MAX_WORKER_THREADS},
|
||||
} ConfigFlagEntry;
|
||||
const ConfigFlagEntry aLimits[] = {
|
||||
{"SQLITE_ENABLE_FTS5", JTYPE_BOOL,
|
||||
#ifdef SQLITE_ENABLE_FTS5
|
||||
1
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
},
|
||||
{"SQLITE_MAX_ALLOCATION_SIZE", JTYPE_INT, SQLITE_MAX_ALLOCATION_SIZE},
|
||||
{"SQLITE_LIMIT_LENGTH", JTYPE_INT, SQLITE_LIMIT_LENGTH},
|
||||
{"SQLITE_MAX_LENGTH", JTYPE_INT, SQLITE_MAX_LENGTH},
|
||||
{"SQLITE_LIMIT_SQL_LENGTH", JTYPE_INT, SQLITE_LIMIT_SQL_LENGTH},
|
||||
{"SQLITE_MAX_SQL_LENGTH", JTYPE_INT, SQLITE_MAX_SQL_LENGTH},
|
||||
{"SQLITE_LIMIT_COLUMN", JTYPE_INT, SQLITE_LIMIT_COLUMN},
|
||||
{"SQLITE_MAX_COLUMN", JTYPE_INT, SQLITE_MAX_COLUMN},
|
||||
{"SQLITE_LIMIT_EXPR_DEPTH", JTYPE_INT, SQLITE_LIMIT_EXPR_DEPTH},
|
||||
{"SQLITE_MAX_EXPR_DEPTH", JTYPE_INT, SQLITE_MAX_EXPR_DEPTH},
|
||||
{"SQLITE_LIMIT_COMPOUND_SELECT", JTYPE_INT, SQLITE_LIMIT_COMPOUND_SELECT},
|
||||
{"SQLITE_MAX_COMPOUND_SELECT", JTYPE_INT, SQLITE_MAX_COMPOUND_SELECT},
|
||||
{"SQLITE_LIMIT_VDBE_OP", JTYPE_INT, SQLITE_LIMIT_VDBE_OP},
|
||||
{"SQLITE_MAX_VDBE_OP", JTYPE_INT, SQLITE_MAX_VDBE_OP},
|
||||
{"SQLITE_LIMIT_FUNCTION_ARG", JTYPE_INT, SQLITE_LIMIT_FUNCTION_ARG},
|
||||
{"SQLITE_MAX_FUNCTION_ARG", JTYPE_INT, SQLITE_MAX_FUNCTION_ARG},
|
||||
{"SQLITE_LIMIT_ATTACHED", JTYPE_INT, SQLITE_LIMIT_ATTACHED},
|
||||
{"SQLITE_MAX_ATTACHED", JTYPE_INT, SQLITE_MAX_ATTACHED},
|
||||
{"SQLITE_LIMIT_LIKE_PATTERN_LENGTH", JTYPE_INT, SQLITE_LIMIT_LIKE_PATTERN_LENGTH},
|
||||
{"SQLITE_MAX_LIKE_PATTERN_LENGTH", JTYPE_INT, SQLITE_MAX_LIKE_PATTERN_LENGTH},
|
||||
{"SQLITE_LIMIT_VARIABLE_NUMBER", JTYPE_INT, SQLITE_LIMIT_VARIABLE_NUMBER},
|
||||
{"SQLITE_MAX_VARIABLE_NUMBER", JTYPE_INT, SQLITE_MAX_VARIABLE_NUMBER},
|
||||
{"SQLITE_LIMIT_TRIGGER_DEPTH", JTYPE_INT, SQLITE_LIMIT_TRIGGER_DEPTH},
|
||||
{"SQLITE_MAX_TRIGGER_DEPTH", JTYPE_INT, SQLITE_MAX_TRIGGER_DEPTH},
|
||||
{"SQLITE_LIMIT_WORKER_THREADS", JTYPE_INT, SQLITE_LIMIT_WORKER_THREADS},
|
||||
{"SQLITE_MAX_WORKER_THREADS", JTYPE_INT, SQLITE_MAX_WORKER_THREADS},
|
||||
{0,0}
|
||||
};
|
||||
jfieldID fieldId;
|
||||
jclass const klazz = (*env)->GetObjectClass(env, sJni);
|
||||
const LimitEntry * pLimit;
|
||||
const ConfigFlagEntry * pConfFlag;
|
||||
memset(&S3Global, 0, sizeof(S3Global));
|
||||
(void)S3Global_env_cache(env);
|
||||
assert( 1 == S3Global.envCache.used );
|
||||
@ -3335,12 +3376,21 @@ Java_org_sqlite_jni_SQLite3Jni_init(JNIEnv * const env, jclass self, jobject sJn
|
||||
(*env)->FatalError(env, "GetJavaVM() failure shouldn't be possible.");
|
||||
}
|
||||
|
||||
for( pLimit = &aLimits[0]; pLimit->zName; ++pLimit ){
|
||||
fieldId = (*env)->GetStaticFieldID(env, klazz, pLimit->zName, "I");
|
||||
for( pConfFlag = &aLimits[0]; pConfFlag->zName; ++pConfFlag ){
|
||||
char const * zSig = (JTYPE_BOOL == pConfFlag->jtype) ? "Z" : "I";
|
||||
fieldId = (*env)->GetStaticFieldID(env, klazz, pConfFlag->zName, zSig);
|
||||
EXCEPTION_IS_FATAL("Missing an expected static member of the SQLite3Jni class.");
|
||||
//MARKER(("Setting %s (field=%p) = %d\n", pLimit->zName, fieldId, pLimit->value));
|
||||
//MARKER(("Setting %s (field=%p) = %d\n", pConfFlag->zName, fieldId, pConfFlag->value));
|
||||
assert(fieldId);
|
||||
(*env)->SetStaticIntField(env, klazz, fieldId, (jint)pLimit->value);
|
||||
switch(pConfFlag->jtype){
|
||||
case JTYPE_INT:
|
||||
(*env)->SetStaticIntField(env, klazz, fieldId, (jint)pConfFlag->value);
|
||||
break;
|
||||
case JTYPE_BOOL:
|
||||
(*env)->SetStaticBooleanField(env, klazz, fieldId,
|
||||
pConfFlag->value ? JNI_TRUE : JNI_FALSE);
|
||||
break;
|
||||
}
|
||||
EXCEPTION_IS_FATAL("Seting a static member of the SQLite3Jni class failed.");
|
||||
}
|
||||
}
|
||||
|
@ -1808,7 +1808,7 @@ JNIEXPORT jobject JNICALL Java_org_sqlite_jni_fts5_1api_getInstanceForDb
|
||||
/*
|
||||
* Class: org_sqlite_jni_fts5_api
|
||||
* Method: xCreateFunction
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/sqlite/jni/fts5_api/fts5_extension_function;)I
|
||||
* Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/sqlite/jni/fts5_extension_function;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_sqlite_jni_fts5_1api_xCreateFunction
|
||||
(JNIEnv *, jobject, jstring, jobject, jobject);
|
||||
|
@ -41,6 +41,10 @@ public final class Fts5ExtensionApi extends NativePointerHolder<Fts5ExtensionApi
|
||||
@NotNull OutputPointer.Int32 pnToken);
|
||||
public native int xColumnText(@NotNull Fts5Context cx, int iCol,
|
||||
@NotNull OutputPointer.ByteArray txt);
|
||||
/**
|
||||
Convenience overload which converts the output byte array
|
||||
to a UTF-8 string.
|
||||
*/
|
||||
public int xColumnText(@NotNull Fts5Context cx, int iCol,
|
||||
@NotNull OutputPointer.String txt){
|
||||
final OutputPointer.ByteArray out = new OutputPointer.ByteArray();
|
||||
|
@ -24,32 +24,32 @@ package org.sqlite.jni;
|
||||
public final class OutputPointer {
|
||||
public static final class Int32 {
|
||||
private int value;
|
||||
Int32(){this(0);}
|
||||
Int32(int v){value = v;}
|
||||
public Int32(){this(0);}
|
||||
public Int32(int v){value = v;}
|
||||
public final int getValue(){return value;}
|
||||
public final void setValue(int v){value = v;}
|
||||
}
|
||||
|
||||
public static final class Int64 {
|
||||
private long value;
|
||||
Int64(){this(0);}
|
||||
Int64(long v){value = v;}
|
||||
public Int64(){this(0);}
|
||||
public Int64(long v){value = v;}
|
||||
public final long getValue(){return value;}
|
||||
public final void setValue(long v){value = v;}
|
||||
}
|
||||
|
||||
public static final class String {
|
||||
private java.lang.String value;
|
||||
String(){this(null);}
|
||||
String(java.lang.String v){value = v;}
|
||||
public String(){this(null);}
|
||||
public String(java.lang.String v){value = v;}
|
||||
public final java.lang.String getValue(){return value;}
|
||||
public final void setValue(java.lang.String v){value = v;}
|
||||
}
|
||||
|
||||
public static final class ByteArray {
|
||||
private byte value[];
|
||||
ByteArray(){this(null);}
|
||||
ByteArray(byte v[]){value = v;}
|
||||
public ByteArray(){this(null);}
|
||||
public ByteArray(byte v[]){value = v;}
|
||||
public final byte[] getValue(){return value;}
|
||||
public final void setValue(byte v[]){value = v;}
|
||||
}
|
||||
|
@ -802,6 +802,11 @@ public final class SQLite3Jni {
|
||||
public static final String SQLITE_VERSION = sqlite3_libversion();
|
||||
public static final String SQLITE_SOURCE_ID = sqlite3_sourceid();
|
||||
|
||||
//! Feature flags which are initialized at lib startup. Necessarily
|
||||
// non-final so that lib init can fill out the proper values,
|
||||
// but modifying them from client code has no effect.
|
||||
public static boolean SQLITE_ENABLE_FTS5 = false;
|
||||
|
||||
// access
|
||||
public static final int SQLITE_ACCESS_EXISTS = 0;
|
||||
public static final int SQLITE_ACCESS_READWRITE = 1;
|
||||
|
@ -915,22 +915,31 @@ public class Tester1 {
|
||||
sqlite3_close_v2(db);
|
||||
}
|
||||
|
||||
/**
|
||||
If FTS5 is available, runs FTS5 tests, else returns with no side
|
||||
effects. If it is available but loading of the FTS5 bits fails,
|
||||
it throws.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void testFts5() throws Exception {
|
||||
if( !SQLITE_ENABLE_FTS5 ){
|
||||
outln("SQLITE_ENABLE_FTS5 is not set. Skipping FTS5 tests.");
|
||||
return;
|
||||
}
|
||||
Exception err = null;
|
||||
try {
|
||||
Class t = Class.forName("org.sqlite.jni.TesterFts5");
|
||||
java.lang.reflect.Constructor ctor = t.getConstructor();
|
||||
ctor.setAccessible(true);
|
||||
ctor.newInstance();
|
||||
ctor.newInstance() /* will run all tests */;
|
||||
}catch(ClassNotFoundException e){
|
||||
outln("FTS5 classes not loaded. Skipping FTS tests.");
|
||||
outln("FTS5 classes not loaded.");
|
||||
err = e;
|
||||
}catch(NoSuchMethodException e){
|
||||
outln("FTS5 tester ctor not found. Skipping FTS tests.");
|
||||
outln("FTS5 tester ctor not found.");
|
||||
err = e;
|
||||
}catch(Exception e){
|
||||
outln("FTS5 tester cannot be instantiated. Skipping FTS tests.");
|
||||
outln("Instantiation of FTS5 tester threw.");
|
||||
err = e;
|
||||
}
|
||||
if( null != err ){
|
||||
|
@ -37,18 +37,21 @@ public class TesterFts5 {
|
||||
final String pUserData = "This is pUserData";
|
||||
ValueHolder<Boolean> xDestroyCalled = new ValueHolder<>(false);
|
||||
ValueHolder<Integer> xFuncCount = new ValueHolder<>(0);
|
||||
fts5_api.fts5_extension_function func = new fts5_api.fts5_extension_function(){
|
||||
final fts5_extension_function func = new fts5_extension_function(){
|
||||
public void xFunction(Fts5ExtensionApi ext, Fts5Context fCx,
|
||||
sqlite3_context pCx, sqlite3_value argv[]){
|
||||
int nCols = ext.xColumnCount(fCx);
|
||||
affirm( 2 == nCols );
|
||||
affirm( nCols == argv.length );
|
||||
affirm( ext.xUserData(fCx) == pUserData );
|
||||
if(false){
|
||||
if(true){
|
||||
OutputPointer.String op = new OutputPointer.String();
|
||||
for(int i = 0; i < nCols; ++i ){
|
||||
int rc = ext.xColumnText(fCx, i, op);
|
||||
affirm( 0 == rc );
|
||||
outln("xFunction col "+i+": "+op.getValue());
|
||||
final String val = op.getValue();
|
||||
affirm( val.equals(sqlite3_value_text(argv[i])) );
|
||||
//outln("xFunction col "+i+": "+val);
|
||||
}
|
||||
}
|
||||
++xFuncCount.value;
|
||||
|
@ -32,20 +32,6 @@ public final class fts5_api extends NativePointerHolder<fts5_api> {
|
||||
*/
|
||||
public static native fts5_api getInstanceForDb(@NotNull sqlite3 db);
|
||||
|
||||
public static abstract class fts5_extension_function {
|
||||
// typedef void (*fts5_extension_function)(
|
||||
// const Fts5ExtensionApi *pApi, /* API offered by current FTS version */
|
||||
// Fts5Context *pFts, /* First arg to pass to pApi functions */
|
||||
// sqlite3_context *pCtx, /* Context for returning result/error */
|
||||
// int nVal, /* Number of values in apVal[] array */
|
||||
// sqlite3_value **apVal /* Array of trailing arguments */
|
||||
// );
|
||||
public abstract void xFunction(Fts5ExtensionApi ext, Fts5Context fCx,
|
||||
sqlite3_context pCx, sqlite3_value argv[]);
|
||||
//! Optionally override
|
||||
public void xDestroy(){}
|
||||
}
|
||||
|
||||
// int (*xCreateTokenizer)(
|
||||
// fts5_api *pApi,
|
||||
// const char *zName,
|
||||
|
37
ext/jni/src/org/sqlite/jni/fts5_extension_function.java
Normal file
37
ext/jni/src/org/sqlite/jni/fts5_extension_function.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
** 2023-08-05
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file is part of the JNI bindings for the sqlite3 C API.
|
||||
*/
|
||||
package org.sqlite.jni;
|
||||
|
||||
/**
|
||||
JNI-level wrapper for C's fts5_extension_function type.
|
||||
|
||||
*/
|
||||
public abstract class fts5_extension_function {
|
||||
// typedef void (*fts5_extension_function)(
|
||||
// const Fts5ExtensionApi *pApi, /* API offered by current FTS version */
|
||||
// Fts5Context *pFts, /* First arg to pass to pApi functions */
|
||||
// sqlite3_context *pCtx, /* Context for returning result/error */
|
||||
// int nVal, /* Number of values in apVal[] array */
|
||||
// sqlite3_value **apVal /* Array of trailing arguments */
|
||||
// );
|
||||
|
||||
/**
|
||||
The callback implementation, corresponding to the xFunction
|
||||
argument of C's fts5_api::xCreateFunction().
|
||||
*/
|
||||
public abstract void xFunction(Fts5ExtensionApi ext, Fts5Context fCx,
|
||||
sqlite3_context pCx, sqlite3_value argv[]);
|
||||
//! Optionally override
|
||||
public void xDestroy(){}
|
||||
}
|
29
manifest
29
manifest
@ -1,5 +1,5 @@
|
||||
C Bind\sFts5ExtensionApi::xUserData()\sto\sJNI\sand\sextend\sxCreateFunction()\sto\saccept\sthat\sargument.\sIn\stest\scode,\suse\sassert()\sinstead\sof\sexceptions\sif\sassert()\sis\senabled\sso\sthat\stest\sfailures\s(exceptions)\sthrown\svia\scallbacks\sdo\snot\sget\ssuppressed\s(which\sthey\sotherwise\snecessarily\sare\sto\savoid\scrashing\sthe\shost\sapp).
|
||||
D 2023-08-05T11:16:54.971
|
||||
C JNI\sinternal\srefactoring\sand\scleanups.
|
||||
D 2023-08-05T12:48:33.207
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -230,32 +230,33 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c
|
||||
F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9
|
||||
F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
|
||||
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
|
||||
F ext/jni/GNUmakefile a875d018a336ae47803cc5ca2768399beaf7b164734612ae9318f56256fc9779
|
||||
F ext/jni/GNUmakefile bb4cd99bd8da534215cb6d278f05a626283eb5d2e8aebdb4d35e548637d35a9a
|
||||
F ext/jni/README.md 6ff7e1f4100dee980434a6ee37a199b653bceec62e233a6e2ccde6e7ae0c58bf
|
||||
F ext/jni/src/c/sqlite3-jni.c db90d821b0129b95ec804bbeab3e223eea34d307a042eab54cdaaeae9e36ec02
|
||||
F ext/jni/src/c/sqlite3-jni.h 7bc36622b63d858b06441b19a2f51be9fc1cf2f8177eb28cf5888c4ab6bd930d
|
||||
F ext/jni/src/c/sqlite3-jni.c 110e133920b469d1ff83ca4c1f23f8b8e6abce40c62b905bedfbdd6d117338a9
|
||||
F ext/jni/src/c/sqlite3-jni.h 96561bfb446e4481dea3016e57299e30ad97bca8a0256c04c83a4068681e6abd
|
||||
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
|
||||
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 eab47de28f43ea5deabf9f3da863067c99f96713421bfad7bebb24bcacef4d1c
|
||||
F ext/jni/src/org/sqlite/jni/Fts5ExtensionApi.java 15e524b997bac1449a273c6eb5d6b095ec7f9d0c88a8f8042d50ec66710e6f28
|
||||
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
|
||||
F ext/jni/src/org/sqlite/jni/NativePointerHolder.java 9c5d901cce4f7e57c3d623f4e2476f9f79a8eed6e51b2a603f37866018e040ee
|
||||
F ext/jni/src/org/sqlite/jni/OutputPointer.java d37636dd3b82097792dae9c8c255b135153845407cdbc6689f15c475850d6c93
|
||||
F ext/jni/src/org/sqlite/jni/OutputPointer.java 013f2b5fe569d0585a695f5cfa605a3be857b4d4622f22ec5f2c28d9b5d6650d
|
||||
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 1c470a8cdb5c61218304eb76b1188e98e562b105eac816557ef512e1b48fa55a
|
||||
F ext/jni/src/org/sqlite/jni/Tester1.java e094dca4c2760dba5cd169906f19a01fb7509a318d47fa76de537a6e610c1c47
|
||||
F ext/jni/src/org/sqlite/jni/TesterFts5.java 52f36beeb8cd61f31d3fb001bef88befd0c7ce55ed0d94476f9bdfe0dadd46cc
|
||||
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java c98b13c1e3843a42cf9959d094ac301113f35a460cbeef3d9cadacdbaa8afeb8
|
||||
F ext/jni/src/org/sqlite/jni/Tester1.java 732d26e858cfe32d664eab805ed8331fcef5cd460b19aa9afac8636f8a92bda3
|
||||
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 97c693d095bfc826c6a2e2906a1fbf53bcbb0aba7798e1135d7957d17d4ad3d4
|
||||
F ext/jni/src/org/sqlite/jni/fts5_api.java ae52ff7f963976fabb7e87b0b8cdb3f9d2ba1838e7d3b79b0b4cb526202d4709
|
||||
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 600c3ddc1ac28ee8f58669fb435fd0d21f2972c652039361fde907d4fe44eb58
|
||||
F ext/jni/src/org/sqlite/jni/sqlite3_context.java d26573fc7b309228cb49786e9078597d96232257defa955a3425d10897bca810
|
||||
@ -2080,8 +2081,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 96281ad0d5b2f020622c4f85f8694886e6a29fb43e1fbeb2a346ed2e94f109fb
|
||||
R f5fddb77ac440b71910871c77b4331be
|
||||
P e43837377696e468cd31cf71585fe235ffe67a9f4d3b036c5f9d0cb7141d0f57
|
||||
R 1c284c5b70026e59635fc8c8a01c3637
|
||||
U stephan
|
||||
Z 93c24d40c86efbed9f0183e7bb02737a
|
||||
Z d433ff069de41673d993c33002d0fb03
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
e43837377696e468cd31cf71585fe235ffe67a9f4d3b036c5f9d0cb7141d0f57
|
||||
7397973a2f191d75b149cf73a6d7ee1798820c1cd37d83af14e565067ede1b04
|
Loading…
Reference in New Issue
Block a user