mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
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
This commit is contained in:
committed by
Ron Evans
parent
0db403dc0c
commit
b41e58bcb4
Vendored
+16
@@ -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
|
||||
|
||||
Vendored
+6
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user