Skip to content

Commit 1ed0d12

Browse files
runtime: testprogcgo: don't call exported Go functions directly from Go
Instead route through a C function, to avoid declaration conflicts between the declaration needed in the cgo comment and the declaration generated by cgo in _cgo_export.h. This is not something user code will ever do, so no need to make it work in cgo. Fixes #46502 Change-Id: I1bfffdc76ef8ea63e3829871298d0774157957a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/327309 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Jason A. Donenfeld <[email protected]>
1 parent 9d46ee5 commit 1ed0d12

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/runtime/testdata/testprogcgo/aprof.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package main
1010
// The test fails when the function is the first C function.
1111
// The exported functions are the first C functions, so we use that.
1212

13-
// extern void GoNop();
13+
// extern void CallGoNop();
1414
import "C"
1515

1616
import (
@@ -38,7 +38,7 @@ func CgoCCodeSIGPROF() {
3838
break
3939
}
4040
}
41-
C.GoNop()
41+
C.CallGoNop()
4242
}
4343
c <- true
4444
}()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include "_cgo_export.h"
6+
7+
void CallGoNop() {
8+
GoNop();
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// This is not in bigstack_windows.c because it needs to be part of
6+
// testprogcgo but is not part of the DLL built from bigstack_windows.c.
7+
8+
#include "_cgo_export.h"
9+
10+
void CallGoBigStack1(char* p) {
11+
goBigStack1(p);
12+
}

src/runtime/testdata/testprogcgo/bigstack_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package main
66

77
/*
88
typedef void callback(char*);
9-
extern void goBigStack1(char*);
9+
extern void CallGoBigStack1(char*);
1010
extern void bigStack(callback*);
1111
*/
1212
import "C"
@@ -18,7 +18,7 @@ func init() {
1818
func BigStack() {
1919
// Create a large thread stack and call back into Go to test
2020
// if Go correctly determines the stack bounds.
21-
C.bigStack((*C.callback)(C.goBigStack1))
21+
C.bigStack((*C.callback)(C.CallGoBigStack1))
2222
}
2323

2424
//export goBigStack1

0 commit comments

Comments
 (0)