cmd/cgo: update JNI's jobject to uintptr check for newer Android NDKs

In Android's NDK16, jobject is now declared as:
    #ifdef __cplusplus
    class _jobject {};
    typedef _jobject*       jobject;
    #else /* not __cplusplus */
    typedef void*           jobject;
    #endif

This makes the jobject to uintptr check fail because it expects the
following definition:
    struct _jobject;
    typedef struct _jobject *jobject;

Update the type check to handle that new type definition in both C and
C++ modes.

Fixes #26213

Change-Id: Ic36d4a5176526998d2d5e4e404f8943961141f7a
GitHub-Last-Rev: 42037c3c58
GitHub-Pull-Request: golang/go#26221
Reviewed-on: https://go-review.googlesource.com/122217
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Steeve Morin 2018-07-17 15:55:01 +00:00 committed by Ian Lance Taylor
parent bccbf59046
commit 5419e7a09d
6 changed files with 121 additions and 7 deletions

View file

@ -2772,13 +2772,31 @@ func (c *typeConv) badJNI(dt *dwarf.TypedefType) bool {
}
}
// Check that the typedef is:
// struct _jobject;
// typedef struct _jobject *jobject;
// Check that the typedef is either:
// 1:
// struct _jobject;
// typedef struct _jobject *jobject;
// 2: (in NDK16 in C++)
// class _jobject {};
// typedef _jobject* jobject;
// 3: (in NDK16 in C)
// typedef void* jobject;
if ptr, ok := w.Type.(*dwarf.PtrType); ok {
if str, ok := ptr.Type.(*dwarf.StructType); ok {
if str.StructName == "_jobject" && str.Kind == "struct" && len(str.Field) == 0 && str.Incomplete {
return true
switch v := ptr.Type.(type) {
case *dwarf.VoidType:
return true
case *dwarf.StructType:
if v.StructName == "_jobject" && len(v.Field) == 0 {
switch v.Kind {
case "struct":
if v.Incomplete {
return true
}
case "class":
if !v.Incomplete {
return true
}
}
}
}
}