diff options
author | Keith Randall <khr@google.com> | 2018-07-10 13:47:15 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2018-07-12 19:15:12 +0000 |
commit | b888a6227fa56f4698f9e5ca74e8bee10830bebe (patch) | |
tree | 911138515501b47890e870033ad5d79b8f61e5c3 /misc | |
parent | 85cfa4d55e177a70913ce8977ce847af7c4298e2 (diff) | |
download | go-git-b888a6227fa56f4698f9e5ca74e8bee10830bebe.tar.gz |
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 <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/issue24161_darwin_test.go | 12 | ||||
-rw-r--r-- | misc/cgo/test/issue24161e0/main.go | 22 | ||||
-rw-r--r-- | misc/cgo/test/issue24161e1/main.go | 31 | ||||
-rw-r--r-- | misc/cgo/test/issue24161e2/main.go | 33 |
4 files changed, 98 insertions, 0 deletions
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 <CoreFoundation/CoreFoundation.h> +#include <Security/Security.h> +*/ +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 <CoreFoundation/CoreFoundation.h> +#include <Security/Security.h> +*/ +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 <CoreFoundation/CoreFoundation.h> +#include <Security/Security.h> +*/ +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) {} |