mirror of
https://github.com/golang/go
synced 2024-11-26 02:17:58 -07:00
misc/cgo/testso: enable test on windows
Depends on CL 8715043 and CL 8676050. Fixes #5273. R=alex.brainman, r CC=gobot, golang-dev https://golang.org/cl/8764043
This commit is contained in:
parent
c285789059
commit
8c72b81132
14
misc/cgo/testso/cgoso.c
Normal file
14
misc/cgo/testso/cgoso.c
Normal file
@ -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
|
@ -6,11 +6,13 @@ package cgosotest
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -L. -lcgosotest
|
#cgo LDFLAGS: -L. -lcgosotest
|
||||||
|
void init(void);
|
||||||
void sofunc(void);
|
void sofunc(void);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func Test() {
|
func Test() {
|
||||||
|
C.init()
|
||||||
C.sofunc()
|
C.sofunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,22 @@
|
|||||||
|
|
||||||
// +build ignore
|
// +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)
|
void sofunc(void)
|
||||||
{
|
{
|
||||||
extern void goCallback(void);
|
|
||||||
goCallback();
|
goCallback();
|
||||||
}
|
}
|
||||||
|
18
misc/cgo/testso/test.bat
Normal file
18
misc/cgo/testso/test.bat
Normal file
@ -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
|
@ -87,6 +87,14 @@ echo # ..\misc\cgo\test
|
|||||||
go test ..\misc\cgo\test
|
go test ..\misc\cgo\test
|
||||||
if errorlevel 1 goto fail
|
if errorlevel 1 goto fail
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
|
echo # ..\misc\cgo\testso
|
||||||
|
cd ..\misc\cgo\testso
|
||||||
|
set FAIL=0
|
||||||
|
call test.bat
|
||||||
|
cd ..\..\..\src
|
||||||
|
if %FAIL%==1 goto fail
|
||||||
|
echo.
|
||||||
:nocgo
|
:nocgo
|
||||||
|
|
||||||
echo # ..\doc\progs
|
echo # ..\doc\progs
|
||||||
|
Loading…
Reference in New Issue
Block a user