diff options
author | Ayke van Laethem <[email protected]> | 2019-11-06 14:02:18 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2019-11-06 15:54:18 +0100 |
commit | b41e58bcb4a769f0fbfd7d1c85aaeb239802dc4e (patch) | |
tree | e18fd040a5d1a7083d0bcd629dceec2f83a82110 /cgo/testdata | |
parent | 0db403dc0c073f767bf211baea5d9adfe327adc5 (diff) | |
download | tinygo-b41e58bcb4a769f0fbfd7d1c85aaeb239802dc4e.tar.gz tinygo-b41e58bcb4a769f0fbfd7d1c85aaeb239802dc4e.zip |
cgo: rename reserved field names like `type`
This commit renames reserved field names like `type` to `_type`, and in
turn renames those fields as well (recursively). This avoids name
clashes when a C struct contains a field named `type`, which is a
reserved keyword in Go.
For some details, see:
https://golang.org/cmd/cgo/#hdr-Go_references_to_C
Diffstat (limited to 'cgo/testdata')
-rw-r--r-- | cgo/testdata/types.go | 16 | ||||
-rw-r--r-- | cgo/testdata/types.out.go | 6 |
2 files changed, 22 insertions, 0 deletions
diff --git a/cgo/testdata/types.go b/cgo/testdata/types.go index b129d4be4..bd1f0ffbe 100644 --- a/cgo/testdata/types.go +++ b/cgo/testdata/types.go @@ -15,6 +15,18 @@ typedef struct point3d { int z; } point3d_t; +// Structs with reserved field names. +struct type1 { + // All these fields should be renamed. + int type; + int _type; + int __type; +}; +struct type2 { + // This field should not be renamed. + int _type; +}; + // Enums. These define constant numbers. All these constants must be given the // correct number. typedef enum option { @@ -66,6 +78,10 @@ var ( _ C.point3d_t _ C.struct_point3d + // Structs with reserved field names. + _ C.struct_type1 + _ C.struct_type2 + // Enums (anonymous and named). _ C.option_t _ C.enum_option diff --git a/cgo/testdata/types.out.go b/cgo/testdata/types.out.go index 6e586a9d7..939c1a5a6 100644 --- a/cgo/testdata/types.out.go +++ b/cgo/testdata/types.out.go @@ -72,4 +72,10 @@ type C.struct_point3d struct { y C.int z C.int } +type C.struct_type1 struct { + _type C.int + __type C.int + ___type C.int +} +type C.struct_type2 struct{ _type C.int } type C.enum_option C.int |