Skip to content

Commit 8769d89

Browse files
Add 64-bit support to JNI layer
1 parent 2098258 commit 8769d89

11 files changed

+54
-48
lines changed

jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APP_PROJECT_PATH := $(shell pwd)
2-
APP_ABI := armeabi armeabi-v7a x86
2+
APP_ABI := armeabi armeabi-v7a x86 x86_64 arm64-v8a
33
APP_PLATFORM := 21
44
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
55
APP_STL := stlport_static

jni/net_sqlcipher_CursorWindow.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131
#include <wchar.h>
3232
#include <stdlib.h>
3333

34+
#include <stdint.h>
35+
#include <inttypes.h>
36+
3437
namespace sqlcipher {
3538

3639
static jfieldID gWindowField;
3740
static jfieldID gBufferField;
3841
static jfieldID gSizeCopiedField;
3942

40-
#define GET_WINDOW(env, object) ((CursorWindow *)env->GetIntField(object, gWindowField))
41-
#define SET_WINDOW(env, object, window) (env->SetIntField(object, gWindowField, (int)window))
43+
#define GET_WINDOW(env, object) ((CursorWindow *)env->GetLongField(object, gWindowField))
44+
#define SET_WINDOW(env, object, window) (env->SetLongField(object, gWindowField,(intptr_t)window))
4245
#define SET_BUFFER(env, object, buf) (env->SetObjectField(object, gBufferField, buf))
4346
#define SET_SIZE_COPIED(env, object, size) (env->SetIntField(object, gSizeCopiedField, size))
4447

@@ -280,7 +283,7 @@ namespace sqlcipher {
280283
int64_t value;
281284
if (window->getLong(row, column, &value)) {
282285
char buf[32];
283-
snprintf(buf, sizeof(buf), "%lld", value);
286+
snprintf(buf, sizeof(buf), "%"PRId64"", value);
284287
return env->NewStringUTF((const char*)buf);
285288
}
286289
return NULL;
@@ -356,7 +359,7 @@ namespace sqlcipher {
356359
if (window->getLong(row, column, &value)) {
357360
int len;
358361
char buf[32];
359-
len = snprintf(buf, sizeof(buf), "%lld", value);
362+
len = snprintf(buf, sizeof(buf), "%"PRId64"", value);
360363
jint bufferLength = env->GetArrayLength(buffer);
361364
if(len > bufferLength || dst == NULL){
362365
jstring content = env->NewStringUTF(buf);
@@ -649,7 +652,7 @@ namespace sqlcipher {
649652
LOGE("Can't find net/sqlcipher/CursorWindow");
650653
return -1;
651654
}
652-
gWindowField = env->GetFieldID(clazz, "nWindow", "I");
655+
gWindowField = env->GetFieldID(clazz, "nWindow", "J");
653656
if (gWindowField == NULL) {
654657
LOGE("Error locating fields");
655658
return -1;

jni/net_sqlcipher_database_SQLiteCompiledSql.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ static jfieldID gStatementField;
3838

3939

4040
#define GET_STATEMENT(env, object) \
41-
(sqlite3_stmt *)env->GetIntField(object, gStatementField)
41+
(sqlite3_stmt *)env->GetLongField(object, gStatementField)
4242
#define GET_HANDLE(env, object) \
43-
(sqlite3 *)env->GetIntField(object, gHandleField)
43+
(sqlite3 *)env->GetLongField(object, gHandleField)
4444

4545

4646
sqlite3_stmt * compile(JNIEnv* env, jobject object,
@@ -54,7 +54,7 @@ sqlite3_stmt * compile(JNIEnv* env, jobject object,
5454
// Make sure not to leak the statement if it already exists
5555
if (statement != NULL) {
5656
sqlite3_finalize(statement);
57-
env->SetIntField(object, gStatementField, 0);
57+
env->SetLongField(object, gStatementField, 0);
5858
}
5959

6060
// Compile the SQL
@@ -66,7 +66,7 @@ sqlite3_stmt * compile(JNIEnv* env, jobject object,
6666
if (err == SQLITE_OK) {
6767
// Store the statement in the Java object for future calls
6868
LOGV("Prepared statement %p on %p", statement, handle);
69-
env->SetIntField(object, gStatementField, (int)statement);
69+
env->SetLongField(object, gStatementField, (intptr_t)statement);
7070
return statement;
7171
} else {
7272
// Error messages like 'near ")": syntax error' are not
@@ -97,7 +97,7 @@ static void native_finalize(JNIEnv* env, jobject object)
9797

9898
if (statement != NULL) {
9999
sqlite3_finalize(statement);
100-
env->SetIntField(object, gStatementField, 0);
100+
env->SetLongField(object, gStatementField, 0);
101101
}
102102
}
103103

@@ -118,8 +118,8 @@ int register_android_database_SQLiteCompiledSql(JNIEnv * env)
118118
return -1;
119119
}
120120

121-
gHandleField = env->GetFieldID(clazz, "nHandle", "I");
122-
gStatementField = env->GetFieldID(clazz, "nStatement", "I");
121+
gHandleField = env->GetFieldID(clazz, "nHandle", "J");
122+
gStatementField = env->GetFieldID(clazz, "nStatement", "J");
123123

124124
if (gHandleField == NULL || gStatementField == NULL) {
125125
LOGE("Error locating fields");

jni/net_sqlcipher_database_SQLiteDatabase.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace sqlcipher {
8585
{
8686
int value;
8787
int highWater;
88-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
88+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
8989
int status = sqlite3_status(operation, &value, &highWater, reset);
9090
if(status != SQLITE_OK){
9191
throw_sqlite3_exception(env, handle);
@@ -99,7 +99,10 @@ namespace sqlcipher {
9999
jsize size = 0;
100100
jbyte *key = 0;
101101
sqlite3 *handle = NULL;
102-
handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
102+
handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
103+
if(handle == NULL){
104+
LOGE("env->GetLongField returned NULL when retrieving sqlite3 *\n");
105+
}
103106
key = env->GetByteArrayElements(jKey, NULL);
104107
size = env->GetArrayLength(jKey);
105108
if(key == NULL || size == 0) goto done;
@@ -116,7 +119,7 @@ namespace sqlcipher {
116119
jsize size = 0;
117120
jbyte *key = 0;
118121
sqlite3 *handle = NULL;
119-
handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
122+
handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
120123
key = env->GetByteArrayElements(jKey, NULL);
121124
size = env->GetArrayLength(jKey);
122125
if(key == NULL || size == 0) goto done;
@@ -133,7 +136,7 @@ namespace sqlcipher {
133136
int idx;
134137
jint releaseElements = 0;
135138
jboolean arrayIsCopy;
136-
sqlite3 *handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
139+
sqlite3 *handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
137140
jsize sz = env->GetArrayLength(jKey);
138141
jchar* jKeyChar = env->GetCharArrayElements(jKey, &arrayIsCopy);
139142
jstring key = env->NewString(jKeyChar, sz);
@@ -151,7 +154,7 @@ namespace sqlcipher {
151154

152155
void native_rawExecSQL(JNIEnv* env, jobject object, jstring sql)
153156
{
154-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
157+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
155158
char const * sqlCommand = env->GetStringUTFChars(sql, NULL);
156159
int status = sqlite3_exec(handle, sqlCommand, NULL, NULL, NULL);
157160
env->ReleaseStringUTFChars(sql, sqlCommand);
@@ -244,7 +247,7 @@ namespace sqlcipher {
244247
sqlite3_enable_load_extension(handle, 1);
245248

246249
LOGV("Opened '%s' - %p\n", path8, handle);
247-
env->SetIntField(object, offset_db_handle, (int) handle);
250+
env->SetLongField(object, offset_db_handle, (intptr_t)handle);
248251
handle = NULL; // The caller owns the handle now.
249252

250253
done:
@@ -272,7 +275,7 @@ namespace sqlcipher {
272275
/* public native void enableSqlTracing(); */
273276
static void enableSqlTracing(JNIEnv* env, jobject object, jstring databaseName)
274277
{
275-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
278+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
276279
sqlite3_trace(handle, &sqlTrace, (void *)getDatabaseName(env, handle, databaseName));
277280
}
278281

@@ -284,15 +287,15 @@ namespace sqlcipher {
284287
/* public native void enableSqlProfiling(); */
285288
static void enableSqlProfiling(JNIEnv* env, jobject object, jstring databaseName)
286289
{
287-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
290+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
288291
sqlite3_profile(handle, &sqlProfile, (void *)getDatabaseName(env, handle, databaseName));
289292
}
290293

291294

292295
/* public native void close(); */
293296
static void dbclose(JNIEnv* env, jobject object)
294297
{
295-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
298+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
296299

297300
if (handle != NULL) {
298301
// release the memory associated with the traceFuncArg in enableSqlTracing function
@@ -309,7 +312,7 @@ namespace sqlcipher {
309312
int result = sqlite3_close(handle);
310313
if (result == SQLITE_OK) {
311314
LOGV("Closed %p\n", handle);
312-
env->SetIntField(object, offset_db_handle, 0);
315+
env->SetLongField(object, offset_db_handle, 0);
313316
} else {
314317
// This can happen if sub-objects aren't closed first. Make sure the caller knows.
315318
LOGE("sqlite3_close(%p) failed: %d\n", handle, result);
@@ -324,7 +327,7 @@ namespace sqlcipher {
324327
int err;
325328
int stepErr;
326329
sqlite3_stmt * statement = NULL;
327-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
330+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
328331
jchar const * sql = env->GetStringChars(sqlString, NULL);
329332
jsize sqlLen = env->GetStringLength(sqlString);
330333

@@ -372,23 +375,23 @@ namespace sqlcipher {
372375
/* native long lastInsertRow(); */
373376
static jlong lastInsertRow(JNIEnv* env, jobject object)
374377
{
375-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
378+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
376379

377380
return sqlite3_last_insert_rowid(handle);
378381
}
379382

380383
/* native int lastChangeCount(); */
381384
static jint lastChangeCount(JNIEnv* env, jobject object)
382385
{
383-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
386+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
384387

385388
return sqlite3_changes(handle);
386389
}
387390

388391
/* native int native_getDbLookaside(); */
389392
static jint native_getDbLookaside(JNIEnv* env, jobject object)
390393
{
391-
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
394+
sqlite3 * handle = (sqlite3 *)env->GetLongField(object, offset_db_handle);
392395
int pCur = -1;
393396
int unused;
394397
sqlite3_db_status(handle, SQLITE_DBSTATUS_LOOKASIDE_USED, &pCur, &unused, 0);
@@ -550,7 +553,7 @@ namespace sqlcipher {
550553
return -1;
551554
}
552555

553-
offset_db_handle = env->GetFieldID(clazz, "mNativeHandle", "I");
556+
offset_db_handle = env->GetFieldID(clazz, "mNativeHandle", "J");
554557
if (offset_db_handle == NULL) {
555558
LOGE("Can't find SQLiteDatabase.mNativeHandle\n");
556559
return -1;

jni/net_sqlcipher_database_SQLiteProgram.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ static jfieldID gStatementField;
3838

3939

4040
#define GET_STATEMENT(env, object) \
41-
(sqlite3_stmt *)env->GetIntField(object, gStatementField)
41+
(sqlite3_stmt *)env->GetLongField(object, gStatementField)
4242
#define GET_HANDLE(env, object) \
43-
(sqlite3 *)env->GetIntField(object, gHandleField)
43+
(sqlite3 *)env->GetLongField(object, gHandleField)
4444

4545
static void native_compile(JNIEnv* env, jobject object, jstring sqlString)
4646
{
@@ -179,8 +179,8 @@ int register_android_database_SQLiteProgram(JNIEnv * env)
179179
return -1;
180180
}
181181

182-
gHandleField = env->GetFieldID(clazz, "nHandle", "I");
183-
gStatementField = env->GetFieldID(clazz, "nStatement", "I");
182+
gHandleField = env->GetFieldID(clazz, "nHandle", "J");
183+
gStatementField = env->GetFieldID(clazz, "nStatement", "J");
184184

185185
if (gHandleField == NULL || gStatementField == NULL) {
186186
LOGE("Error locating fields");

jni/net_sqlcipher_database_SQLiteQuery.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ static jfieldID gStatementField;
4444

4545

4646
#define GET_STATEMENT(env, object) \
47-
(sqlite3_stmt *)env->GetIntField(object, gStatementField)
47+
(sqlite3_stmt *)env->GetLongField(object, gStatementField)
4848
#define GET_HANDLE(env, object) \
49-
(sqlite3 *)env->GetIntField(object, gHandleField)
49+
(sqlite3 *)env->GetLongField(object, gHandleField)
5050

5151
static int skip_rows(sqlite3_stmt *statement, int maxRows) {
5252
int retryCount = 0;
@@ -342,8 +342,8 @@ int register_android_database_SQLiteQuery(JNIEnv * env)
342342
return -1;
343343
}
344344

345-
gHandleField = env->GetFieldID(clazz, "nHandle", "I");
346-
gStatementField = env->GetFieldID(clazz, "nStatement", "I");
345+
gHandleField = env->GetFieldID(clazz, "nHandle", "J");
346+
gStatementField = env->GetFieldID(clazz, "nStatement", "J");
347347

348348
if (gHandleField == NULL || gStatementField == NULL) {
349349
LOGE("Error locating fields");

jni/net_sqlcipher_database_SQLiteStatement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static jfieldID gStatementField;
3939

4040

4141
#define GET_STATEMENT(env, object) \
42-
(sqlite3_stmt *)env->GetIntField(object, gStatementField)
42+
(sqlite3_stmt *)env->GetLongField(object, gStatementField)
4343
#define GET_HANDLE(env, object) \
44-
(sqlite3 *)env->GetIntField(object, gHandleField)
44+
(sqlite3 *)env->GetLongField(object, gHandleField)
4545

4646

4747
static void native_execute(JNIEnv* env, jobject object)
@@ -136,8 +136,8 @@ int register_android_database_SQLiteStatement(JNIEnv * env)
136136
return -1;
137137
}
138138

139-
gHandleField = env->GetFieldID(clazz, "nHandle", "I");
140-
gStatementField = env->GetFieldID(clazz, "nStatement", "I");
139+
gHandleField = env->GetFieldID(clazz, "nHandle", "J");
140+
gStatementField = env->GetFieldID(clazz, "nStatement", "J");
141141

142142
if (gHandleField == NULL || gStatementField == NULL) {
143143
LOGE("Error locating fields");

src/net/sqlcipher/CursorWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class CursorWindow extends android.database.CursorWindow implements Parce
4141
/** The pointer to the native window class. set by the native methods in
4242
* android_database_CursorWindow.cpp
4343
*/
44-
private int nWindow;
44+
private long nWindow;
4545

4646
private int mStartPos;
4747

src/net/sqlcipher/database/SQLiteCompiledSql.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636
/**
3737
* Native linkage, do not modify. This comes from the database.
3838
*/
39-
/* package */ int nHandle = 0;
39+
/* package */ long nHandle = 0;
4040

4141
/**
4242
* Native linkage, do not modify. When non-0 this holds a reference to a valid
4343
* sqlite3_statement object. It is only updated by the native code, but may be
4444
* checked in this class when the database lock is held to determine if there
4545
* is a valid native-side program or not.
4646
*/
47-
/* package */ int nStatement = 0;
47+
/* package */ long nStatement = 0;
4848

4949
/** the following are for debugging purposes */
5050
private String mSqlStmt = null;

src/net/sqlcipher/database/SQLiteDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public static synchronized void loadLibs (Context context, File workingDir) {
374374
/* package */ static final String GET_LOCK_LOG_PREFIX = "GETLOCK:";
375375

376376
/** Used by native code, do not rename */
377-
/* package */ int mNativeHandle = 0;
377+
/* package */ long mNativeHandle = 0;
378378

379379
/** Used to make temp table names unique */
380380
/* package */ int mTempTableSequence = 0;

0 commit comments

Comments
 (0)