1
0
mirror of https://github.com/golang/go synced 2024-11-14 08:50:22 -07:00
go/misc/cgo/test/testdata/issue9026/issue9026.go
Tai e13a4d9586 cmd/cgo: build unique C type cache keys from parent names
When translating C types, cache the in-progress type under its parent
names, so that anonymous structs can also be translated for multiple
typedefs, without clashing.

Standalone types are not affected by this change.

Also updated the test for issue 9026 because the C struct name
generation algorithm has changed.

Fixes #31891

Change-Id: I00cc64852a2617ce33da13f74caec886af05b9f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/181857
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-05 00:16:04 +00:00

37 lines
931 B
Go

package issue9026
// This file appears in its own package since the assertion tests the
// per-package counter used to create fresh identifiers.
/*
typedef struct {} git_merge_file_input;
typedef struct {} git_merge_file_options;
void git_merge_file(
git_merge_file_input *in,
git_merge_file_options *opts) {}
*/
import "C"
import (
"fmt"
"testing"
)
func Test(t *testing.T) {
var in C.git_merge_file_input
var opts *C.git_merge_file_options
C.git_merge_file(&in, opts)
// Test that the generated type names are deterministic.
// (Previously this would fail about 10% of the time.)
//
// Brittle: the assertion may fail spuriously when the algorithm
// changes, but should remain stable otherwise.
got := fmt.Sprintf("%T %T", in, opts)
want := "issue9026._Ctype_struct___0 *issue9026._Ctype_struct___1"
if got != want {
t.Errorf("Non-deterministic type names: got %s, want %s", got, want)
}
}