cgo: mangle identifier names

This mangles CGo identifier names to something like "_Cgo_foo" instead
of using literal identifiers like "C.foo". This works around
https://github.com/golang/go/issues/71777.

I don't like this solution, but I hope we'll find a better solution in
the future. In that case we can revert this commit.
This commit is contained in:
Ayke van Laethem
2025-02-16 14:29:32 +01:00
committed by Ron Evans
parent a6cd072fa1
commit ea53ace270
9 changed files with 367 additions and 383 deletions
+45 -64
View File
@@ -92,18 +92,18 @@ type noescapingFunc struct {
// cgoAliases list type aliases between Go and C, for types that are equivalent // cgoAliases list type aliases between Go and C, for types that are equivalent
// in both languages. See addTypeAliases. // in both languages. See addTypeAliases.
var cgoAliases = map[string]string{ var cgoAliases = map[string]string{
"C.int8_t": "int8", "_Cgo_int8_t": "int8",
"C.int16_t": "int16", "_Cgo_int16_t": "int16",
"C.int32_t": "int32", "_Cgo_int32_t": "int32",
"C.int64_t": "int64", "_Cgo_int64_t": "int64",
"C.uint8_t": "uint8", "_Cgo_uint8_t": "uint8",
"C.uint16_t": "uint16", "_Cgo_uint16_t": "uint16",
"C.uint32_t": "uint32", "_Cgo_uint32_t": "uint32",
"C.uint64_t": "uint64", "_Cgo_uint64_t": "uint64",
"C.uintptr_t": "uintptr", "_Cgo_uintptr_t": "uintptr",
"C.float": "float32", "_Cgo_float": "float32",
"C.double": "float64", "_Cgo_double": "float64",
"C._Bool": "bool", "_Cgo__Bool": "bool",
} }
// builtinAliases are handled specially because they only exist on the Go side // builtinAliases are handled specially because they only exist on the Go side
@@ -145,48 +145,46 @@ typedef unsigned long long _Cgo_ulonglong;
// The string/bytes functions below implement C.CString etc. To make sure the // The string/bytes functions below implement C.CString etc. To make sure the
// runtime doesn't need to know the C int type, lengths are converted to uintptr // runtime doesn't need to know the C int type, lengths are converted to uintptr
// first. // first.
// These functions will be modified to get a "C." prefix, so the source below
// doesn't reflect the final AST.
const generatedGoFilePrefixBase = ` const generatedGoFilePrefixBase = `
import "syscall" import "syscall"
import "unsafe" import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func __GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func __GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func __CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func __get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
` `
const generatedGoFilePrefixOther = generatedGoFilePrefixBase + ` const generatedGoFilePrefixOther = generatedGoFilePrefixBase + `
func __get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
` `
@@ -197,7 +195,7 @@ func __get_errno() error {
// map the errno values to match the values in the syscall package. // map the errno values to match the values in the syscall package.
// Source of the errno values: lib/mingw-w64/mingw-w64-headers/crt/errno.h // Source of the errno values: lib/mingw-w64/mingw-w64-headers/crt/errno.h
const generatedGoFilePrefixWindows = generatedGoFilePrefixBase + ` const generatedGoFilePrefixWindows = generatedGoFilePrefixBase + `
var __errno_mapping = [...]syscall.Errno{ var _Cgo___errno_mapping = [...]syscall.Errno{
1: syscall.EPERM, 1: syscall.EPERM,
2: syscall.ENOENT, 2: syscall.ENOENT,
3: syscall.ESRCH, 3: syscall.ESRCH,
@@ -238,10 +236,10 @@ var __errno_mapping = [...]syscall.Errno{
42: syscall.EILSEQ, 42: syscall.EILSEQ,
} }
func __get_errno() error { func _Cgo___get_errno() error {
num := C.__get_errno_num() num := _Cgo___get_errno_num()
if num < uintptr(len(__errno_mapping)) { if num < uintptr(len(_Cgo___errno_mapping)) {
if mapped := __errno_mapping[num]; mapped != 0 { if mapped := _Cgo___errno_mapping[num]; mapped != 0 {
return mapped return mapped
} }
} }
@@ -304,23 +302,6 @@ func Process(files []*ast.File, dir, importPath string, fset *token.FileSet, cfl
// If the Comments field is not set to nil, the go/format package will get // If the Comments field is not set to nil, the go/format package will get
// confused about where comments should go. // confused about where comments should go.
p.generated.Comments = nil p.generated.Comments = nil
// Adjust some of the functions in there.
for _, decl := range p.generated.Decls {
switch decl := decl.(type) {
case *ast.FuncDecl:
switch decl.Name.Name {
case "CString", "GoString", "GoStringN", "__GoStringN", "GoBytes", "__GoBytes", "CBytes", "__CBytes", "__get_errno_num", "__get_errno", "__errno_mapping":
// Adjust the name to have a "C." prefix so it is correctly
// resolved.
decl.Name.Name = "C." + decl.Name.Name
}
}
}
// Patch some types, for example *C.char in C.CString.
cf := p.newCGoFile(nil, -1) // dummy *cgoFile for the walker
astutil.Apply(p.generated, func(cursor *astutil.Cursor) bool {
return cf.walker(cursor, nil)
}, nil)
// Find `import "C"` C fragments in the file. // Find `import "C"` C fragments in the file.
p.cgoHeaders = make([]string, len(files)) // combined CGo header fragment for each file p.cgoHeaders = make([]string, len(files)) // combined CGo header fragment for each file
@@ -399,7 +380,7 @@ func Process(files []*ast.File, dir, importPath string, fset *token.FileSet, cfl
Tok: token.TYPE, Tok: token.TYPE,
} }
for _, name := range builtinAliases { for _, name := range builtinAliases {
typeSpec := p.getIntegerType("C."+name, names["_Cgo_"+name]) typeSpec := p.getIntegerType("_Cgo_"+name, names["_Cgo_"+name])
gen.Specs = append(gen.Specs, typeSpec) gen.Specs = append(gen.Specs, typeSpec)
} }
p.generated.Decls = append(p.generated.Decls, gen) p.generated.Decls = append(p.generated.Decls, gen)
@@ -1272,7 +1253,7 @@ func (p *cgoPackage) getUnnamedDeclName(prefix string, itf interface{}) string {
func (f *cgoFile) getASTDeclName(name string, found clangCursor, iscall bool) string { func (f *cgoFile) getASTDeclName(name string, found clangCursor, iscall bool) string {
// Some types are defined in stdint.h and map directly to a particular Go // Some types are defined in stdint.h and map directly to a particular Go
// type. // type.
if alias := cgoAliases["C."+name]; alias != "" { if alias := cgoAliases["_Cgo_"+name]; alias != "" {
return alias return alias
} }
node := f.getASTDeclNode(name, found) node := f.getASTDeclNode(name, found)
@@ -1282,7 +1263,7 @@ func (f *cgoFile) getASTDeclName(name string, found clangCursor, iscall bool) st
} }
return node.Name.Name return node.Name.Name
} }
return "C." + name return "_Cgo_" + name
} }
// getASTDeclNode will declare the given C AST node (if not already defined) and // getASTDeclNode will declare the given C AST node (if not already defined) and
@@ -1382,8 +1363,8 @@ extern __typeof(%s) %s __attribute__((alias(%#v)));
case *elaboratedTypeInfo: case *elaboratedTypeInfo:
// Add struct bitfields. // Add struct bitfields.
for _, bitfield := range elaboratedType.bitfields { for _, bitfield := range elaboratedType.bitfields {
f.createBitfieldGetter(bitfield, "C."+name) f.createBitfieldGetter(bitfield, "_Cgo_"+name)
f.createBitfieldSetter(bitfield, "C."+name) f.createBitfieldSetter(bitfield, "_Cgo_"+name)
} }
if elaboratedType.unionSize != 0 { if elaboratedType.unionSize != 0 {
// Create union getters/setters. // Create union getters/setters.
@@ -1392,7 +1373,7 @@ extern __typeof(%s) %s __attribute__((alias(%#v)));
f.addError(elaboratedType.pos, fmt.Sprintf("union must have field with a single name, it has %d names", len(field.Names))) f.addError(elaboratedType.pos, fmt.Sprintf("union must have field with a single name, it has %d names", len(field.Names)))
continue continue
} }
f.createUnionAccessor(field, "C."+name) f.createUnionAccessor(field, "_Cgo_"+name)
} }
} }
} }
@@ -1441,7 +1422,7 @@ func (f *cgoFile) walker(cursor *astutil.Cursor, names map[string]clangCursor) b
node.Rhs = append(node.Rhs, &ast.CallExpr{ node.Rhs = append(node.Rhs, &ast.CallExpr{
Fun: &ast.Ident{ Fun: &ast.Ident{
NamePos: node.Lhs[1].End(), NamePos: node.Lhs[1].End(),
Name: "C.__get_errno", Name: "_Cgo___get_errno",
}, },
}) })
} }
@@ -1466,7 +1447,7 @@ func (f *cgoFile) walker(cursor *astutil.Cursor, names map[string]clangCursor) b
return true return true
} }
if x.Name == "C" { if x.Name == "C" {
name := "C." + node.Sel.Name name := "_Cgo_" + node.Sel.Name
if found, ok := names[node.Sel.Name]; ok { if found, ok := names[node.Sel.Name]; ok {
name = f.getASTDeclName(node.Sel.Name, found, false) name = f.getASTDeclName(node.Sel.Name, found, false)
} }
+27 -27
View File
@@ -219,7 +219,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
numArgs := int(C.tinygo_clang_Cursor_getNumArguments(c)) numArgs := int(C.tinygo_clang_Cursor_getNumArguments(c))
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Fun, Kind: ast.Fun,
Name: "C." + name, Name: "_Cgo_" + name,
} }
exportName := name exportName := name
localName := name localName := name
@@ -257,7 +257,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
}, },
Name: &ast.Ident{ Name: &ast.Ident{
NamePos: pos, NamePos: pos,
Name: "C." + localName, Name: "_Cgo_" + localName,
Obj: obj, Obj: obj,
}, },
Type: &ast.FuncType{ Type: &ast.FuncType{
@@ -319,7 +319,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
return decl, stringSignature return decl, stringSignature
case C.CXCursor_StructDecl, C.CXCursor_UnionDecl: case C.CXCursor_StructDecl, C.CXCursor_UnionDecl:
typ := f.makeASTRecordType(c, pos) typ := f.makeASTRecordType(c, pos)
typeName := "C." + name typeName := "_Cgo_" + name
typeExpr := typ.typeExpr typeExpr := typ.typeExpr
if typ.unionSize != 0 { if typ.unionSize != 0 {
// Convert to a single-field struct type. // Convert to a single-field struct type.
@@ -340,7 +340,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
obj.Decl = typeSpec obj.Decl = typeSpec
return typeSpec, typ return typeSpec, typ
case C.CXCursor_TypedefDecl: case C.CXCursor_TypedefDecl:
typeName := "C." + name typeName := "_Cgo_" + name
underlyingType := C.tinygo_clang_getTypedefDeclUnderlyingType(c) underlyingType := C.tinygo_clang_getTypedefDeclUnderlyingType(c)
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Typ, Kind: ast.Typ,
@@ -378,12 +378,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
} }
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Var, Kind: ast.Var,
Name: "C." + name, Name: "_Cgo_" + name,
} }
valueSpec := &ast.ValueSpec{ valueSpec := &ast.ValueSpec{
Names: []*ast.Ident{{ Names: []*ast.Ident{{
NamePos: pos, NamePos: pos,
Name: "C." + name, Name: "_Cgo_" + name,
Obj: obj, Obj: obj,
}}, }},
Type: typeExpr, Type: typeExpr,
@@ -407,12 +407,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
} }
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Con, Kind: ast.Con,
Name: "C." + name, Name: "_Cgo_" + name,
} }
valueSpec := &ast.ValueSpec{ valueSpec := &ast.ValueSpec{
Names: []*ast.Ident{{ Names: []*ast.Ident{{
NamePos: pos, NamePos: pos,
Name: "C." + name, Name: "_Cgo_" + name,
Obj: obj, Obj: obj,
}}, }},
Values: []ast.Expr{expr}, Values: []ast.Expr{expr},
@@ -423,7 +423,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
case C.CXCursor_EnumDecl: case C.CXCursor_EnumDecl:
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Typ, Kind: ast.Typ,
Name: "C." + name, Name: "_Cgo_" + name,
} }
underlying := C.tinygo_clang_getEnumDeclIntegerType(c) underlying := C.tinygo_clang_getEnumDeclIntegerType(c)
// TODO: gc's CGo implementation uses types such as `uint32` for enums // TODO: gc's CGo implementation uses types such as `uint32` for enums
@@ -431,7 +431,7 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
typeSpec := &ast.TypeSpec{ typeSpec := &ast.TypeSpec{
Name: &ast.Ident{ Name: &ast.Ident{
NamePos: pos, NamePos: pos,
Name: "C." + name, Name: "_Cgo_" + name,
Obj: obj, Obj: obj,
}, },
Assign: pos, Assign: pos,
@@ -454,12 +454,12 @@ func (f *cgoFile) createASTNode(name string, c clangCursor) (ast.Node, any) {
} }
obj := &ast.Object{ obj := &ast.Object{
Kind: ast.Con, Kind: ast.Con,
Name: "C." + name, Name: "_Cgo_" + name,
} }
valueSpec := &ast.ValueSpec{ valueSpec := &ast.ValueSpec{
Names: []*ast.Ident{{ Names: []*ast.Ident{{
NamePos: pos, NamePos: pos,
Name: "C." + name, Name: "_Cgo_" + name,
Obj: obj, Obj: obj,
}}, }},
Values: []ast.Expr{expr}, Values: []ast.Expr{expr},
@@ -745,27 +745,27 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
var typeName string var typeName string
switch typ.kind { switch typ.kind {
case C.CXType_Char_S, C.CXType_Char_U: case C.CXType_Char_S, C.CXType_Char_U:
typeName = "C.char" typeName = "_Cgo_char"
case C.CXType_SChar: case C.CXType_SChar:
typeName = "C.schar" typeName = "_Cgo_schar"
case C.CXType_UChar: case C.CXType_UChar:
typeName = "C.uchar" typeName = "_Cgo_uchar"
case C.CXType_Short: case C.CXType_Short:
typeName = "C.short" typeName = "_Cgo_short"
case C.CXType_UShort: case C.CXType_UShort:
typeName = "C.ushort" typeName = "_Cgo_ushort"
case C.CXType_Int: case C.CXType_Int:
typeName = "C.int" typeName = "_Cgo_int"
case C.CXType_UInt: case C.CXType_UInt:
typeName = "C.uint" typeName = "_Cgo_uint"
case C.CXType_Long: case C.CXType_Long:
typeName = "C.long" typeName = "_Cgo_long"
case C.CXType_ULong: case C.CXType_ULong:
typeName = "C.ulong" typeName = "_Cgo_ulong"
case C.CXType_LongLong: case C.CXType_LongLong:
typeName = "C.longlong" typeName = "_Cgo_longlong"
case C.CXType_ULongLong: case C.CXType_ULongLong:
typeName = "C.ulonglong" typeName = "_Cgo_ulonglong"
case C.CXType_Bool: case C.CXType_Bool:
typeName = "bool" typeName = "bool"
case C.CXType_Float, C.CXType_Double, C.CXType_LongDouble: case C.CXType_Float, C.CXType_Double, C.CXType_LongDouble:
@@ -896,7 +896,7 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
typeSpelling := getString(C.clang_getTypeSpelling(typ)) typeSpelling := getString(C.clang_getTypeSpelling(typ))
typeKindSpelling := getString(C.clang_getTypeKindSpelling(typ.kind)) typeKindSpelling := getString(C.clang_getTypeKindSpelling(typ.kind))
f.addError(pos, fmt.Sprintf("unknown C type: %v (libclang type kind %s)", typeSpelling, typeKindSpelling)) f.addError(pos, fmt.Sprintf("unknown C type: %v (libclang type kind %s)", typeSpelling, typeKindSpelling))
typeName = "C.<unknown>" typeName = "_Cgo_<unknown>"
} }
return &ast.Ident{ return &ast.Ident{
NamePos: pos, NamePos: pos,
@@ -913,7 +913,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
var goName string var goName string
typeSize := C.clang_Type_getSizeOf(underlyingType) typeSize := C.clang_Type_getSizeOf(underlyingType)
switch name { switch name {
case "C.char": case "_Cgo_char":
if typeSize != 1 { if typeSize != 1 {
// This happens for some very special purpose architectures // This happens for some very special purpose architectures
// (DSPs etc.) that are not currently targeted. // (DSPs etc.) that are not currently targeted.
@@ -926,7 +926,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
case C.CXType_Char_U: case C.CXType_Char_U:
goName = "uint8" goName = "uint8"
} }
case "C.schar", "C.short", "C.int", "C.long", "C.longlong": case "_Cgo_schar", "_Cgo_short", "_Cgo_int", "_Cgo_long", "_Cgo_longlong":
switch typeSize { switch typeSize {
case 1: case 1:
goName = "int8" goName = "int8"
@@ -937,7 +937,7 @@ func (p *cgoPackage) getIntegerType(name string, cursor clangCursor) *ast.TypeSp
case 8: case 8:
goName = "int64" goName = "int64"
} }
case "C.uchar", "C.ushort", "C.uint", "C.ulong", "C.ulonglong": case "_Cgo_uchar", "_Cgo_ushort", "_Cgo_uint", "_Cgo_ulong", "_Cgo_ulonglong":
switch typeSize { switch typeSize {
case 1: case 1:
goName = "uint8" goName = "uint8"
+31 -31
View File
@@ -5,50 +5,50 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
+38 -38
View File
@@ -5,58 +5,58 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
const C.foo = 3 const _Cgo_foo = 3
const C.bar = C.foo const _Cgo_bar = _Cgo_foo
const C.unreferenced = 4 const _Cgo_unreferenced = 4
const C.referenced = C.unreferenced const _Cgo_referenced = _Cgo_unreferenced
const C.fnlike_val = 5 const _Cgo_fnlike_val = 5
const C.square_val = (20 * 20) const _Cgo_square_val = (20 * 20)
const C.add_val = (3 + 5) const _Cgo_add_val = (3 + 5)
+46 -46
View File
@@ -14,16 +14,16 @@
// testdata/errors.go:3:1: function "unusedFunction" in #cgo noescape line is not used // testdata/errors.go:3:1: function "unusedFunction" in #cgo noescape line is not used
// Type checking errors after CGo processing: // Type checking errors after CGo processing:
// testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as C.char value in variable declaration (overflows) // testdata/errors.go:102: cannot use 2 << 10 (untyped int constant 2048) as _Cgo_char value in variable declaration (overflows)
// testdata/errors.go:105: unknown field z in struct literal // testdata/errors.go:105: unknown field z in struct literal
// testdata/errors.go:108: undefined: C.SOME_CONST_1 // testdata/errors.go:108: undefined: _Cgo_SOME_CONST_1
// testdata/errors.go:110: cannot use C.SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows) // testdata/errors.go:110: cannot use _Cgo_SOME_CONST_3 (untyped int constant 1234) as byte value in variable declaration (overflows)
// testdata/errors.go:112: undefined: C.SOME_CONST_4 // testdata/errors.go:112: undefined: _Cgo_SOME_CONST_4
// testdata/errors.go:114: undefined: C.SOME_CONST_b // testdata/errors.go:114: undefined: _Cgo_SOME_CONST_b
// testdata/errors.go:116: undefined: C.SOME_CONST_startspace // testdata/errors.go:116: undefined: _Cgo_SOME_CONST_startspace
// testdata/errors.go:119: undefined: C.SOME_PARAM_CONST_invalid // testdata/errors.go:119: undefined: _Cgo_SOME_PARAM_CONST_invalid
// testdata/errors.go:122: undefined: C.add_toomuch // testdata/errors.go:122: undefined: _Cgo_add_toomuch
// testdata/errors.go:123: undefined: C.add_toolittle // testdata/errors.go:123: undefined: _Cgo_add_toolittle
package main package main
@@ -32,58 +32,58 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
type C.struct_point_t struct { type _Cgo_struct_point_t struct {
x C.int x _Cgo_int
y C.int y _Cgo_int
} }
type C.point_t = C.struct_point_t type _Cgo_point_t = _Cgo_struct_point_t
const C.SOME_CONST_3 = 1234 const _Cgo_SOME_CONST_3 = 1234
const C.SOME_PARAM_CONST_valid = 3 + 4 const _Cgo_SOME_PARAM_CONST_valid = 3 + 4
+33 -33
View File
@@ -10,53 +10,53 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
const C.BAR = 3 const _Cgo_BAR = 3
const C.FOO_H = 1 const _Cgo_FOO_H = 1
+42 -42
View File
@@ -5,80 +5,80 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
//export foo //export foo
func C.foo(a C.int, b C.int) C.int func _Cgo_foo(a _Cgo_int, b _Cgo_int) _Cgo_int
var C.foo$funcaddr unsafe.Pointer var _Cgo_foo$funcaddr unsafe.Pointer
//export variadic0 //export variadic0
//go:variadic //go:variadic
func C.variadic0() func _Cgo_variadic0()
var C.variadic0$funcaddr unsafe.Pointer var _Cgo_variadic0$funcaddr unsafe.Pointer
//export variadic2 //export variadic2
//go:variadic //go:variadic
func C.variadic2(x C.int, y C.int) func _Cgo_variadic2(x _Cgo_int, y _Cgo_int)
var C.variadic2$funcaddr unsafe.Pointer var _Cgo_variadic2$funcaddr unsafe.Pointer
//export _Cgo_static_173c95a79b6df1980521_staticfunc //export _Cgo_static_173c95a79b6df1980521_staticfunc
func C.staticfunc!symbols.go(x C.int) func _Cgo_staticfunc!symbols.go(x _Cgo_int)
var C.staticfunc!symbols.go$funcaddr unsafe.Pointer var _Cgo_staticfunc!symbols.go$funcaddr unsafe.Pointer
//export notEscapingFunction //export notEscapingFunction
//go:noescape //go:noescape
func C.notEscapingFunction(a *C.int) func _Cgo_notEscapingFunction(a *_Cgo_int)
var C.notEscapingFunction$funcaddr unsafe.Pointer var _Cgo_notEscapingFunction$funcaddr unsafe.Pointer
//go:extern someValue //go:extern someValue
var C.someValue C.int var _Cgo_someValue _Cgo_int
+103 -99
View File
@@ -5,158 +5,162 @@ import "unsafe"
var _ unsafe.Pointer var _ unsafe.Pointer
//go:linkname C.CString runtime.cgo_CString //go:linkname _Cgo_CString runtime.cgo_CString
func C.CString(string) *C.char func _Cgo_CString(string) *_Cgo_char
//go:linkname C.GoString runtime.cgo_GoString //go:linkname _Cgo_GoString runtime.cgo_GoString
func C.GoString(*C.char) string func _Cgo_GoString(*_Cgo_char) string
//go:linkname C.__GoStringN runtime.cgo_GoStringN //go:linkname _Cgo___GoStringN runtime.cgo_GoStringN
func C.__GoStringN(*C.char, uintptr) string func _Cgo___GoStringN(*_Cgo_char, uintptr) string
func C.GoStringN(cstr *C.char, length C.int) string { func _Cgo_GoStringN(cstr *_Cgo_char, length _Cgo_int) string {
return C.__GoStringN(cstr, uintptr(length)) return _Cgo___GoStringN(cstr, uintptr(length))
} }
//go:linkname C.__GoBytes runtime.cgo_GoBytes //go:linkname _Cgo___GoBytes runtime.cgo_GoBytes
func C.__GoBytes(unsafe.Pointer, uintptr) []byte func _Cgo___GoBytes(unsafe.Pointer, uintptr) []byte
func C.GoBytes(ptr unsafe.Pointer, length C.int) []byte { func _Cgo_GoBytes(ptr unsafe.Pointer, length _Cgo_int) []byte {
return C.__GoBytes(ptr, uintptr(length)) return _Cgo___GoBytes(ptr, uintptr(length))
} }
//go:linkname C.__CBytes runtime.cgo_CBytes //go:linkname _Cgo___CBytes runtime.cgo_CBytes
func C.__CBytes([]byte) unsafe.Pointer func _Cgo___CBytes([]byte) unsafe.Pointer
func C.CBytes(b []byte) unsafe.Pointer { func _Cgo_CBytes(b []byte) unsafe.Pointer {
return C.__CBytes(b) return _Cgo___CBytes(b)
} }
//go:linkname C.__get_errno_num runtime.cgo_errno //go:linkname _Cgo___get_errno_num runtime.cgo_errno
func C.__get_errno_num() uintptr func _Cgo___get_errno_num() uintptr
func C.__get_errno() error { func _Cgo___get_errno() error {
return syscall.Errno(C.__get_errno_num()) return syscall.Errno(_Cgo___get_errno_num())
} }
type ( type (
C.char uint8 _Cgo_char uint8
C.schar int8 _Cgo_schar int8
C.uchar uint8 _Cgo_uchar uint8
C.short int16 _Cgo_short int16
C.ushort uint16 _Cgo_ushort uint16
C.int int32 _Cgo_int int32
C.uint uint32 _Cgo_uint uint32
C.long int32 _Cgo_long int32
C.ulong uint32 _Cgo_ulong uint32
C.longlong int64 _Cgo_longlong int64
C.ulonglong uint64 _Cgo_ulonglong uint64
) )
type C.myint = C.int type _Cgo_myint = _Cgo_int
type C.struct_point2d_t struct { type _Cgo_struct_point2d_t struct {
x C.int x _Cgo_int
y C.int y _Cgo_int
} }
type C.point2d_t = C.struct_point2d_t type _Cgo_point2d_t = _Cgo_struct_point2d_t
type C.struct_point3d struct { type _Cgo_struct_point3d struct {
x C.int x _Cgo_int
y C.int y _Cgo_int
z C.int z _Cgo_int
} }
type C.point3d_t = C.struct_point3d type _Cgo_point3d_t = _Cgo_struct_point3d
type C.struct_type1 struct { type _Cgo_struct_type1 struct {
_type C.int _type _Cgo_int
__type C.int __type _Cgo_int
___type C.int ___type _Cgo_int
} }
type C.struct_type2 struct{ _type C.int } type _Cgo_struct_type2 struct{ _type _Cgo_int }
type C.union_union1_t struct{ i C.int } type _Cgo_union_union1_t struct{ i _Cgo_int }
type C.union1_t = C.union_union1_t type _Cgo_union1_t = _Cgo_union_union1_t
type C.union_union3_t struct{ $union uint64 } type _Cgo_union_union3_t struct{ $union uint64 }
func (union *C.union_union3_t) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } func (union *_Cgo_union_union3_t) unionfield_i() *_Cgo_int {
func (union *C.union_union3_t) unionfield_d() *float64 { return (*_Cgo_int)(unsafe.Pointer(&union.$union))
}
func (union *_Cgo_union_union3_t) unionfield_d() *float64 {
return (*float64)(unsafe.Pointer(&union.$union)) return (*float64)(unsafe.Pointer(&union.$union))
} }
func (union *C.union_union3_t) unionfield_s() *C.short { func (union *_Cgo_union_union3_t) unionfield_s() *_Cgo_short {
return (*C.short)(unsafe.Pointer(&union.$union)) return (*_Cgo_short)(unsafe.Pointer(&union.$union))
} }
type C.union3_t = C.union_union3_t type _Cgo_union3_t = _Cgo_union_union3_t
type C.union_union2d struct{ $union [2]uint64 } type _Cgo_union_union2d struct{ $union [2]uint64 }
func (union *C.union_union2d) unionfield_i() *C.int { return (*C.int)(unsafe.Pointer(&union.$union)) } func (union *_Cgo_union_union2d) unionfield_i() *_Cgo_int {
func (union *C.union_union2d) unionfield_d() *[2]float64 { return (*_Cgo_int)(unsafe.Pointer(&union.$union))
}
func (union *_Cgo_union_union2d) unionfield_d() *[2]float64 {
return (*[2]float64)(unsafe.Pointer(&union.$union)) return (*[2]float64)(unsafe.Pointer(&union.$union))
} }
type C.union2d_t = C.union_union2d type _Cgo_union2d_t = _Cgo_union_union2d
type C.union_unionarray_t struct{ arr [10]C.uchar } type _Cgo_union_unionarray_t struct{ arr [10]_Cgo_uchar }
type C.unionarray_t = C.union_unionarray_t type _Cgo_unionarray_t = _Cgo_union_unionarray_t
type C._Ctype_union___0 struct{ $union [3]uint32 } type _Cgo__Ctype_union___0 struct{ $union [3]uint32 }
func (union *C._Ctype_union___0) unionfield_area() *C.point2d_t { func (union *_Cgo__Ctype_union___0) unionfield_area() *_Cgo_point2d_t {
return (*C.point2d_t)(unsafe.Pointer(&union.$union)) return (*_Cgo_point2d_t)(unsafe.Pointer(&union.$union))
} }
func (union *C._Ctype_union___0) unionfield_solid() *C.point3d_t { func (union *_Cgo__Ctype_union___0) unionfield_solid() *_Cgo_point3d_t {
return (*C.point3d_t)(unsafe.Pointer(&union.$union)) return (*_Cgo_point3d_t)(unsafe.Pointer(&union.$union))
} }
type C.struct_struct_nested_t struct { type _Cgo_struct_struct_nested_t struct {
begin C.point2d_t begin _Cgo_point2d_t
end C.point2d_t end _Cgo_point2d_t
tag C.int tag _Cgo_int
coord C._Ctype_union___0 coord _Cgo__Ctype_union___0
} }
type C.struct_nested_t = C.struct_struct_nested_t type _Cgo_struct_nested_t = _Cgo_struct_struct_nested_t
type C.union_union_nested_t struct{ $union [2]uint64 } type _Cgo_union_union_nested_t struct{ $union [2]uint64 }
func (union *C.union_union_nested_t) unionfield_point() *C.point3d_t { func (union *_Cgo_union_union_nested_t) unionfield_point() *_Cgo_point3d_t {
return (*C.point3d_t)(unsafe.Pointer(&union.$union)) return (*_Cgo_point3d_t)(unsafe.Pointer(&union.$union))
} }
func (union *C.union_union_nested_t) unionfield_array() *C.unionarray_t { func (union *_Cgo_union_union_nested_t) unionfield_array() *_Cgo_unionarray_t {
return (*C.unionarray_t)(unsafe.Pointer(&union.$union)) return (*_Cgo_unionarray_t)(unsafe.Pointer(&union.$union))
} }
func (union *C.union_union_nested_t) unionfield_thing() *C.union3_t { func (union *_Cgo_union_union_nested_t) unionfield_thing() *_Cgo_union3_t {
return (*C.union3_t)(unsafe.Pointer(&union.$union)) return (*_Cgo_union3_t)(unsafe.Pointer(&union.$union))
} }
type C.union_nested_t = C.union_union_nested_t type _Cgo_union_nested_t = _Cgo_union_union_nested_t
type C.enum_option = C.int type _Cgo_enum_option = _Cgo_int
type C.option_t = C.enum_option type _Cgo_option_t = _Cgo_enum_option
type C.enum_option2_t = C.uint type _Cgo_enum_option2_t = _Cgo_uint
type C.option2_t = C.enum_option2_t type _Cgo_option2_t = _Cgo_enum_option2_t
type C.struct_types_t struct { type _Cgo_struct_types_t struct {
f float32 f float32
d float64 d float64
ptr *C.int ptr *_Cgo_int
} }
type C.types_t = C.struct_types_t type _Cgo_types_t = _Cgo_struct_types_t
type C.myIntArray = [10]C.int type _Cgo_myIntArray = [10]_Cgo_int
type C.struct_bitfield_t struct { type _Cgo_struct_bitfield_t struct {
start C.uchar start _Cgo_uchar
__bitfield_1 C.uchar __bitfield_1 _Cgo_uchar
d C.uchar d _Cgo_uchar
e C.uchar e _Cgo_uchar
} }
func (s *C.struct_bitfield_t) bitfield_a() C.uchar { return s.__bitfield_1 & 0x1f } func (s *_Cgo_struct_bitfield_t) bitfield_a() _Cgo_uchar { return s.__bitfield_1 & 0x1f }
func (s *C.struct_bitfield_t) set_bitfield_a(value C.uchar) { func (s *_Cgo_struct_bitfield_t) set_bitfield_a(value _Cgo_uchar) {
s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0 s.__bitfield_1 = s.__bitfield_1&^0x1f | value&0x1f<<0
} }
func (s *C.struct_bitfield_t) bitfield_b() C.uchar { func (s *_Cgo_struct_bitfield_t) bitfield_b() _Cgo_uchar {
return s.__bitfield_1 >> 5 & 0x1 return s.__bitfield_1 >> 5 & 0x1
} }
func (s *C.struct_bitfield_t) set_bitfield_b(value C.uchar) { func (s *_Cgo_struct_bitfield_t) set_bitfield_b(value _Cgo_uchar) {
s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5 s.__bitfield_1 = s.__bitfield_1&^0x20 | value&0x1<<5
} }
func (s *C.struct_bitfield_t) bitfield_c() C.uchar { func (s *_Cgo_struct_bitfield_t) bitfield_c() _Cgo_uchar {
return s.__bitfield_1 >> 6 return s.__bitfield_1 >> 6
} }
func (s *C.struct_bitfield_t) set_bitfield_c(value C.uchar, func (s *_Cgo_struct_bitfield_t) set_bitfield_c(value _Cgo_uchar,
) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 } ) { s.__bitfield_1 = s.__bitfield_1&0x3f | value<<6 }
type C.bitfield_t = C.struct_bitfield_t type _Cgo_bitfield_t = _Cgo_struct_bitfield_t
+2 -3
View File
@@ -432,9 +432,8 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) {
// pass for C variadic functions. This includes both explicit // pass for C variadic functions. This includes both explicit
// (with ...) and implicit (no parameters in signature) // (with ...) and implicit (no parameters in signature)
// functions. // functions.
if strings.HasPrefix(f.Name(), "C.") { if strings.HasPrefix(f.Name(), "_Cgo_") {
// This prefix cannot naturally be created, it must have // This prefix was created as a result of CGo preprocessing.
// been created as a result of CGo preprocessing.
info.variadic = true info.variadic = true
} }
} }