Граф коммитов

69 Коммитов

Автор SHA1 Сообщение Дата
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
David Crawshaw e5193c59b3 cmd/gomobile: reorganize build logic
The goal here is to remove several inconsistencies between
-target=android and -target=ios support, along with making the flow
of the command follow the path you might expect given a certain set
of flags, and preparing for `gomobile bind` support of ios. In
particular, building non-main packages now works with both targets
and the initialization of global build state is clearer.

The reorg also is designed around an nm trick I thought of
yesterday to do better package import scanning without a slow
all-file scan. This will give better detection of x/mobile/app and
x/mobile/exp/audio/al packages. There's a TODO about it, and I'll do
it in a future CL.

Tested with:

	go test golang.org/x/mobile/cmd/gomobile
	gomobile init
	gomobile bind golang.org/x/mobile/asset
	go test golang.org/x/mobile/bind/java
	gomobile build -target=ios golang.org/x/mobile/example/basic
	gomobile build -target=ios golang.org/x/mobile/gl
	gomobile build -target=android golang.org/x/mobile/gl
	gomobile build -target=android golang.org/x/mobile/example/basic
	(Along with manual testing of basic on an android device.)

That might make a pretty good _test.go.

Change-Id: I41230008c3c15db25a11c33b9eaca4abada9f411
Reviewed-on: https://go-review.googlesource.com/12051
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-13 18:54:16 +00:00
Elias Naur 5aee943213 x/mobile/bind: remove debug print
Android support has advanced to the point where this logging statement
adds very little information.

Change-Id: I3c8c9d60be8c0b52a519f9e44711bd211b5bfe67
Reviewed-on: https://go-review.googlesource.com/11990
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-10 17:08:45 +00:00
David Crawshaw 960fedd178 internal/mobileinit: new package for shared logic
Package app contains some logic that we want to share with
gobind-based libraries. So move it to a new internal package
that both can import.

Long term the log changes should be in the standard library,
but the Go tree is currently frozen.

Fixes golang/go#11630.

Change-Id: I9ff622fc499bf255bce18df23cb68b03f667947f
Reviewed-on: https://go-review.googlesource.com/11981
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-08 21:29:11 +00:00
Hyang-Ah (Hana) Kim a922dd97b1 bind/objc: remove '_' after Go<pkgname> prefix from names.
Before this change, func Hello() of mypkg package generated a function
GoMypkg_Hello to distinguish the prefix from the function name.
It seems the use of '_' is very rare in Objective-C though.
After this change, it generates GoMypkgHello.

Change-Id: Ic7aa2b667363a447a5ff3500262502d3137d6853
Reviewed-on: https://go-review.googlesource.com/11893
Reviewed-by: Damien Neil <dneil@google.com>
2015-07-07 03:29:17 +00:00
David Crawshaw 5ced61ace7 cmd/gomobile: call System.loadLibrary for .aar
Change-Id: I3fd099910cfb1fe112ded4386905d370acfea002
Reviewed-on: https://go-review.googlesource.com/11816
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-07-06 22:21:32 +00:00
Alan Donovan 616f82b347 bind: fix build broken by API change to golang.org/x/tools/go/types
Fixes golang/go#11509.

Change-Id: Ia54febfa3ef9b589befb09b8f5d79cb6d7f6c4da
Reviewed-on: https://go-review.googlesource.com/11841
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-07-02 12:24:20 +00:00
David Crawshaw 8144405762 app, bind: separate the app package from gobind
Historically, the app package implemented Go runtime initialization.
This was convoluted, so the package was used both by all-Go apps
(currently based on Android's NativeActivity) and bind-based apps.

With Go 1.5 we have -buildmode=c-shared, which does a lot of the work
of the old app package. That code was removed a while back, but both
all-Go and gobind-based apps still used package app. The intermingled
initialization processes led to some strange states.

This CL separates gobind-based apps completely from the app package.
As part of that users are now expected to use System.loadLibrary
themselves. (A future CL may want to make the loadLibrary call part
of the .aar generated by gomobile bind.)

Delete the libhello example, which has been replaced by gomobile bind,
which could do with its own example at some point. Also delete the
libhellojni example, which now has nothing to do with the x/mobile
repository.

Change-Id: I444397f246dbafe81e5c53532eb482c197d26f70
Reviewed-on: https://go-review.googlesource.com/11654
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-29 11:40:40 +00:00
James Schofield 5878957524 mobile/bind: Fix objc bindings for multiple return vals.
The existing implementation generates uncompilable objc code for
functions returning two results.

Change-Id: I13f7329596d8fa6103c4b7827c26c5461e16a925
Reviewed-on: https://go-review.googlesource.com/11364
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-24 18:25:43 +00:00
Hyang-Ah (Hana) Kim 3a9b5b50ac bind: correct methods' return arg type mapping in obj-c binding.
Change-Id: Ieda05982c7f894c5603103b8890658e682e97423
Reviewed-on: https://go-review.googlesource.com/11307
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-23 13:13:31 +00:00
Hyang-Ah (Hana) Kim d7fb1ce757 bind: fix a bug in handling func returning a struct.
Change-Id: I63963c20c283638cfdc86b037f6aff70a115a78c
Reviewed-on: https://go-review.googlesource.com/10893
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-11 17:32:32 +00:00
Hyang-Ah (Hana) Kim 9c7482eec9 bind/objc: use gobind -lang=objc,go to generate code.
Removed checked-in version of go, objective-c proxy code.

Change-Id: Iac2c6ba3156def680746b5ae1fe02d6e712532a7
Reviewed-on: https://go-review.googlesource.com/10842
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-10 00:17:26 +00:00
Hyang-Ah (Hana) Kim 8f4eb9eb49 bind: add objective-c code generator.
Translate error type to NSError.
Interface type is not supported yet.

Change-Id: I54abba2360cff41ef8ca08063b0120e7edd65a47
Reviewed-on: https://go-review.googlesource.com/10793
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2015-06-09 20:58:21 +00:00
Hyang-Ah (Hana) Kim 343eae7dd2 bind/objc: simplify reference counting of Go objects.
With https://go-review.googlesource.com/10638, the reference counting
of Go objects can be simplified. Everytime a Go object is passed into
Objective-C side, a new proxy object with GoSeqRef is created.
Deallocation of a GoSeqRef decrements the reference counter of the
corresponding Go object.

Test the Go object is collected.

Note: It's possible to reduce the number of GoSeqRef
allocations by maintaining a map of weak references to the existing
GoSeqRef, but for now, we allocate a new GoSeqRef instance.

Change-Id: I57a5a4b249c5800d9eba95d128a2cdf74bbef566
Reviewed-on: https://go-review.googlesource.com/10639
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2015-06-04 23:02:01 +00:00
Hyang-Ah (Hana) Kim b24fa8f869 bind/objc: add read/write Int and BOOL values.
Change-Id: I9e1d0c62acfa43cfc1b0dd79ff25b89b43a891cb
Reviewed-on: https://go-review.googlesource.com/10710
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-04 20:31:20 +00:00
David Crawshaw f373bd373c bind: rename parameter p
Fixes golang/go#11064.

Change-Id: Idb4376f0143b0d1c8e87e7ccc54aae343b504e4a
Reviewed-on: https://go-review.googlesource.com/10689
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-06-04 17:29:43 +00:00
Hyang-Ah (Hana) Kim c533dca65f bind/java: manage Java object lifetime based on reference count.
The gobind framework is supposed to use reference counting to
keep track of objects (e.g. pointer to a Go struct, interface
values) crossing the language boundary. This change fixes two bugs:

1) no reference counting on Java object: Previously, the lifetime
of a Java object was manages in the following way.

 a. The Java object is pinned in an internal map (javaObjs) when it's
constructed.
 b. When Go receives the reference to the Java object, it creates a
proxy object and sets a finalizer on it. The finalizer signals Java
to unpin the Java object (remove from the javaObjs map).
 c. The javaObjs map is also used to identify the Java object when
Go asks to invoke a method on it later.

When the same Java object is sent to Java more than once, and the
finalizer (b) runs after the first use, the second use of the Java
object can cause the crash described in golang/go#10933.

This change fixes the bug by reference counting the Java object.
Java side pins the Java object and increments the refcount whenever it
sees the object sent to Go (in Seq.writeRef). When the Go proxy
object's finalizer runs, the refcount is decremented. When the refcount
becomes 0, the object gets unpined.

2) race in Go object lifetime management: Pinning on a Go object
has been done when the Go object is sent to Java but the Go object
is not in the pinned object map yet. (bind/seq.WriteGoRef).
Unpinning the object occurs when Java finds there are no proxy objects
on its side. For this, Java maintains a reference count map (goObjs).
When the refcount becomes zero, Java notifies Go so the object is
unpinned. Here is a race case:

 a. Java has a proxy object for a Go object.
 b. Go is preparing for sending the same Go object. seq.WriteGoRef
notices the corresponding entry in the pinned object map already,
and returns. The remaining work for sending the object continues.
 c. The proxy object in Java finalizes and triggers deletion of the
object from the pinned object map.
 d. The remaining work for (b) completes and Java creates a new proxy
object. When a method is called for the Go object, the Go object is
already removed from the object map on Go side and maybe already GC'd.

This change fixes it by converting the pinned object map to reference
counter map maintained in Go. The counter increments for each
seq.WriteGoRef call. The finalizer of the proxy object in Java causes
a decrement of the counter.

Fixes golang/go#10933.

Renables the skipped testJavaRefGC.

Change-Id: I0992e002b1050b6183689e5ab821e058adbb420f
Reviewed-on: https://go-review.googlesource.com/10638
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-04 16:53:15 +00:00
Hyang-Ah (Hana) Kim d8725953a1 bind: remove an unused field from javaGen.
Change-Id: If1eab27d334c38288fb0c7cec3e4bf2143ddaf91
Reviewed-on: https://go-review.googlesource.com/10637
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-03 14:31:32 +00:00
Hyang-Ah (Hana) Kim a7e5f659df bind/objc: allow passing Go objects to objective-C.
Change-Id: I2aa3971cd8800485f2934d5efb89cea8042e7d88
Reviewed-on: https://go-review.googlesource.com/10632
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-06-02 16:03:04 +00:00
Hyang-Ah (Hana) Kim cc98479faf bind: make generated names less go-like to avoid name collision.
Change-Id: Ib3f27ceb38ae0d2416e8aef6f3ffe81c7f6c9044
Reviewed-on: https://go-review.googlesource.com/10550
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-29 19:58:06 +00:00
Elias Naur e241db99d5 bind/java: revert byte array class workaround from CL 9783
After CL 10296 the workaround from CL 9783 is no longer necessary.
Revert the workaround but keep the global reference, just in case.

Change-Id: I3fdd580e4122c36508beb9d328739b910dbbe2e2
Reviewed-on: https://go-review.googlesource.com/10483
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-29 10:36:48 +00:00
David Crawshaw 64c20ce93d bind/java: initialize seq machinery from Java
This ensures that the java bindings are ready before any calls are
made by user code. As a bonus, the JNIEnv* is from the Seq class so I
believe no tricks are required to find the right class loader.

Fixes golang/go#10903.

Change-Id: I33b3b39cef6cc2da36e271de882ba8d26610ea34
Reviewed-on: https://go-review.googlesource.com/10296
Reviewed-by: Elias Naur <elias.naur@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-28 18:37:54 +00:00
Hyang-Ah (Hana) Kim 6e800237e4 bind/objc: simplify GoSeq.
Change-Id: I86e5409d5e09794108cdf5ef1b4c80155d8874cf
Reviewed-on: https://go-review.googlesource.com/10049
Reviewed-by: Damien Neil <dneil@google.com>
2015-05-14 22:26:19 +00:00
Hyang-Ah (Hana) Kim 6d80e5a85f bind: support Bool types.
Also add missing int8/int16 handling in bind/seq.

Fixes golang/go#10855.

Change-Id: I326ada44df10fc3c22628bdd2ae4ee2c3dc7902e
Reviewed-on: https://go-review.googlesource.com/10046
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-14 22:17:57 +00:00
Hyang-Ah (Hana) Kim b658bfdf39 bind: support reference types as struct fields.
Reference types here mean pointers to struct types and
exported interface types. Previously, gobind generated invalid
go/java sources.

Change-Id: Icd666ebbb8edb70c613311798d602fd88cb4479c
Reviewed-on: https://go-review.googlesource.com/9997
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-14 19:48:46 +00:00
Hyang-Ah (Hana) Kim fd342d15ab bind/objc: implement byte array read/write support.
Change-Id: I01ff7369c653bc7d57a3357c8f936d30ca5c0beb
Reviewed-on: https://go-review.googlesource.com/9922
Reviewed-by: Damien Neil <dneil@google.com>
2015-05-13 22:32:52 +00:00
Hyang-Ah (Hana) Kim 5c3e18f08f bind/objc: obj-c binding for functions using numeric, string types.
test.bash is a simple script that builds the c-shared library from
test_main.go, compiles SeqTest.m and the objective-c bindings of testpkg
(testpkg/objc_testpkg/GoTestpkg.*), and runs the output. Eventually this
will be replaced with coed that runs gomobile bind & xcodebuild.

The code under testpkg/go_testpkg and testpkg/objc_testpkg is the output
of gobind (now manually-generated). I am adding it to repo now in order
to get the testpkg/objc_tstpkg reviewed. Eventually, this will be
removed from the repo.

Change-Id: I8d6af3732337992af922cb4615a63f385e19d489
Reviewed-on: https://go-review.googlesource.com/9826
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-13 22:28:22 +00:00
Hyang-Ah (Hana) Kim ec112d8787 bind: mention the supported binding rules.
Change-Id: I4760042871b2ccb7b24ee79ef9adef54cfb9303b
Reviewed-on: https://go-review.googlesource.com/9996
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-13 21:10:50 +00:00
Hyang-Ah (Hana) Kim 4f4272d70b bind: fix Java code generation that takes reference type params.
Also fixes a parameter name handling problem when processing a
function signature that omits parameter names.

Fixes golang/go#10788.

Change-Id: I65273d330bbf3a836ec9e4ffb691927970d795d8
Reviewed-on: https://go-review.googlesource.com/9926
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-12 22:05:40 +00:00
Hyang-Ah (Hana) Kim 910c3fc64e bind/java: find jbytearray class info using jbytearray object.
The previous way (JNIEnv's FindClass with "[B") does not work
in Android-L for some reason.

Change-Id: I5cccb7bbf651df981a923ecade863302521d5c5c
Reviewed-on: https://go-review.googlesource.com/9783
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-12 17:43:40 +00:00
David Crawshaw 5cddc1460e app: introduce Config and start registration
Config provides a way to concurrently access Width and Height.

Register provides a way for packages to run code on app state change
without plumbing changes all the way to the process main function.
This is motivated by gl/glutil.Image which needs to rebuild its
textures on start/stop and can be deeply nested.
(See golang.org/cl/9707 for the followup.)

Tested manually on android and darwin/amd64. Doing this kind makes it
clear any CL modifying this code needs a lot of manual testing right
now, so some kind of trybot support is something I'm going to
prioritise.

Fixes golang/go#10686
Fixes golang/go#10461
Fixes golang/go#10442
Fixes golang/go#10226
Updates golang/go#10327

Change-Id: I2882ebf3995b6ed857cda823e94fbb17c54b43a8
Reviewed-on: https://go-review.googlesource.com/9708
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-06 17:32:53 +00:00
Hyang-Ah (Hana) Kim 601608a0e0 bind/java: use the class loader cached during JNI_OnLoad call.
This allows the application class loader to be used when
the bind/java package or other part of JNI dynamically
loads java classes from a non-Java thread.

http://developer.android.com/training/articles/perf-jni.html#faq_FindClass

Fixes golang/go#10668.

Change-Id: I44df3a9362617fa6dd26ddf88247e4fdaee7c7e8
Reviewed-on: https://go-review.googlesource.com/9732
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-06 03:41:18 +00:00
David Crawshaw 66ea9e5b49 app: simplify and document init sequence
The global constructor added for -buildmode=c-shared takes care
of a lot of the messier steps that were being done here.

Change-Id: I00525765855b2ad0fcecb0639d6a7ee3feea9ed9
Reviewed-on: https://go-review.googlesource.com/9648
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-05-04 12:09:13 +00:00
Hyang-Ah (Hana) Kim 812950cfd1 bind/objc: GoSeq for obj-c and go communication.
duplicate code from bind/java/seq_android.c to use for obj-c/go binding.

Change-Id: Iefd5d4171cca3a30c5d56f9b37647463e6fd0c5a
Reviewed-on: https://go-review.googlesource.com/9409
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-05-01 19:28:10 +00:00
Hyang-Ah (Hana) Kim 30559f84c5 bind/java: add mising copyright statements.
Change-Id: Ifb120cba013d48fa83af41a43ccbbe7de87b26c8
Reviewed-on: https://go-review.googlesource.com/9408
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-28 18:08:06 +00:00
Hyang-Ah (Hana) Kim bdbc727b12 bind/java: convert test.bash to go test.
This change deletes unnecessary files - they are auto-generated by
the gomobile bind command.

Change-Id: I490664dfcf52683dd8d2ea821d0b7e458bc06671
Reviewed-on: https://go-review.googlesource.com/8925
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-15 12:57:12 +00:00
Hyang-Ah (Hana) Kim 0150454fb3 bind/seq: add Buffer.{Read,Write}UTF8.
Change-Id: I204dd9c9080c9c1e350210932397a500247aea28
Reviewed-on: https://go-review.googlesource.com/8896
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-14 18:50:33 +00:00
Hyang-Ah (Hana) Kim 334412418f bind: replace {Read,Write}UTF16 with {Read,Write}String for string.
This is to enable more flexible encoding/decoding of Go string.
For Java, we use UTF16 to be compatible with java string.
For other languages, we will want other way to represent a string.

Change-Id: Iccd53e2eea18d37636c3c619d06cb473facef0cd
Reviewed-on: https://go-review.googlesource.com/8628
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-09 12:44:56 +00:00
Hyang-Ah (Hana) Kim d886eeda27 bind/java: fix testpkg's gobind generate command.
Change-Id: I36494baac428ed9fdd777d2b03bf23a9cb2568b5
Reviewed-on: https://go-review.googlesource.com/8627
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-09 12:44:41 +00:00
Hyang-Ah (Hana) Kim 20544e603c bind/java/SeqTest: call Go.init from the test case constructor.
Go.init must be called once and from the main thread.
setUp is called from a non-main thread and once per each test.

Change-Id: I848a1461793463785b38141e077da5bf5e53cb4c
Reviewed-on: https://go-review.googlesource.com/6832
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-05 00:04:29 +00:00
Hyang-Ah (Hana) Kim d6d776925d bind/java: use gomobile to build bind lib.
Change-Id: I3390ff0e59bec6414aed7645fb7b67c33263d798
Reviewed-on: https://go-review.googlesource.com/6664
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-03-04 22:37:44 +00:00
David Crawshaw 47a1495872 bind/java: fix build
Tested on darwin/amd64 with
	go build golang.org/x/mobile/...

Change-Id: Iec31ccb318913cea5acc7dcec1c6a858bf8654de
Reviewed-on: https://go-review.googlesource.com/5770
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-24 17:48:51 +00:00
Hyang-Ah Hana Kim 8fc47a26f1 bind/java/SeqTest: use AndroidTestCase for Context.
To exercise the code path that uses Context given to Go.init.

Change-Id: Ied1f9efff325c711275a1969c373011c59e1d08d
Reviewed-on: https://go-review.googlesource.com/5750
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-24 16:20:09 +00:00
Hyang-Ah Hana Kim d267d4cb61 bind/seq: fix unaligned memory access in serialization.
Unaligned memory access caused SIGBUS when using ndk r10d.

Change-Id: Ic219873f1e2a30bf3a41cdf3c552d058e55db0cb
Reviewed-on: https://go-review.googlesource.com/5500
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-02-23 21:01:14 +00:00
David Crawshaw b2dee7a880 app, cmd/gomobile: expose an app.State variable
The State can be used in the Start callback (and lazily-initialized
packages) instead of JavaInit. This stores a reference to the
android.context.Context for the (future) keyboard package and for
setting TMPDIR.

Second attempt at https://golang.org/cl/4400.

Change-Id: I673997b26ab25ce5140cb31950593d8c6dbd9c51
Reviewed-on: https://go-review.googlesource.com/5555
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-02-23 17:54:17 +00:00
Hyang-Ah (Hana) Kim 71e2276663 bind/java: pin java byte array elements until Seq send is done.
When passing a byte array from Java to Go, Seq.writeByteArray JNI
call encodes only the array size and the pointer to the array.
Go-side receives the (size, ptr) pair info during the subsequent
Seq.send JNI call, and copies the elements into a Go byte slice.
We must pin the array elements until Go-side completes copying
so that they are not moved or collected by Java runtime.

This change keeps track of the pinned array info in a 'pinned' linked
list, and unpin them as the Seq memory is freed.  The jbyteArray
argument passed to Seq.writeByteArray is needed to release the pinned
byte array elements, but that is a "local reference". It is not
guaranteed that the reference is valid after the method returns. Thus,
we stash its global reference in the 'pinned' list and delete it later
as well.

A similar problem can occur on the byte slice returned from a Go function.
This change does not address the case yet.

Fixes golang/go#9486

Change-Id: I1255aefbc80b21ccbe9b2bf37699faaf0c5f0bae
Reviewed-on: https://go-review.googlesource.com/2586
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-01-14 19:06:28 +00:00
Hyang-Ah Hana Kim 2b3c96656c cmd/gobind: implement interface method binding.
This change makes gobind to generate proper Go-side proxy code to
handle interface methods that have parameters and return values.

It allows gobind to accept struct pointer types as parameters
or a return value of a method.

Fixes golang/go#9487, golang/go#9488.

Change-Id: Id243c42ee0701d40e3871e392140368c2f8f9bc6
Reviewed-on: https://go-review.googlesource.com/2348
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-01-07 18:26:42 +00:00
Hyang-Ah Hana Kim 8f449fffd2 bind/java/testpkg: use go generate to run gobind on testpkg.
Change-Id: I2426f3607120b7ce2da60bcb45d834b539d7dbb9
Reviewed-on: https://go-review.googlesource.com/2342
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-01-07 17:28:35 +00:00
Shenghou Ma bd50534d55 bind: remove temporary files used in tests
Fixes golang/go#9513

Change-Id: I19a14f6e8f24396e5a191258917e5ff9caf8928a
Reviewed-on: https://go-review.googlesource.com/2343
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-01-06 06:13:23 +00:00