github.com/cyrilou242/gomobile-java@v0.0.0-20220215185836-09daef25a210/bind/seq.go.support (about)

     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  
     5  package main
     6  
     7  // Go support functions for generated Go bindings. This file is
     8  // copied into the generated main package, and compiled along
     9  // with the bindings.
    10  
    11  // #cgo android CFLAGS: -D__GOBIND_ANDROID__
    12  // #cgo darwin CFLAGS: -D__GOBIND_DARWIN__
    13  // #include <stdlib.h>
    14  // #include "seq.h"
    15  import "C"
    16  import (
    17  	"unsafe"
    18  
    19  	"github.com/cyrilou242/gomobile-java/bind/seq"
    20  )
    21  
    22  func init() {
    23  	_seq.FinalizeRef = func(ref *_seq.Ref) {
    24  		refnum := ref.Bind_Num
    25  		if refnum < 0 {
    26  			panic(fmt.Sprintf("not a foreign ref: %d", refnum))
    27  		}
    28  		C.go_seq_dec_ref(C.int32_t(refnum))
    29  	}
    30  	_seq.IncForeignRef = func(refnum int32) {
    31  		if refnum < 0 {
    32  			panic(fmt.Sprintf("not a foreign ref: %d", refnum))
    33  		}
    34  		C.go_seq_inc_ref(C.int32_t(refnum))
    35  	}
    36  	// Workaround for issue #17393.
    37  	signal.Notify(make(chan os.Signal), syscall.SIGPIPE)
    38  }
    39  
    40  // IncGoRef is called by foreign code to pin a Go object while its refnum is crossing
    41  // the language barrier
    42  //export IncGoRef
    43  func IncGoRef(refnum C.int32_t) {
    44  	_seq.Inc(int32(refnum))
    45  }
    46  
    47  func main() {}