2
0
mirror of synced 2025-02-23 23:08:14 +00:00
mobile/bind/seq.go.support
Elias Naur 72eef9d093 bind: avoid crashes from SIGPIPE
The Go runtime doesn't handle SIGIPE signals from writing to closed
sockets or pipes in c-archive and c-shared mode (issue 17393).
Work around it in gomobile by simply ignoring all SIGPIPE signals;
they're not useful in mobile apps anyway.

Change-Id: Ibd7ee41058856c5eddb4a519345a3851a29e9b44
Reviewed-on: https://go-review.googlesource.com/33771
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-12-01 16:06:28 +00:00

48 lines
1.1 KiB
Plaintext

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gomobile_bind
// Go support functions for generated Go bindings. This file is
// copied into the generated package, gomobile_bind, and compiled
// along with the bindings.
// #include <stdlib.h>
// #include "seq.h"
import "C"
import (
"fmt"
"os"
"os/signal"
"syscall"
_seq "golang.org/x/mobile/bind/seq"
)
func init() {
_seq.FinalizeRef = func(ref *_seq.Ref) {
refnum := ref.Bind_Num
if refnum < 0 {
panic(fmt.Sprintf("not a foreign ref: %d", refnum))
}
C.go_seq_dec_ref(C.int32_t(refnum))
}
_seq.IncForeignRef = func(refnum int32) {
if refnum < 0 {
panic(fmt.Sprintf("not a foreign ref: %d", refnum))
}
C.go_seq_inc_ref(C.int32_t(refnum))
}
// Workaround for issue #17393.
signal.Notify(make(chan os.Signal), syscall.SIGPIPE)
}
// IncGoRef is called by foreign code to pin a Go object while its refnum is crossing
// the language barrier
//export IncGoRef
func IncGoRef(refnum C.int32_t) {
_seq.Inc(int32(refnum))
}