summaryrefslogtreecommitdiff
path: root/src/cmd/fix
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2018-01-17 10:38:10 -0800
committerKeith Randall <khr@golang.org>2018-01-17 20:35:43 +0000
commitbd89333426954e24167a9b78f1dd8b0483a560f8 (patch)
tree0b3df0219e254c5cb06f89fcfed1fc699599dbdb /src/cmd/fix
parent18d527b3f09521a21e4068917f9b4513fcfcc2ef (diff)
downloadgo-git-bd89333426954e24167a9b78f1dd8b0483a560f8.tar.gz
cmd/fix: don't depend on *GetTypeID functions being present
cgo uses the presence of these functions to determine whether a given type is in the CFTypeRef hierarchy and thus should be a uintptr instead of a pointer. But if the *GetTypeID functions aren't used by the user code, then they won't be present in the cgo output, and thus cmd/fix won't see them. Use the simpler rule that anything ending in *Ref should be rewritten. This could over-rewrite, but I don't see a simpler solution. Unlike cgo, it is easy to edit the output to fix any issues. And fix is a much rarer operation than cgo. This is a revert of portions of CL 87616. Update #23091 Change-Id: I74ecd9fb25490a3d279b372e107248452bb62185 Reviewed-on: https://go-review.googlesource.com/88075 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/fix')
-rw-r--r--src/cmd/fix/cftype.go10
-rw-r--r--src/cmd/fix/jnitype.go3
-rw-r--r--src/cmd/fix/typecheck.go1
3 files changed, 6 insertions, 8 deletions
diff --git a/src/cmd/fix/cftype.go b/src/cmd/fix/cftype.go
index 5e742a4fdf..3341348272 100644
--- a/src/cmd/fix/cftype.go
+++ b/src/cmd/fix/cftype.go
@@ -30,19 +30,17 @@ var cftypeFix = fix{
// 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 {
- var tc TypeConfig
- return typefix(f, &tc, func(s string) bool {
- return strings.HasPrefix(s, "C.") && strings.HasSuffix(s, "Ref") &&
- (s == "C.CFTypeRef" || tc.External[s[:len(s)-3]+"GetTypeID"] == "func() C.CFTypeID")
+ return typefix(f, func(s string) bool {
+ return strings.HasPrefix(s, "C.") && strings.HasSuffix(s, "Ref") && s != "C.CFAllocatorRef"
})
}
// typefix replaces nil with 0 for all nils whose type, when passed to badType, returns true.
-func typefix(f *ast.File, tc *TypeConfig, badType func(string) bool) bool {
+func typefix(f *ast.File, badType func(string) bool) bool {
if !imports(f, "C") {
return false
}
- typeof, _ := typecheck(tc, f)
+ typeof, _ := typecheck(&TypeConfig{}, f)
// step 1: Find all the nils with the offending types.
// Compute their replacement.
diff --git a/src/cmd/fix/jnitype.go b/src/cmd/fix/jnitype.go
index 75ae570c4d..29abe0f007 100644
--- a/src/cmd/fix/jnitype.go
+++ b/src/cmd/fix/jnitype.go
@@ -27,8 +27,7 @@ var jniFix = fix{
// and similar for subtypes of jobject.
// This fix finds nils initializing these types and replaces the nils with 0s.
func jnifix(f *ast.File) bool {
- var tc TypeConfig
- return typefix(f, &tc, func(s string) bool {
+ return typefix(f, func(s string) bool {
switch s {
case "C.jobject":
return true
diff --git a/src/cmd/fix/typecheck.go b/src/cmd/fix/typecheck.go
index a52a54202d..c5900d8dcd 100644
--- a/src/cmd/fix/typecheck.go
+++ b/src/cmd/fix/typecheck.go
@@ -152,6 +152,7 @@ func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, ass
// If we import "C", add types of cgo objects.
cfg.External = map[string]string{}
+ cfg1.External = cfg.External
if imports(f, "C") {
// Run cgo on gofmtFile(f)
// Parse, extract decls from _cgo_gotypes.go