seq.go.support 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. // Go support functions for generated Go bindings. This file is
  6. // copied into the generated main package, and compiled along
  7. // with the bindings.
  8. // #cgo android CFLAGS: -D__GOBIND_ANDROID__
  9. // #cgo darwin CFLAGS: -D__GOBIND_DARWIN__
  10. // #include <stdlib.h>
  11. // #include "seq.h"
  12. import "C"
  13. import (
  14. "fmt"
  15. "os"
  16. "os/signal"
  17. "syscall"
  18. _ "golang.org/x/mobile/bind/java"
  19. _seq "golang.org/x/mobile/bind/seq"
  20. )
  21. func init() {
  22. _seq.FinalizeRef = func(ref *_seq.Ref) {
  23. refnum := ref.Bind_Num
  24. if refnum < 0 {
  25. panic(fmt.Sprintf("not a foreign ref: %d", refnum))
  26. }
  27. C.go_seq_dec_ref(C.int32_t(refnum))
  28. }
  29. _seq.IncForeignRef = func(refnum int32) {
  30. if refnum < 0 {
  31. panic(fmt.Sprintf("not a foreign ref: %d", refnum))
  32. }
  33. C.go_seq_inc_ref(C.int32_t(refnum))
  34. }
  35. // Workaround for issue #17393.
  36. signal.Notify(make(chan os.Signal), syscall.SIGPIPE)
  37. }
  38. // IncGoRef is called by foreign code to pin a Go object while its refnum is crossing
  39. // the language barrier
  40. //export IncGoRef
  41. func IncGoRef(refnum C.int32_t) {
  42. _seq.Inc(int32(refnum))
  43. }
  44. func main() {}