2
0
mirror of synced 2025-02-23 06:48:15 +00:00

267 Commits

Author SHA1 Message Date
Elias Naur
060f2570e9 mobile/bind: add integration test for CL 19417
Change-Id: I6a2cab4ca9b5bd61db51d08966da19fdfb07c344
Reviewed-on: https://go-review.googlesource.com/19463
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-12 15:13:48 +00:00
Elias Naur
d1c2f486a3 mobile/bind: handle null references from Java in Go
The Seq Java class has a special case for null references. Expand
the special case to Go so that null references from Java are properly
translated to nil.

Fixes golang/go#14228

Change-Id: I915d1f843c9db299d6910480f6d10dae0121a3b4
Reviewed-on: https://go-review.googlesource.com/19460
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-12 14:54:21 +00:00
Elias Naur
46f9e01d1e mobile/bind: ensure that Java->Go->Java calls stay on same thread
Java methods from Go are run on a thread pool managed on the Java side,
to avoid the complexities of getting Go threads to play along with the
Android JVM. However, for call stacks that contain a Java->Go->Java
chain, this behaviour confuses Java code sensitive to specific threads
if the Go->Java call is executed on an arbitrary thread from the pool.
For example, most Android UI changes must happen on the single UI
thread.

Replace the thread pool with direct calls to mimic ObjC<->Go and
Java->Go calls. Threads not already attached to the JVM are attached.
Introduce a thread local variable to detach such threads at thread exit.

Change-Id: I8cb65803c9278666ae77a0c7a65dc2d9c7e739e1
Reviewed-on: https://go-review.googlesource.com/19334
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-11 21:58:20 +00:00
Elias Naur
7538792349 mobile/bind: translate implicit Go interface implementations to Java
To implement an interface in Java the interface type must be listed
in the class declaration. Emulate the implicit Go interface
implementations in Java by listing all possible (non-empty) interfaces.

For example, given

type (
    S struct{}
    I  interface {
        M()
    }
)

func (s *S) M() {
}

in Go, the Java class S will be declared to implement the Java
interface I.

Fixes a TODO.

Change-Id: I5b0d2dd65938004ab29029f481cace4b8fb4b26f
Reviewed-on: https://go-review.googlesource.com/19417
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-02-11 21:46:02 +00:00
Elias Naur
89fdf89e93 bind: make Seq.RefTracker.createRef obey the refcnt invariant
An inspection of the RefTracker inc and dec methods suggests
that a particular Java Stub instance is included in the javaObjs
map if and only if its reference count, refcnt, is larger than zero.

A newly created reference created by RefTracker.createRef has zero
refcnt but was also inserted in the javaObjs map, violating the invariant.

Fix that by not inserting new references in javaObjs. Without the fix
a Stub instance that were never passed to Go would leak, along with
any other instances it referenced, transitively.

This fixes a Java reference tracking problem, I have not verified if
the same problem applies to the Go and ObjC sides of the Seq machinery.

Change-Id: I3ede90d5258630bc837fe61bba850df222d09a26
Reviewed-on: https://go-review.googlesource.com/19261
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-02-05 12:55:00 +00:00
Hyang-Ah Hana Kim
8b3b2fb1ae cmd/gomobile: move go.LoadJNI class to LoadJNI.java
This allows reuse of the code in custom gomobile bind tools.

Change-Id: I4e013ca871d0fa64983e7efb5e1e9dad8ac723c0
Reviewed-on: https://go-review.googlesource.com/18581
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-01 21:25:56 +00:00
Hyang-Ah (Hana) Kim
77ab3b76c2 bind/java: use size_t to match Send/Recv param types
Fixes the bug in 64bit platforms.

Change-Id: I499995d69db03d136dcb2ca7f930ba1e309c8b6d
Reviewed-on: https://go-review.googlesource.com/19070
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-29 01:39:28 +00:00
Hyang-Ah Hana Kim
24a199a648 bind: update testdata to reflect changes from cl/17866
Change-Id: Icdc68c536b8bc9c5e3874731e33b5f90e123a052
Reviewed-on: https://go-review.googlesource.com/18618
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-13 21:19:59 +00:00
Hyang-Ah Hana Kim
0951da6cb2 bind/java, internal/mobileinit: add dummy import "C"
not harmful, but this consistency may simplify cgo handling
in some custom build systems

Change-Id: Id4692986725b3737c23cdeb9ce1a1fa2bc9f7dad
Reviewed-on: https://go-review.googlesource.com/18615
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-01-13 19:14:56 +00:00
David Crawshaw
ab6091a309 bind: do not generate unused Seq objects
Updates golang/go#12619

Change-Id: Ie851795580c82ade3ee70bdb3945b23ca72f57e0
Reviewed-on: https://go-review.googlesource.com/17866
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-01-11 18:08:22 +00:00
David Crawshaw
e154aff74e bind/java: custom int-keyed hashmap
This removes the last dependency on an Android class in the running
gobind code. (Tests still need some work before they will run on the
desktop.)

Change-Id: I49bfb545d4587c6f430c0938fa1ca4d513b56d77
Reviewed-on: https://go-review.googlesource.com/17252
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-12-02 14:48:43 +00:00
David Crawshaw
2454c829c1 bind/java: move android-specific context code
Change-Id: I7b1dfae97576c7bb2d45e6c2a5732e20df79a77b
Reviewed-on: https://go-review.googlesource.com/17251
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-12-02 14:44:46 +00:00
Hyang-Ah Hana Kim
0a581ceb1e bind/java: do not return null String for empty Go string
Fixes golang/go#13430

Change-Id: Ic018761af6a40f6b04ec4449110f54af8f543a53
Reviewed-on: https://go-review.googlesource.com/17273
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-12-01 20:12:01 +00:00
Meir Fischer
9cdfd16af3 bind: use single Ref for null objects
The aim of the RefTracker is to "... pin Java objects so
they don't get GCed while the only reference to them is
held by Go code." But in the case of null objects there is
nothing to GC. Therefore we do return a single Ref which
contains a null object, but we ignore the logic that is used
to pin for GC purposes.

Change-Id: If3771ec0180d09485963c3297abccb39a1a8d9ab
Reviewed-on: https://go-review.googlesource.com/13647
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-30 20:03:33 +00:00
David Crawshaw
7b89485f3d bind/java: use standard Java Logger
Change-Id: I47c9ba45d3c366821856c1a28bb945ed11b6e18a
Reviewed-on: https://go-review.googlesource.com/17234
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-11-30 17:41:42 +00:00
David Crawshaw
e2a9091da2 bind: remove extra "package" from error string
Fixes golang/go#13064

Change-Id: I2cde12a831607cd37d9760d92c0ef0f53fd6dd8b
Reviewed-on: https://go-review.googlesource.com/16351
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-11-13 12:13:51 +00:00
Daniel Skinner
3b97f7024e cmd/gomobile: synthesize minSdkVersion for manifest
Fixes golang/go#13172

Change-Id: I16cab3f74f668ce3522a1a14c979aca5c988347c
Reviewed-on: https://go-review.googlesource.com/16843
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-13 09:00:34 +00:00
Hyang-Ah Hana Kim
a54776c08a bind, internal/loader: fix errors reported by vet
Change-Id: Ia1c2e13cd093fec1c4d6c38828b057d1a38274e4
Reviewed-on: https://go-review.googlesource.com/16841
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-11-11 22:33:35 +00:00
Hyang-Ah (Hana) Kim
4eceb7296e bind: error on named basic types
error message example:

 gomobile: unsupported named type github.com/sridharv/bugreports/typealiasmissing.Alias

Objective-C and Java generation code currently panics, which need to be
fixed separately. (See TODO in bind/seq.go)

Fixes golang/go#13190

Change-Id: Ie46dc58ea800522b8ab7cb8ac662ad561e0ca82e
Reviewed-on: https://go-review.googlesource.com/16780
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-11-11 22:33:09 +00:00
Hyang-Ah Hana Kim
9c6db08f1d bind/objc/testpkg: delete accidentally committed files.
Change-Id: I9a2a83ef64cb9ee877db952ff6f8e050cd52873d
Reviewed-on: https://go-review.googlesource.com/16840
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-11-11 22:32:48 +00:00
Hyang-Ah (Hana) Kim
9868458844 bind/objc: correct handling of empty string return value.
Fixes golang/go#13087

Change-Id: I9d7319d9ed3eee73e6479510911f796ab0607bd2
Reviewed-on: https://go-review.googlesource.com/16452
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-28 19:30:01 +00:00
Hyang-Ah (Hana) Kim
8a59fd3f45 bind: correctly lowercasing all caps names
Fixes golang/go#13031

Change-Id: I6cae8e303d0d929e26c44cbdf1c243e98dabb766
Reviewed-on: https://go-review.googlesource.com/16270
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-23 16:10:33 +00:00
Hyang-Ah (Hana) Kim
bf2ca7a93b x/mobile/bind: forward declare protocol/class for interface types
Fixes golang/go#13004

Change-Id: I114cf3d7d970485d0609b1d7b497e232010e64df
Reviewed-on: https://go-review.googlesource.com/16155
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-22 17:03:04 +00:00
Burcu Dogan
319b6ff544 bind: use the prefix in the include guards
Fixes golang/go#12984.

Change-Id: I485e6071ff136eb3f475d03ebebf8d306f24c931
Reviewed-on: https://go-review.googlesource.com/16027
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-19 16:13:27 +00:00
Hyang-Ah (Hana) Kim
51389df416 bind/objc: use lowercase for method names.
Fixes golang/go#12889.

Change-Id: I4b8f5e4b2c4fe53146fc351889664cbeb5a1860b
Reviewed-on: https://go-review.googlesource.com/15780
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-13 18:34:52 +00:00
Hyang-Ah (Hana) Kim
090457ac45 bind/objc: change exported var accessors to class methods.
for example,

package testpkg
var AnInt int64

will be mapped to

@interface GoTestpkg: NSObject
+ (int64_t) AnInt;
+ (void) setAnInt:(int64_t)v;
@end

Followup of cl/15340

Update golang/go#12475

Change-Id: Ie26c92af977fc3dd62dcad2b10c6a5c1c1b8941b
Reviewed-on: https://go-review.googlesource.com/15770
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-13 18:34:32 +00:00
Hyang-Ah (Hana) Kim
bb506cefe4 bind: error for packages with no exported names.
For error message improvement mentioned in golang/go#12842

Change-Id: I066ae9dc9415b34bf93128098199bbb935b7dedc
Reviewed-on: https://go-review.googlesource.com/15410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-07 20:50:02 +00:00
Hyang-Ah (Hana) Kim
45ed283c80 bind: support exported variables
basic types, struct*, interface.

TODO: error, non-pointer struct, pointer basic types, slice of bytes.

Update golang/go#12475.

Change-Id: I5ff91059b1f963b0cadb6f76cb0e12f7b6b98718
Reviewed-on: https://go-review.googlesource.com/15340
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-10-07 20:48:45 +00:00
Hyang-Ah (Hana) Kim
60728759f9 bind: add const type support
Update golang/go#12475

Change-Id: I7fdc22462b5925c84ebbeb54517032c2fbd0545b
Reviewed-on: https://go-review.googlesource.com/15120
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-30 20:56:48 +00:00
David Crawshaw
7a70f37cf6 bind/objc: remove a constructor and retain blocks
A framework generated with gomobile bind -target=ios has two global
constructors: one initializing a data structure and another using it.
These constructors are defined in different translation units, which
(I believe, reasoning from C++ global constructors) means their order
of initialization is undefined.

A capturing block is stack allocated. Its memory is invalid after the
function returns. Make a copy of the interface initializer blocks so
they can be saved to the heap.

Block implementation background:
http://www.cocoawithlove.com/2009/10/how-blocks-are-implemented-and.html

Updates golang/go#12590

Change-Id: Ia7ae9f4bbd8df6e6e79949de54b3e6c48148c700
Reviewed-on: https://go-review.googlesource.com/14549
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-15 17:38:26 +00:00
Meir Fischer
00865a642f bind: improve readability for float default values
To improve readability for default numeric types
represented as strings, use 0.0 for floating point types.
(No tests make use of this change so golden update
not necessary; not significant enough for new test/test mod.)
Fix spelling on error statement; this was the only
instance of that spelling error in the repository.

Change-Id: I373890725b33da11c6780ba93674d89541bf758c
Reviewed-on: https://go-review.googlesource.com/13645
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-01 18:16:37 +00:00
Hyang-Ah (Hana) Kim
671f57b233 bind: fix interface methods' multiple return values handling.
Fixes golang/go#12403

Change-Id: I9b8e6d69beb1ceb27e991348212acb5054497e47
Reviewed-on: https://go-review.googlesource.com/14077
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-31 16:32:47 +00:00
Hyang-Ah (Hana) Kim
c384607ef3 bind: support for custom java package name and objective-c prefix.
Introduce options -javapkg and -prefix for gobind command.

The following generates java class Testpkg with package name com.example.

gobind -lang=java -javapkg=com.example testpkg

The following generates objective-c files where function and type names
are prefixed with ExampleTestpkg.

gobind -lang=objc -prefix=Example testpkg

As discussed in golang/go#9660 and golang/go#12245.

Gomobile support is not yet implemented.

Change-Id: Ib9e39997ce915580a5a2e25643c0c28373f27ee1
Reviewed-on: https://go-review.googlesource.com/13969
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-28 13:57:06 +00:00
David Crawshaw
4628c38e0f bind: handle unimplementable interfaces
Fixes golang/go#12330

Change-Id: I1568d04b7e48242105a7028ca471e2138f684eeb
Reviewed-on: https://go-review.googlesource.com/13946
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-27 21:36:14 +00:00
David Crawshaw
11fe695b54 bind: support fields with type error
Fixes golang/go#12328

Change-Id: I42872d26acb1c44522a64405cfa2d0f10fb24485
Reviewed-on: https://go-review.googlesource.com/13919
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-26 20:25:55 +00:00
Hyang-Ah (Hana) Kim
da28dd9045 bind/objc: fix error return type handling
Fixes golang/go#12307.

Change-Id: I5560b616a3cd51c536d9e5529745681effe26e9a
Reviewed-on: https://go-review.googlesource.com/13913
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-25 15:22:55 +00:00
Hana Kim
49a82fefe3 all: support go get golang.org/x/mobile/... on Windows
Fixes golang/go#12212
Workaround for golang/go#12261 until golang/go#9306 is fixed.

Change-Id: I51c1bcfc92c1553fe2132586a0234b1c1af6aeb1
Reviewed-on: https://go-review.googlesource.com/13745
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-24 21:09:04 +00:00
David Crawshaw
48bd7cbbc7 bind: adjust invalid java package names
Updates golang/go#12273

Change-Id: I8eac3e84d5a473e9ffe45705cea88537573aef61
Reviewed-on: https://go-review.googlesource.com/13873
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-24 21:08:09 +00:00
David Crawshaw
da78c710f3 bind/testdata: update golden files
Tests now pass on OS X.

Change-Id: Id2e6c5bd9ddd4070962ff9bc121d7902e8c9a647
Reviewed-on: https://go-review.googlesource.com/13694
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-08-18 17:57:47 +00:00
Hyang-Ah (Hana) Kim
5c55c26446 bind/objc: don't expose internal class types mapped to Go interface.
For interface binding, we need only protocols.

Change-Id: I377ec9c8de0a3414d48272892b169fb94823e8ff
Reviewed-on: https://go-review.googlesource.com/13541
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-11 19:16:10 +00:00
Hyang-Ah (Hana) Kim
50f2c0f60e bind/objc: update test.bash to run gobind.
Change-Id: I38379d6f1a6bbaa13234060b52edc8206b750644
Reviewed-on: https://go-review.googlesource.com/13028
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-08-05 20:02:56 +00:00
Hyang-Ah (Hana) Kim
9865dd0755 bind: implement objective-C interface binding code generation.
Depends on cl/12389 progress.

Change-Id: I044b0cf7c4df1d84b9ee158a4ceb3fdb13bf7645
Reviewed-on: https://go-review.googlesource.com/12410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-31 20:12:37 +00:00
Hyang-Ah (Hana) Kim
926122382b bind/objc: Interface binding support
Given a Go package defining an interface,

  package testpkg
  type I interface {
      Fn()
  }

I is mapped to an objective-c protocol and a proxy interface
that implements the routing of method calls from Go.

  @protocol GoTestpkgI
  -(void)Fn;
  @end

Users implement a class conforming the generated protocol. For example,

  @interface MyI <GoTestpkgI> {
  }
  @end

  @implementation MyI {
  }
  - (void)Fn { .... }
  @end

Gobind will also create a proxy interface to handle Go objects
implementing the interface and passed to Objective-C, but that will
be hidden from users.

  @interface GoTestpkgI : NSObject <GoTestpkgI> {
  ...
  -(void)Fn;
  @end

The gobind code to generate the objective-c binding is in a separate CL.

Change-Id: I6a72d34fe3a5b8d2774d2d53913229c1e71f2d60
Reviewed-on: https://go-review.googlesource.com/12389
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2015-07-31 20:12:03 +00:00
David Crawshaw
b780379135 bind: vendor x/tools/go/loader
This breaks our dependency on the x/tools repository, which has a
tendency to change in unexpected ways. It also means we can use the
version of go/types that ships with Go 1.5.

Along the way, it appears that cgo processing has changed slightly.
The old check for cgo files apparently wasn't working, so I removed
it.

Change-Id: I14378e9df9cd65c5ab61b47728ba0d56f31cdf76
Reviewed-on: https://go-review.googlesource.com/12680
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-28 18:02:47 +00:00
Hyang-Ah (Hana) Kim
c261c465a9 bind: seq.Transact requires interface descriptor.
seq.Transact is called when Go calls a method of a foreign object
that implements a Go interface. Currently, we assume that the foreign
object has an instance method that can conduct the message routing,
so the object id and the method code is sufficient for transact.

Passing the interface descriptor (e.g.  go.testpkg.I) however allows
the bind internal to use non-instance methods to implement the routing.

Change-Id: I1f61a04f919fbd09117ea332d678cd50e4861e46
Reviewed-on: https://go-review.googlesource.com/12685
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-27 18:08:41 +00:00
Hyang-Ah (Hana) Kim
4755f4ad8f bind/objc: fixes miscalculation of string length.
Also, fixes the memory allocation bug - misuse of mem_ensure that caused
to allocate 72 bytes of memory to carry 16 bytes of data for instance.

Fixes golang/go#11842.

Change-Id: I21798be2ec7adfb68cc2897bb46a924f05f3478c
Reviewed-on: https://go-review.googlesource.com/12577
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-23 22:35:14 +00:00
Hyang-Ah (Hana) Kim
c039090cf1 bind/java: fix misuse of mem_ensure.
mem_ensure is to ensure the remaining space in buffer
is large enough to hold extra size bytes. We've been passing
the target capacity instead of the number of extra bytes we
need.

Change-Id: Ic6f6ddb4ad22cbcdbc44eb4a58e6a415ae771fb2
Reviewed-on: https://go-review.googlesource.com/12578
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-23 22:34:55 +00:00
Hyang-Ah (Hana) Kim
103c0611a8 bind/java: suppress compiler warning
non-varargs call of varargs method with inexact argument type for last
parameter

Change-Id: I7623951c365b8cf899a17ee784c8d4f3b4bdb198
Reviewed-on: https://go-review.googlesource.com/12528
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-22 21:01:20 +00:00
Hyang-Ah (Hana) Kim
136fa9bbbb bind/java: reenable asset access.
This is done by moving app.Context to internal/mobileinit,
introducing mobileinit.SetCurrentContext and,
making bind/java depend on it.

TODO: check gomobile bind's proguard rule - context lookup
was implemented through reflection on android.app.AppGlobals class.

Change-Id: Ieb6ad503eeef8c2c1c5836a21c667938c5a701a2
Reviewed-on: https://go-review.googlesource.com/12279
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 21:15:37 +00:00
Hyang-Ah (Hana) Kim
6fb2670129 bind/objc: Remove reference of seq.h from generated header file.
This allows gomobile bind to stop copying seq.h to the destination.

Change-Id: I4a23613fe0407500ad483ae9d8f6bb823d82f082
Reviewed-on: https://go-review.googlesource.com/12300
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 14:02:16 +00:00