github.com/SahandAslani/gomobile@v0.0.0-20210909130135-2cb2d44c09b2/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  
    17  import (
    18  	"fmt"
    19  	"os"
    20  	"os/signal"
    21  	"syscall"
    22  
    23  	_ "github.com/SahandAslani/gomobile/bind/java"
    24  	_seq "github.com/SahandAslani/gomobile/bind/seq"
    25  )
    26  
    27  func init() {
    28  	_seq.FinalizeRef = func(ref *_seq.Ref) {
    29  		refnum := ref.Bind_Num
    30  		if refnum < 0 {
    31  			panic(fmt.Sprintf("not a foreign ref: %d", refnum))
    32  		}
    33  		C.go_seq_dec_ref(C.int32_t(refnum))
    34  	}
    35  	_seq.IncForeignRef = func(refnum int32) {
    36  		if refnum < 0 {
    37  			panic(fmt.Sprintf("not a foreign ref: %d", refnum))
    38  		}
    39  		C.go_seq_inc_ref(C.int32_t(refnum))
    40  	}
    41  	// Workaround for issue #17393.
    42  	signal.Notify(make(chan os.Signal), syscall.SIGPIPE)
    43  }
    44  
    45  // IncGoRef is called by foreign code to pin a Go object while its refnum is crossing
    46  // the language barrier
    47  //export IncGoRef
    48  func IncGoRef(refnum C.int32_t) {
    49  	_seq.Inc(int32(refnum))
    50  }
    51  
    52  func main() {}