Skip to content

Commit 285ddcb

Browse files
ianlancetaylorpull[bot]
authored andcommitted
cmd/cgo: declare _GoString{Len,Ptr} in _cgo_export.h
Fixes #71226 Change-Id: I91c46a4310a9c7a9fcd1e3a131ca16e46949edb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/642235 Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f17db0b commit 285ddcb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cmd/cgo/out.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,8 @@ const builtinExportProlog = `
19381938
19391939
#ifndef GO_CGO_GOSTRING_TYPEDEF
19401940
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
1941+
extern size_t _GoStringLen(_GoString_ s);
1942+
extern const char *_GoStringPtr(_GoString_ s);
19411943
#endif
19421944
19431945
#endif

test/fixedbugs/issue71226.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// build
2+
3+
//go:build cgo
4+
5+
// Copyright 2025 The Go Authors. All rights reserved.
6+
// Use of this source code is governed by a BSD-style
7+
// license that can be found in the LICENSE file.
8+
9+
package main
10+
11+
/*
12+
#cgo CFLAGS: -Werror -Wimplicit-function-declaration
13+
14+
#include <stdio.h>
15+
16+
static void CFn(_GoString_ gostr) {
17+
printf("%.*s\n", _GoStringLen(gostr), _GoStringPtr(gostr));
18+
}
19+
*/
20+
import "C"
21+
22+
func main() {
23+
C.CFn("hello, world")
24+
}
25+
26+
// The bug only occurs if there is an exported function.
27+
//export Fn
28+
func Fn() {
29+
}

0 commit comments

Comments
 (0)