aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fix
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2018-01-12 10:08:38 -0800
committerKeith Randall <khr@golang.org>2018-01-17 06:38:57 +0000
commitd162a297ed216fb02ebe409ace2387c3a656de66 (patch)
tree22ebd7ad45ee9eb149fcc36c6a686f5cc05ab40f /src/cmd/fix
parent165e7523fb627cc7f6be56b7318fea34d73d7167 (diff)
downloadgo-d162a297ed216fb02ebe409ace2387c3a656de66.tar.gz
go-d162a297ed216fb02ebe409ace2387c3a656de66.zip
cmd/cgo: rewrite CFTypeRef and subytes on Darwin to uintptr
Cgo currently maps CFTypeRef and its subtypes to unsafe.Pointer or a pointer to a named empty struct. However, Darwin sometimes encodes some of CFTypeRef's subtypes as a few int fields packed in a pointer wrapper. This hackery confuses the Go runtime as the pointers can look like they point to things that shouldn't be pointed at. Switch CFTypeRef and its subtypes to map to uintptr. Detecting the affected set of types is tricky, there are over 200 of them, and the set isn't static across Darwin versions. Fortunately, downcasting from CFTypeRef to a subtype requires calling CFGetTypeID, getting a CFTypeID token, and comparing that with a known id from a *GetTypeID() call. So we can find all the type names by detecting all the *GetTypeID() prototypes and rewriting the corresponding *Ref types to uintptr. This strategy covers all the cases I've checked and is unlikely to have a false positive. Update #23091. Change-Id: I487eb4105c9b4785ba564de9c38d472c8c9a76ac Reviewed-on: https://go-review.googlesource.com/87615 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 'src/cmd/fix')
-rw-r--r--src/cmd/fix/cftype.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmd/fix/cftype.go b/src/cmd/fix/cftype.go
index 1f06cd6c33..841bd4dccb 100644
--- a/src/cmd/fix/cftype.go
+++ b/src/cmd/fix/cftype.go
@@ -19,7 +19,7 @@ var cftypeFix = fix{
name: "cftype",
date: "2017-09-27",
f: cftypefix,
- desc: `Fixes initializers of C.CF*Ptr types`,
+ desc: `Fixes initializers of C.*Ref types`,
disabled: false,
}
@@ -27,11 +27,11 @@ var cftypeFix = fix{
// type CFTypeRef unsafe.Pointer
// New state:
// type CFTypeRef uintptr
-// and similar for other CF*Ref types.
+// and similar for other *Ref types.
// This fix finds nils initializing these types and replaces the nils with 0s.
func cftypefix(f *ast.File) bool {
return typefix(f, func(s string) bool {
- return strings.HasPrefix(s, "C.CF") && strings.HasSuffix(s, "Ref")
+ return strings.HasPrefix(s, "C.") && strings.HasSuffix(s, "Ref")
})
}