void callback(void *f);
void callGoFoo(void);
void callGoStackCheck(void);
+void callPanic(void);
*/
import "C"
}
}
+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.
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;
+}
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) }
#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.
#pragma cgo_export_static _cgo_allocate
#pragma cgo_export_dynamic _cgo_allocate
+#pragma textflag NOSPLIT
void
_cgo_allocate(void *a, int32 n)
{
#pragma cgo_export_static _cgo_panic
#pragma cgo_export_dynamic _cgo_panic
+#pragma textflag NOSPLIT
void
_cgo_panic(void *a, int32 n)
{