diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-11-17 10:47:02 +0100 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-12-04 23:04:27 +0100 |
commit | 515a8cf4005cb146052256ff4b9ac2de895849ae (patch) | |
tree | 86c186054e3c1343000656a287bc58635d7adfed /sal | |
parent | 333a894ba84553762542c47636791f92360c69b5 (diff) |
android: use ByteBuffer to send or store pointers in JNI bindings
Using direct ByteBuffer is much nicer option to store or send
pointers between C(++) code and Java via JNI as it handles endiness
and pointer size for us. Using "long" type can have unexpected
results in 32-bit architectures (mostly Android). This was causing
grief especially when Android introduced support for 64-bit
architectures starting with SDK 19.
Change-Id: Ie92d0f913b668e1724e846d70d1820445d9cb086
Diffstat (limited to 'sal')
-rw-r--r-- | sal/android/libreofficekit-jni.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sal/android/libreofficekit-jni.c b/sal/android/libreofficekit-jni.c index 416198234051..41fa97e8273d 100644 --- a/sal/android/libreofficekit-jni.c +++ b/sal/android/libreofficekit-jni.c @@ -147,13 +147,17 @@ jboolean Java_org_libreoffice_kit_LibreOfficeKit_initializeNative } __attribute__ ((visibility("default"))) -jlong Java_org_libreoffice_kit_LibreOfficeKit_getLibreOfficeKitHandle +jobject Java_org_libreoffice_kit_LibreOfficeKit_getLibreOfficeKitHandle (JNIEnv* env, jobject clazz) { + LibreOfficeKit* aOffice; + (void) env; (void) clazz; - return (jlong) (intptr_t) libreofficekit_hook(full_program_dir); + aOffice = libreofficekit_hook(full_program_dir); + + return (*env)->NewDirectByteBuffer(env, (void*) aOffice, sizeof(LibreOfficeKit)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |