xlab/android-go

Pointer type uint32 is too small for 64bit compilation (*_Ctype_ulong)

tomas-mraz opened this issue · 1 comments

Hi, I made new build scripts for the android vulkandraw app in the forked repo https://github.com/tomas-mraz/vulkan-go_demos.
And it works in minimum configuration for 32bit arm architecture.
But for arm64 (aarch64) arch during compilation "so" library occurs error:

app.c:44:44: warning: incompatible function pointer types assigning to 'void (*)(ANativeActivity *, int)' (aka 'void (*)(struct ANativeActivity *, int)') from 'void (ANativeActivity *, GoInt)' (aka 'void (struct ANativeActivity *, long long)') [-Wincompatible-function-pointer-types]
# github.com/xlab/android-go/app
C:\Go\pkg\mod\github.com\xlab\android-go@v0.0.0-20180723170811-ebf4d6dd1830\app\events.go:116:38: cannot convert outSize (variable of type *_Ctype_ulong) to type *uint32
make: *** [Makefile:14: build64] Error 2

I understand the pointer to memory must be in a 64bit world much bigger. OK.

I changed in events.go lines

104 type SaveStateFunc func(activity *android.NativeActivity, size *uint64) unsafe.Pointer
116	result := fn(activityRef, (*uint64)(outSize))
126 func onWindowFocusChanged(activity *C.ANativeActivity, hasFocus int64) {

but the compilation is still not satisfied... and incompatible with 'void (*)(ANativeActivity *, int)' ... where does it come from?
Can someone point me in the right direction, please? Thanks.

Hi. I think I got it.

104: type SaveStateFunc func(activity *android.NativeActivity, size uintptr) unsafe.Pointer
116: result := fn(activityRef, uintptr(unsafe.Pointer(outSize)))

With help https://groups.google.com/g/golang-nuts/c/IreLjw1b0L0
"The problem is int is 32bit on 32bit platforms and will soon be 64bit on 64bit platforms.
uintptr also adjusts it's size based on target arch, which probably the reason size_t was created as well."

PR is on the way.