From 519725bb3c075ee2462c929f5997cb068e18466a Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 26 Mar 2012 16:50:58 +0200 Subject: Imported Upstream version 2012.03.22 --- misc/cgo/test/backdoor/backdoor.go | 7 +++++++ misc/cgo/test/backdoor/runtime.c | 23 +++++++++++++++++++++++ misc/cgo/test/basic.go | 4 ++-- misc/cgo/test/callback.go | 8 +++----- misc/cgo/test/callback_c.c | 20 ++++++++++++++++++++ misc/cgo/test/issue1328.go | 2 +- misc/cgo/test/issue1560.go | 5 +---- misc/cgo/test/runtime.c | 21 --------------------- 8 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 misc/cgo/test/backdoor/backdoor.go create mode 100644 misc/cgo/test/backdoor/runtime.c delete mode 100644 misc/cgo/test/runtime.c (limited to 'misc/cgo/test') diff --git a/misc/cgo/test/backdoor/backdoor.go b/misc/cgo/test/backdoor/backdoor.go new file mode 100644 index 000000000..efe4f01f4 --- /dev/null +++ b/misc/cgo/test/backdoor/backdoor.go @@ -0,0 +1,7 @@ +// Copyright 2012 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 backdoor + +func LockedOSThread() bool // in runtime.c diff --git a/misc/cgo/test/backdoor/runtime.c b/misc/cgo/test/backdoor/runtime.c new file mode 100644 index 000000000..54e6a1ef8 --- /dev/null +++ b/misc/cgo/test/backdoor/runtime.c @@ -0,0 +1,23 @@ +// Copyright 2011 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. + +// Expose some runtime functions for testing. +// Must be in a non-cgo-using package so that +// the go command compiles this file with 6c, not gcc. + +typedef char bool; + +bool runtime·lockedOSThread(void); + +static void +FLUSH(void*) +{ +} + +void +·LockedOSThread(bool b) +{ + b = runtime·lockedOSThread(); + FLUSH(&b); +} diff --git a/misc/cgo/test/basic.go b/misc/cgo/test/basic.go index cd6d88168..70ec5e43a 100644 --- a/misc/cgo/test/basic.go +++ b/misc/cgo/test/basic.go @@ -55,7 +55,7 @@ int add(int x, int y) { */ import "C" import ( - "os" + "syscall" "testing" "unsafe" ) @@ -110,7 +110,7 @@ func testErrno(t *testing.T) { C.fclose(f) t.Fatalf("C.fopen: should fail") } - if err != os.ENOENT { + if err != syscall.ENOENT { t.Fatalf("C.fopen: unexpected error: %v", err) } } diff --git a/misc/cgo/test/callback.go b/misc/cgo/test/callback.go index ef852561b..e6a1462b3 100644 --- a/misc/cgo/test/callback.go +++ b/misc/cgo/test/callback.go @@ -6,14 +6,12 @@ package cgotest /* void callback(void *f); -void callGoFoo(void) { - extern void goFoo(void); - goFoo(); -} +void callGoFoo(void); */ import "C" import ( + "./backdoor" "runtime" "testing" "unsafe" @@ -43,7 +41,7 @@ func testCallbackGC(t *testing.T) { nestedCall(runtime.GC) } -func lockedOSThread() bool // in runtime.c +var lockedOSThread = backdoor.LockedOSThread func testCallbackPanic(t *testing.T) { // Make sure panic during callback unwinds properly. diff --git a/misc/cgo/test/callback_c.c b/misc/cgo/test/callback_c.c index c296d70e0..47f07301b 100644 --- a/misc/cgo/test/callback_c.c +++ b/misc/cgo/test/callback_c.c @@ -15,3 +15,23 @@ callback(void *f) goCallback(f); data[sizeof(data)-1] = 0; } + +void +callGoFoo(void) +{ + extern void goFoo(void); + goFoo(); +} + +void +IntoC(void) +{ + BackIntoGo(); +} + +void +twoSleep(int n) +{ + BackgroundSleep(n); + sleep(n); +} diff --git a/misc/cgo/test/issue1328.go b/misc/cgo/test/issue1328.go index e01207dd9..e1796d6f7 100644 --- a/misc/cgo/test/issue1328.go +++ b/misc/cgo/test/issue1328.go @@ -7,7 +7,7 @@ package cgotest import "testing" // extern void BackIntoGo(void); -// void IntoC() { BackIntoGo(); } +// void IntoC(void); import "C" //export BackIntoGo diff --git a/misc/cgo/test/issue1560.go b/misc/cgo/test/issue1560.go index 833b14ae6..3faa966e7 100644 --- a/misc/cgo/test/issue1560.go +++ b/misc/cgo/test/issue1560.go @@ -10,10 +10,7 @@ package cgotest unsigned int sleep(unsigned int seconds); extern void BackgroundSleep(int); -void twoSleep(int n) { - BackgroundSleep(n); - sleep(n); -} +void twoSleep(int); */ import "C" diff --git a/misc/cgo/test/runtime.c b/misc/cgo/test/runtime.c deleted file mode 100644 index e087c7622..000000000 --- a/misc/cgo/test/runtime.c +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2011 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. - -// Expose some runtime functions for testing. - -typedef char bool; - -bool runtime·lockedOSThread(void); - -static void -FLUSH(void*) -{ -} - -void -·lockedOSThread(bool b) -{ - b = runtime·lockedOSThread(); - FLUSH(&b); -} -- cgit v1.2.3