]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/cgo: mark callback functions as NOSPLIT
authorIan Lance Taylor <iant@golang.org>
Wed, 9 Oct 2013 15:44:47 +0000 (08:44 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 9 Oct 2013 15:44:47 +0000 (08:44 -0700)
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/14448044

misc/cgo/test/callback.go
misc/cgo/test/callback_c.c
misc/cgo/test/cgo_test.go
src/pkg/runtime/cgo/callbacks.c

index 838105155a59772ea53f29c256cf0ad350be0ae9..82ed015bd807b5698feca83d0b74044f7975a879 100644 (file)
@@ -8,6 +8,7 @@ package cgotest
 void callback(void *f);
 void callGoFoo(void);
 void callGoStackCheck(void);
+void callPanic(void);
 */
 import "C"
 
@@ -186,6 +187,19 @@ func testCallbackCallers(t *testing.T) {
        }
 }
 
+func testPanicFromC(t *testing.T) {
+       defer func() {
+               r := recover()
+               if r == nil {
+                       t.Fatal("did not panic")
+               }
+               if r.(string) != "panic from C" {
+                       t.Fatal("wrong panic:", r)
+               }
+       }()
+       C.callPanic()
+}
+
 func testCallbackStack(t *testing.T) {
        // Make cgo call and callback with different amount of stack stack available.
        // We do not do any explicit checks, just ensure that it does not crash.
index dcd4ddd4ee3b1062df92e3dee3db354b8db0e939..4bfeb7163e363360c87d2be14fd2ef02382c9fbd 100644 (file)
@@ -64,3 +64,17 @@ callGoStackCheck(void)
        extern void goStackCheck(void);
        goStackCheck();
 }
+
+/* Test calling panic from C.  This is what SWIG does.  */
+
+extern void crosscall2(void (*fn)(void *, int), void *, int);
+extern void _cgo_panic(void *, int);
+
+void
+callPanic(void)
+{
+       struct { const char *p; } a;
+       a.p = "panic from C";
+       crosscall2(_cgo_panic, &a, sizeof a);
+       *(int*)1 = 1;
+}
index 799536c544feff065b23f62eb39a9f50af7e1a3c..45572bad1a2f57bf1ab8fa24d79918530a120f34 100644 (file)
@@ -22,6 +22,7 @@ func TestCallbackGC(t *testing.T)          { testCallbackGC(t) }
 func TestCallbackPanic(t *testing.T)       { testCallbackPanic(t) }
 func TestCallbackPanicLoop(t *testing.T)   { testCallbackPanicLoop(t) }
 func TestCallbackPanicLocked(t *testing.T) { testCallbackPanicLocked(t) }
+func TestPanicFromC(t *testing.T)          { testPanicFromC(t) }
 func TestZeroArgCallback(t *testing.T)     { testZeroArgCallback(t) }
 func TestBlocking(t *testing.T)            { testBlocking(t) }
 func Test1328(t *testing.T)                { test1328(t) }
index 524f30428b0e86d2c56ab185d375e5216edc32df..e91c8bf8a33770758f4579cc625e71bb3938efda 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "../runtime.h"
 #include "../cgocall.h"
+#include "../../../cmd/ld/textflag.h"
 
 // These utility functions are available to be called from code
 // compiled with gcc via crosscall2.
@@ -47,6 +48,7 @@ _cgo_allocate_internal(uintptr len, byte *ret)
 
 #pragma cgo_export_static _cgo_allocate
 #pragma cgo_export_dynamic _cgo_allocate
+#pragma textflag NOSPLIT
 void
 _cgo_allocate(void *a, int32 n)
 {
@@ -76,6 +78,7 @@ _cgo_panic_internal(byte *p)
 
 #pragma cgo_export_static _cgo_panic
 #pragma cgo_export_dynamic _cgo_panic
+#pragma textflag NOSPLIT
 void
 _cgo_panic(void *a, int32 n)
 {