Expose sqlite3_randomness() to JNI.
FossilOrigin-Name: de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf
This commit is contained in:
parent
83a8b6dd82
commit
1943356268
@ -813,15 +813,17 @@ static const char * s3jni__jstring_to_mutf8_bytes(JNIEnv * const env, jstring v
|
||||
#define s3jni_jstring_to_mutf8(ARG) s3jni__jstring_to_mutf8_bytes(env, (ARG))
|
||||
#define s3jni_mutf8_release(ARG,VAR) if( VAR ) (*env)->ReleaseStringUTFChars(env, ARG, VAR)
|
||||
|
||||
static jbyte * s3jni__jbytearray_bytes(JNIEnv * const env, jbyteArray jBA ){
|
||||
static jbyte * s3jni__jbyteArray_bytes(JNIEnv * const env, jbyteArray jBA ){
|
||||
jbyte * const rv = jBA ? (*env)->GetByteArrayElements(env, jBA, NULL) : 0;
|
||||
s3jni_oom_check( jBA ? !!rv : 1 );
|
||||
return rv;
|
||||
}
|
||||
|
||||
#define s3jni_jbytearray_bytes(jByteArray) s3jni__jbytearray_bytes(env, (jByteArray))
|
||||
#define s3jni_jbytearray_release(jByteArray,jBytes) \
|
||||
#define s3jni_jbyteArray_bytes(jByteArray) s3jni__jbyteArray_bytes(env, (jByteArray))
|
||||
#define s3jni_jbyteArray_release(jByteArray,jBytes) \
|
||||
if( jBytes ) (*env)->ReleaseByteArrayElements(env, jByteArray, jBytes, JNI_ABORT)
|
||||
#define s3jni_jbyteArray_commit(jByteArray,jBytes) \
|
||||
if( jBytes ) (*env)->ReleaseByteArrayElements(env, jByteArray, jBytes, JNI_COMMIT)
|
||||
|
||||
/*
|
||||
** Returns the current JNIEnv object. Fails fatally if it cannot find
|
||||
@ -2306,12 +2308,12 @@ S3JniApi(sqlite3_backup_step(),jint,1backup_1step)(
|
||||
S3JniApi(sqlite3_bind_blob(),jint,1bind_1blob)(
|
||||
JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax
|
||||
){
|
||||
jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0;
|
||||
jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0;
|
||||
int rc;
|
||||
if( pBuf ){
|
||||
rc = sqlite3_bind_blob(PtrGet_sqlite3_stmt(jpStmt), (int)ndx,
|
||||
pBuf, (int)nMax, SQLITE_TRANSIENT);
|
||||
s3jni_jbytearray_release(baData, pBuf);
|
||||
s3jni_jbyteArray_release(baData, pBuf);
|
||||
}else{
|
||||
rc = baData
|
||||
? SQLITE_NOMEM
|
||||
@ -2371,11 +2373,11 @@ S3JniApi(sqlite3_bind_parameter_index(),jint,1bind_1parameter_1index)(
|
||||
JniArgsEnvClass, jobject jpStmt, jbyteArray jName
|
||||
){
|
||||
int rc = 0;
|
||||
jbyte * const pBuf = s3jni_jbytearray_bytes(jName);
|
||||
jbyte * const pBuf = s3jni_jbyteArray_bytes(jName);
|
||||
if( pBuf ){
|
||||
rc = sqlite3_bind_parameter_index(PtrGet_sqlite3_stmt(jpStmt),
|
||||
(const char *)pBuf);
|
||||
s3jni_jbytearray_release(jName, pBuf);
|
||||
s3jni_jbyteArray_release(jName, pBuf);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@ -2383,21 +2385,21 @@ S3JniApi(sqlite3_bind_parameter_index(),jint,1bind_1parameter_1index)(
|
||||
S3JniApi(sqlite3_bind_text(),jint,1bind_1text)(
|
||||
JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax
|
||||
){
|
||||
jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0;
|
||||
jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0;
|
||||
int const rc = sqlite3_bind_text(PtrGet_sqlite3_stmt(jpStmt), (int)ndx,
|
||||
(const char *)pBuf,
|
||||
(int)nMax, SQLITE_TRANSIENT);
|
||||
s3jni_jbytearray_release(baData, pBuf);
|
||||
s3jni_jbyteArray_release(baData, pBuf);
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
S3JniApi(sqlite3_bind_text16(),jint,1bind_1text16)(
|
||||
JniArgsEnvClass, jobject jpStmt, jint ndx, jbyteArray baData, jint nMax
|
||||
){
|
||||
jbyte * const pBuf = baData ? s3jni_jbytearray_bytes(baData) : 0;
|
||||
jbyte * const pBuf = baData ? s3jni_jbyteArray_bytes(baData) : 0;
|
||||
int const rc = sqlite3_bind_text16(PtrGet_sqlite3_stmt(jpStmt), (int)ndx,
|
||||
pBuf, (int)nMax, SQLITE_TRANSIENT);
|
||||
s3jni_jbytearray_release(baData, pBuf);
|
||||
s3jni_jbyteArray_release(baData, pBuf);
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
@ -2812,7 +2814,7 @@ S3JniApi(sqlite3_compileoption_get(),jstring,1compileoption_1get)(
|
||||
S3JniApi(sqlite3_complete(),int,1complete)(
|
||||
JniArgsEnvClass, jbyteArray jSql
|
||||
){
|
||||
jbyte * const pBuf = s3jni_jbytearray_bytes(jSql);
|
||||
jbyte * const pBuf = s3jni_jbyteArray_bytes(jSql);
|
||||
const jsize nBa = pBuf ? (*env)->GetArrayLength(env, jSql) : 0;
|
||||
int rc;
|
||||
|
||||
@ -2821,7 +2823,7 @@ S3JniApi(sqlite3_complete(),int,1complete)(
|
||||
rc = (pBuf && 0==pBuf[(nBa ? nBa-1 : 0)])
|
||||
? sqlite3_complete( (const char *)pBuf )
|
||||
: (jSql ? SQLITE_NOMEM : SQLITE_ERROR);
|
||||
s3jni_jbytearray_release(jSql, pBuf);
|
||||
s3jni_jbyteArray_release(jSql, pBuf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -3556,7 +3558,7 @@ jint sqlite3_jni_prepare_v123( int prepVersion, JNIEnv * const env, jclass self,
|
||||
sqlite3_stmt * pStmt = 0;
|
||||
jobject jStmt = 0;
|
||||
const char * zTail = 0;
|
||||
jbyte * const pBuf = s3jni_jbytearray_bytes(baSql);
|
||||
jbyte * const pBuf = s3jni_jbyteArray_bytes(baSql);
|
||||
int rc = SQLITE_ERROR;
|
||||
assert(prepVersion==1 || prepVersion==2 || prepVersion==3);
|
||||
if( !pBuf ){
|
||||
@ -3583,7 +3585,7 @@ jint sqlite3_jni_prepare_v123( int prepVersion, JNIEnv * const env, jclass self,
|
||||
assert(0 && "Invalid prepare() version");
|
||||
}
|
||||
end:
|
||||
s3jni_jbytearray_release(baSql,pBuf);
|
||||
s3jni_jbyteArray_release(baSql,pBuf);
|
||||
if( 0==rc ){
|
||||
if( 0!=outTail ){
|
||||
/* Noting that pBuf is deallocated now but its address is all we need for
|
||||
@ -3885,6 +3887,18 @@ S3JniApi(sqlite3_progress_handler(),void,1progress_1handler)(
|
||||
S3JniDb_mutex_leave;
|
||||
}
|
||||
|
||||
S3JniApi(sqlite3_randomness(),void,1randomness)(
|
||||
JniArgsEnvClass, jbyteArray jTgt
|
||||
){
|
||||
jbyte * const jba = s3jni_jbyteArray_bytes(jTgt);
|
||||
if( jba ){
|
||||
jsize const nTgt = (*env)->GetArrayLength(env, jTgt);
|
||||
sqlite3_randomness( (int)nTgt, jba );
|
||||
s3jni_jbyteArray_commit(jTgt, jba);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
S3JniApi(sqlite3_reset(),jint,1reset)(
|
||||
JniArgsEnvClass, jobject jpStmt
|
||||
){
|
||||
@ -3916,7 +3930,7 @@ static void result_blob_text(int as64 /* true for text64/blob64() mode */,
|
||||
jbyteArray jBa, jlong nMax){
|
||||
int const asBlob = 0==eTextRep;
|
||||
if( jBa ){
|
||||
jbyte * const pBuf = s3jni_jbytearray_bytes(jBa);
|
||||
jbyte * const pBuf = s3jni_jbyteArray_bytes(jBa);
|
||||
jsize nBa = (*env)->GetArrayLength(env, jBa);
|
||||
if( nMax>=0 && nBa>(jsize)nMax ){
|
||||
nBa = (jsize)nMax;
|
||||
@ -3980,7 +3994,7 @@ static void result_blob_text(int as64 /* true for text64/blob64() mode */,
|
||||
break;
|
||||
}
|
||||
}
|
||||
s3jni_jbytearray_release(jBa, pBuf);
|
||||
s3jni_jbyteArray_release(jBa, pBuf);
|
||||
}
|
||||
}else{
|
||||
sqlite3_result_null(pCx);
|
||||
@ -4010,7 +4024,7 @@ S3JniApi(sqlite3_result_error(),void,1result_1error)(
|
||||
){
|
||||
const char * zUnspecified = "Unspecified error.";
|
||||
jsize const baLen = (*env)->GetArrayLength(env, baMsg);
|
||||
jbyte * const pjBuf = baMsg ? s3jni_jbytearray_bytes(baMsg) : NULL;
|
||||
jbyte * const pjBuf = baMsg ? s3jni_jbyteArray_bytes(baMsg) : NULL;
|
||||
switch( pjBuf ? eTextRep : SQLITE_UTF8 ){
|
||||
case SQLITE_UTF8: {
|
||||
const char *zMsg = pjBuf ? (const char *)pjBuf : zUnspecified;
|
||||
@ -4029,7 +4043,7 @@ S3JniApi(sqlite3_result_error(),void,1result_1error)(
|
||||
"to sqlite3_result_error().", -1);
|
||||
break;
|
||||
}
|
||||
s3jni_jbytearray_release(baMsg,pjBuf);
|
||||
s3jni_jbyteArray_release(baMsg,pjBuf);
|
||||
}
|
||||
|
||||
S3JniApi(sqlite3_result_error_code(),void,1result_1error_1code)(
|
||||
@ -4303,8 +4317,8 @@ S3JniApi(sqlite3_status64(),jint,1status64)(
|
||||
static int s3jni_strlike_glob(int isLike, JNIEnv *const env,
|
||||
jbyteArray baG, jbyteArray baT, jint escLike){
|
||||
int rc = 0;
|
||||
jbyte * const pG = s3jni_jbytearray_bytes(baG);
|
||||
jbyte * const pT = pG ? s3jni_jbytearray_bytes(baT) : 0;
|
||||
jbyte * const pG = s3jni_jbyteArray_bytes(baG);
|
||||
jbyte * const pT = pG ? s3jni_jbyteArray_bytes(baT) : 0;
|
||||
|
||||
s3jni_oom_fatal(pT);
|
||||
/* Note that we're relying on the byte arrays having been
|
||||
@ -4313,8 +4327,8 @@ static int s3jni_strlike_glob(int isLike, JNIEnv *const env,
|
||||
? sqlite3_strlike((const char *)pG, (const char *)pT,
|
||||
(unsigned int)escLike)
|
||||
: sqlite3_strglob((const char *)pG, (const char *)pT);
|
||||
s3jni_jbytearray_release(baG, pG);
|
||||
s3jni_jbytearray_release(baT, pT);
|
||||
s3jni_jbyteArray_release(baG, pG);
|
||||
s3jni_jbyteArray_release(baT, pT);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -5229,7 +5243,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef,
|
||||
S3JniEnv * const jc = S3JniEnv_get();
|
||||
struct s3jni_xQueryPhraseState s;
|
||||
int rc = 0;
|
||||
jbyte * const pText = jCallback ? s3jni_jbytearray_bytes(jbaText) : 0;
|
||||
jbyte * const pText = jCallback ? s3jni_jbyteArray_bytes(jbaText) : 0;
|
||||
jsize nText = pText ? (*env)->GetArrayLength(env, jbaText) : 0;
|
||||
jclass const klazz = jCallback ? (*env)->GetObjectClass(env, jCallback) : NULL;
|
||||
|
||||
@ -5244,7 +5258,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef,
|
||||
S3JniIfThrew {
|
||||
S3JniExceptionReport;
|
||||
S3JniExceptionClear;
|
||||
s3jni_jbytearray_release(jbaText, pText);
|
||||
s3jni_jbyteArray_release(jbaText, pText);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
s.tok.jba = S3JniRefLocal(jbaText);
|
||||
@ -5266,7 +5280,7 @@ static jint s3jni_fts5_xTokenize(JniArgsEnvObj, S3JniNphOp const *pRef,
|
||||
assert( s.tok.zPrev );
|
||||
S3JniUnrefLocal(s.tok.jba);
|
||||
}
|
||||
s3jni_jbytearray_release(jbaText, pText);
|
||||
s3jni_jbyteArray_release(jbaText, pText);
|
||||
return (jint)rc;
|
||||
}
|
||||
|
||||
@ -5465,15 +5479,15 @@ Java_org_sqlite_jni_tester_SQLTester_strglob(
|
||||
JniArgsEnvClass, jbyteArray baG, jbyteArray baT
|
||||
){
|
||||
int rc = 0;
|
||||
jbyte * const pG = s3jni_jbytearray_bytes(baG);
|
||||
jbyte * const pT = pG ? s3jni_jbytearray_bytes(baT) : 0;
|
||||
jbyte * const pG = s3jni_jbyteArray_bytes(baG);
|
||||
jbyte * const pT = pG ? s3jni_jbyteArray_bytes(baT) : 0;
|
||||
|
||||
s3jni_oom_fatal(pT);
|
||||
/* Note that we're relying on the byte arrays having been
|
||||
NUL-terminated on the Java side. */
|
||||
rc = !SQLTester_strnotglob((const char *)pG, (const char *)pT);
|
||||
s3jni_jbytearray_release(baG, pG);
|
||||
s3jni_jbytearray_release(baT, pT);
|
||||
s3jni_jbyteArray_release(baG, pG);
|
||||
s3jni_jbyteArray_release(baT, pT);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -1531,6 +1531,14 @@ JNIEXPORT jint JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1preupdate_1old
|
||||
JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1progress_1handler
|
||||
(JNIEnv *, jclass, jobject, jint, jobject);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_randomness
|
||||
* Signature: ([B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_sqlite_jni_SQLite3Jni_sqlite3_1randomness
|
||||
(JNIEnv *, jclass, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: org_sqlite_jni_SQLite3Jni
|
||||
* Method: sqlite3_release_memory
|
||||
|
@ -1040,6 +1040,9 @@ public final class SQLite3Jni {
|
||||
@NotNull sqlite3 db, int n, @Nullable ProgressHandlerCallback h
|
||||
);
|
||||
|
||||
@Canonical
|
||||
public static native void sqlite3_randomness(byte[] target);
|
||||
|
||||
@Canonical
|
||||
public static native int sqlite3_release_memory(int n);
|
||||
|
||||
|
@ -1522,6 +1522,20 @@ public class Tester1 implements Runnable {
|
||||
sqlite3_close_v2(db2);
|
||||
}
|
||||
|
||||
private void testRandomness(){
|
||||
byte[] foo = new byte[20];
|
||||
int i = 0;
|
||||
for( byte b : foo ){
|
||||
i += b;
|
||||
}
|
||||
affirm( i==0 );
|
||||
sqlite3_randomness(foo);
|
||||
for( byte b : foo ){
|
||||
if(b!=0) ++i;
|
||||
}
|
||||
affirm( i!=0, "There's a very slight chance that 0 is actually correct." );
|
||||
}
|
||||
|
||||
/* Copy/paste/rename this to add new tests. */
|
||||
private void _testTemplate(){
|
||||
final sqlite3 db = createNewDb();
|
||||
|
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Expose\ssqlite3_get/set_auxdata()\sto\sJNI.
|
||||
D 2023-09-03T11:58:33.070
|
||||
C Expose\ssqlite3_randomness()\sto\sJNI.
|
||||
D 2023-09-03T12:17:34.015
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -237,8 +237,8 @@ F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a3
|
||||
F ext/jni/GNUmakefile 7bd7f0c28d664b71b08f9d8ff507eb8329f1f3e7b5d88f774f90a1a5259a3fe8
|
||||
F ext/jni/README.md 1332b1fa27918bd5d9ca2d0d4f3ac3a6ab86b9e3699dc5bfe32904a027f3d2a9
|
||||
F ext/jni/jar-dist.make 030aaa4ae71dd86e4ec5e7c1e6cd86f9dfa47c4592c070d2e35157e42498e1fa
|
||||
F ext/jni/src/c/sqlite3-jni.c 649b305d2281d350067b63b1d077410a38ae9a06366634ee5e22131ba070c1ef
|
||||
F ext/jni/src/c/sqlite3-jni.h c95632356c61ccc5975c41bf35e5bc79d24fd1e8375d068731ea0b2f625b51f7
|
||||
F ext/jni/src/c/sqlite3-jni.c 0f10efb673d94b2a4b0b76e42cc8951341df6197d8454f08b6db25b1554242c5
|
||||
F ext/jni/src/c/sqlite3-jni.h c3d1fa02f34bd5d2d71c9172be7732e59624cbc3639419ae3929512c18e102dc
|
||||
F ext/jni/src/org/sqlite/jni/AbstractCollationCallback.java 95e88ba04f4aac51ffec65693e878e234088b2f21b387f4e4285c8b72b33e436
|
||||
F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515799194e031f45edbe16a6373cea18f404dc4
|
||||
F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java e6135be32f12bf140bffa39be7fd1a45ad83b2661ed49c08dbde04c8485feb38
|
||||
@ -262,10 +262,10 @@ F ext/jni/src/org/sqlite/jni/ProgressHandlerCallback.java 7b9ff2218129ece98ba60c
|
||||
F ext/jni/src/org/sqlite/jni/ResultCode.java ba701f20213a5f259e94cfbfdd36eb7ac7ce7797f2c6c7fca2004ff12ce20f86
|
||||
F ext/jni/src/org/sqlite/jni/RollbackHookCallback.java d12352c0e22840de484ffa9b11ed5058bb0daca2e9f218055d3c54c947a273c4
|
||||
F ext/jni/src/org/sqlite/jni/SQLFunction.java 544a875d33fd160467d82e2397ac33157b29971d715a821a4fad3c899113ee8c
|
||||
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java e84f456b5f1636f45c50f1d532247631a1569c99a3a504d04c9ed4f4ed3fbf02
|
||||
F ext/jni/src/org/sqlite/jni/SQLite3Jni.java 8ed33203f0958c32571112164d79edd22b00bb0de4c0f5108e1a5ebf2534ce20
|
||||
F ext/jni/src/org/sqlite/jni/ScalarFunction.java 6d387bb499fbe3bc13c53315335233dbf6a0c711e8fa7c521683219b041c614c
|
||||
F ext/jni/src/org/sqlite/jni/TableColumnMetadata.java 54511b4297fa28dcb3f49b24035e34ced10e3fd44fd0e458e784f4d6b0096dab
|
||||
F ext/jni/src/org/sqlite/jni/Tester1.java 0c37badac93c948d340688967fa205062fa70d6fd1c72730b5ececc1419319cd
|
||||
F ext/jni/src/org/sqlite/jni/Tester1.java caf32da9a15a1202bdb801a036c233864bf676569143057f83d70b5ba2f44ae5
|
||||
F ext/jni/src/org/sqlite/jni/TesterFts5.java 1d127690daac4751300b277a14c09faa0cefd1efa365580cd8d95ea658e1ee59
|
||||
F ext/jni/src/org/sqlite/jni/TraceV2Callback.java beb0b064c1a5f8bfe585a324ed39a4e33edbe379a3fc60f1401661620d3ca7c0
|
||||
F ext/jni/src/org/sqlite/jni/UpdateHookCallback.java 8376f4a931f2d5612b295c003c9515ba933ee76d8f95610e89c339727376e36c
|
||||
@ -2117,8 +2117,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 67391c6588c71af411767d1e4b63c5041a8a9e669102da318e3482ccfc9d9bb9
|
||||
R 85fc08c8b7dbbee0a10820fd8df0b1f2
|
||||
P 0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed
|
||||
R 1c9493f53aa49acbc7601207cf3c352b
|
||||
U stephan
|
||||
Z d25cca227f7f4f43edfdc564cc64fc9b
|
||||
Z a919ad1706be2f43ac4c9258eceb6670
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
0de3271717e0298070097d7ea0ecb996d2e95cf65384e494515a554d0a1dffed
|
||||
de9692242132b8f2c92ef4acb08dd3063327b18666cbb17c4f1153dee9146eaf
|
Loading…
Reference in New Issue
Block a user