internal/mobileinit,bind/java,app: don't treat jobject as a pointer
On Android, the JNI jobject type doesn't always contain a pointer.
Treating a non-pointer as a pointer can crash the runtime. Use
the more appropriate type uintptr instead.
Change-Id: I2b2049918d60226c4d23d6df0b10e68248d54bc2
Reviewed-on: https://go-review.googlesource.com/110256
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/app/android.go b/app/android.go
index dff66c9..883a93c 100644
--- a/app/android.go
+++ b/app/android.go
@@ -68,7 +68,7 @@
//export setCurrentContext
func setCurrentContext(vm *C.JavaVM, ctx C.jobject) {
- mobileinit.SetCurrentContext(unsafe.Pointer(vm), unsafe.Pointer(ctx))
+ mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx))
}
//export callMain
diff --git a/bind/java/context_android.go b/bind/java/context_android.go
index cf41109..dc44431 100644
--- a/bind/java/context_android.go
+++ b/bind/java/context_android.go
@@ -17,5 +17,5 @@
//export setContext
func setContext(vm *C.JavaVM, ctx C.jobject) {
- mobileinit.SetCurrentContext(unsafe.Pointer(vm), unsafe.Pointer(ctx))
+ mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx))
}
diff --git a/internal/mobileinit/ctx_android.go b/internal/mobileinit/ctx_android.go
index 559f918..e0dc166 100644
--- a/internal/mobileinit/ctx_android.go
+++ b/internal/mobileinit/ctx_android.go
@@ -78,7 +78,7 @@
// SetCurrentContext populates the global Context object with the specified
// current JavaVM instance (vm) and android.context.Context object (ctx).
// The android.context.Context object must be a global reference.
-func SetCurrentContext(vm, ctx unsafe.Pointer) {
+func SetCurrentContext(vm unsafe.Pointer, ctx uintptr) {
C.current_vm = (*C.JavaVM)(vm)
C.current_ctx = (C.jobject)(ctx)
}