From b888a6227fa56f4698f9e5ca74e8bee10830bebe Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 10 Jul 2018 13:47:15 -0700 Subject: cmd/cgo: fix cgo bad typedefs Two fixes: 1) Typedefs of the bad typedefs should also not be rewritten to the underlying type. They shouldn't just be uintptr, though, they should retain the C naming structure. For example, in C: typedef const __CFString * CFStringRef; typedef CFStringRef SecKeyAlgorithm; we want the Go: type _Ctype_CFStringRef uintptr type _Ctype_SecKeyAlgorithm = _Ctype_CFStringRef 2) We need more types than just function arguments/return values. At least we need types of global variables, so when we see a reference to: extern const SecKeyAlgorithm kSecKeyAlgorithmECDSASignatureDigestX962SHA1; we know that we need to investigate the type SecKeyAlgorithm. Might as well just find every typedef and check the badness of all of them. This requires looping until a fixed point of known types is reached. Usually it takes just 2 iterations, sometimes 3. Fixes #24161 Change-Id: I32ca7e48eb4d4133c6242e91d1879636f5224ea9 Reviewed-on: https://go-review.googlesource.com/123177 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- misc/cgo/test/issue24161_darwin_test.go | 12 ++++++++++++ misc/cgo/test/issue24161e0/main.go | 22 ++++++++++++++++++++++ misc/cgo/test/issue24161e1/main.go | 31 +++++++++++++++++++++++++++++++ misc/cgo/test/issue24161e2/main.go | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 misc/cgo/test/issue24161e0/main.go create mode 100644 misc/cgo/test/issue24161e1/main.go create mode 100644 misc/cgo/test/issue24161e2/main.go (limited to 'misc') diff --git a/misc/cgo/test/issue24161_darwin_test.go b/misc/cgo/test/issue24161_darwin_test.go index cb15b3c5a0..10fdfbd1bc 100644 --- a/misc/cgo/test/issue24161_darwin_test.go +++ b/misc/cgo/test/issue24161_darwin_test.go @@ -8,6 +8,9 @@ import ( "testing" "./issue24161arg" + "./issue24161e0" + "./issue24161e1" + "./issue24161e2" "./issue24161res" ) @@ -17,3 +20,12 @@ func Test24161Arg(t *testing.T) { func Test24161Res(t *testing.T) { issue24161res.Test(t) } +func Test24161Example0(t *testing.T) { + issue24161e0.Test(t) +} +func Test24161Example1(t *testing.T) { + issue24161e1.Test(t) +} +func Test24161Example2(t *testing.T) { + issue24161e2.Test(t) +} diff --git a/misc/cgo/test/issue24161e0/main.go b/misc/cgo/test/issue24161e0/main.go new file mode 100644 index 0000000000..ec5bea9662 --- /dev/null +++ b/misc/cgo/test/issue24161e0/main.go @@ -0,0 +1,22 @@ +// 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 issue24161e0 + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework CoreFoundation -framework Security +#include +#include +*/ +import "C" +import "testing" + +func f1() { + C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil) +} + +func Test(t *testing.T) {} diff --git a/misc/cgo/test/issue24161e1/main.go b/misc/cgo/test/issue24161e1/main.go new file mode 100644 index 0000000000..aea0ff50c5 --- /dev/null +++ b/misc/cgo/test/issue24161e1/main.go @@ -0,0 +1,31 @@ +// 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 issue24161e1 + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework CoreFoundation -framework Security +#include +#include +*/ +import "C" +import ( + "fmt" + "testing" +) + +func f1() { + C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil) +} + +func f2(e C.CFErrorRef) { + if desc := C.CFErrorCopyDescription(e); desc != 0 { + fmt.Println(desc) + } +} + +func Test(t *testing.T) {} diff --git a/misc/cgo/test/issue24161e2/main.go b/misc/cgo/test/issue24161e2/main.go new file mode 100644 index 0000000000..c6675a7689 --- /dev/null +++ b/misc/cgo/test/issue24161e2/main.go @@ -0,0 +1,33 @@ +// 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 issue24161e2 + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework CoreFoundation -framework Security +#include +#include +*/ +import "C" +import ( + "fmt" + "testing" +) + +var _ C.CFStringRef + +func f1() { + C.SecKeyCreateSignature(0, C.kSecKeyAlgorithmECDSASignatureDigestX962SHA1, 0, nil) +} + +func f2(e C.CFErrorRef) { + if desc := C.CFErrorCopyDescription(e); desc != 0 { + fmt.Println(desc) + } +} + +func Test(t *testing.T) {} -- cgit v1.2.1