]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testso: enable test on windows
authorShenghou Ma <minux.ma@gmail.com>
Mon, 22 Apr 2013 20:42:04 +0000 (04:42 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 22 Apr 2013 20:42:04 +0000 (04:42 +0800)
Depends on CL 8715043 and CL 8676050.
Fixes #5273.

R=alex.brainman, r
CC=gobot, golang-dev
https://golang.org/cl/8764043

misc/cgo/testso/cgoso.c [new file with mode: 0644]
misc/cgo/testso/cgoso.go
misc/cgo/testso/cgoso_c.c
misc/cgo/testso/test.bat [new file with mode: 0644]
src/run.bat

diff --git a/misc/cgo/testso/cgoso.c b/misc/cgo/testso/cgoso.c
new file mode 100644 (file)
index 0000000..917f472
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2013 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.
+
+#include "_cgo_export.h"
+
+#ifdef WIN32
+extern void setCallback(void *);
+void init() {
+       setCallback(goCallback);
+}
+#else
+void init() {}
+#endif
index 44fb616c11821fd15d3da2710b3f6b2ea694f7bd..216cb1f05f55b930f5b97980a228fc2787b8598c 100644 (file)
@@ -6,11 +6,13 @@ package cgosotest
 
 /*
 #cgo LDFLAGS: -L. -lcgosotest
+void init(void);
 void sofunc(void);
 */
 import "C"
 
 func Test() {
+       C.init()
        C.sofunc()
 }
 
index 8c15a6b9ff2003e54a0ca91fd551afb7285fb0c1..27155c27f7b6c2782f5e06fdebf643cd28f9801f 100644 (file)
@@ -4,8 +4,22 @@
 
 // +build ignore
 
+#ifdef WIN32
+// A Windows DLL is unable to call an arbitrary function in
+// the main executable. Work around that by making the main
+// executable pass the callback function pointer to us.
+void (*goCallback)(void);
+__declspec(dllexport) void setCallback(void *f)
+{
+       goCallback = (void (*)())f;
+}
+__declspec(dllexport) void sofunc(void);
+#else
+extern void goCallback(void);
+void setCallback(void *f) { (void)f; }
+#endif
+
 void sofunc(void)
 {
-       extern void goCallback(void);
        goCallback();
 }
diff --git a/misc/cgo/testso/test.bat b/misc/cgo/testso/test.bat
new file mode 100644 (file)
index 0000000..b8cc384
--- /dev/null
@@ -0,0 +1,18 @@
+:: Copyright 2013 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.
+
+@echo off
+
+gcc -c cgoso_c.c
+gcc -shared -o libcgosotest.dll cgoso_c.o
+if not exist libcgosotest.dll goto fail
+go build main.go
+if not exist main.exe goto fail
+main.exe
+goto :end
+
+:fail
+set FAIL=1
+:end
+del /F cgoso_c.o libcgosotest.dll main.exe 2>NUL
index 02d19d6c7e7f915b5f8eb576ff4181cb099d20d4..c7b9b9c5a9acd32bcc056f1f6a8c375717708305 100644 (file)
@@ -87,6 +87,14 @@ echo # ..\misc\cgo\test
 go test ..\misc\cgo\test
 if errorlevel 1 goto fail
 echo.
+
+echo # ..\misc\cgo\testso
+cd ..\misc\cgo\testso
+set FAIL=0
+call test.bat
+cd ..\..\..\src
+if %FAIL%==1 goto fail
+echo.
 :nocgo
 
 echo # ..\doc\progs