--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+import (
+ "testing"
+
+ "./issue24161arg"
+ "./issue24161res"
+)
+
+func Test24161Arg(t *testing.T) {
+ issue24161arg.Test(t)
+}
+func Test24161Res(t *testing.T) {
+ issue24161res.Test(t)
+}
--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161arg
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+
+func test24161array() C.CFArrayRef {
+ return C.CFArrayCreate(0, nil, 0, nil)
+}
--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161arg
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+import "testing"
+
+func Test(t *testing.T) {
+ a := test24161array()
+ C.CFArrayCreateCopy(0, a)
+}
--- /dev/null
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin
+
+package issue24161res
+
+/*
+#cgo LDFLAGS: -framework CoreFoundation
+#include <CoreFoundation/CoreFoundation.h>
+*/
+import "C"
+import (
+ "reflect"
+ "testing"
+)
+
+func Test(t *testing.T) {
+ if k := reflect.TypeOf(C.CFArrayCreate(0, nil, 0, nil)).Kind(); k != reflect.Uintptr {
+ t.Fatalf("bad kind %s\n", k)
+ }
+}
needType := p.guessKinds(f)
if len(needType) > 0 {
p.loadDWARF(f, needType)
+ // If there are typedefs used as arguments, add those
+ // types to the list of types we're interested in, and
+ // try again.
+ if len(p.ArgTypedefs) > 0 {
+ for _, a := range p.ArgTypedefs {
+ f.Name[a] = &Name{
+ Go: a,
+ C: a,
+ }
+ }
+ needType := p.guessKinds(f)
+ if len(needType) > 0 {
+ p.loadDWARF(f, needType)
+ }
+ }
}
if p.rewriteCalls(f) {
// Add `import _cgo_unsafe "unsafe"` after the package statement.
}
conv.FinishType(pos)
}
+ p.ArgTypedefs = conv.argTypedefs
}
// mangleName does name mangling to translate names
ptrSize int64
intSize int64
+
+ // Typedefs used as argument types for C calls.
+ argTypedefs []string
}
var tagGen int
s := *sub
s.Go = c.uintptr
sub = &s
+ // Make sure we update any previously computed type.
+ if oldType := typedef[name.Name]; oldType != nil {
+ oldType.Go = sub.Go
+ }
}
t.Go = name
if unionWithPointer[sub.Go] {
C: tr,
}
case *dwarf.TypedefType:
+ // Keep track of all the typedefs used as arguments.
+ c.argTypedefs = append(c.argTypedefs, dt.Name)
+
// C has much more relaxed rules than Go for
// implicit type conversions. When the parameter
// is type T defined as *X, simulate a little of the
gr = []*ast.Field{{Type: c.goVoid}}
} else if dtype.ReturnType != nil {
r = c.Type(unqual(dtype.ReturnType), pos)
+ if dt, ok := dtype.ReturnType.(*dwarf.TypedefType); ok {
+ c.argTypedefs = append(c.argTypedefs, dt.Name)
+ }
gr = []*ast.Field{{Type: r.Go}}
}
return &FuncType{
GoFiles []string // list of Go files
GccFiles []string // list of gcc output files
Preamble string // collected preamble for _cgo_export.h
+ ArgTypedefs []string // typedefs used as arguments to or results of C functions
}
// A File collects information about a single Go input file.