Commit 8c72b811 authored by Shenghou Ma's avatar Shenghou Ma

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
parent c2857890
// 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
void init(void);
void sofunc(void);
*/
import "C"
func Test() {
C.init()
C.sofunc()
}
......
......@@ -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();
}
:: 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
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment