]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/fix: don't depend on *GetTypeID functions being present
authorKeith Randall <khr@golang.org>
Wed, 17 Jan 2018 18:38:10 +0000 (10:38 -0800)
committerKeith Randall <khr@golang.org>
Wed, 17 Jan 2018 20:35:43 +0000 (20:35 +0000)
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>
src/cmd/fix/cftype.go
src/cmd/fix/jnitype.go
src/cmd/fix/typecheck.go

index 5e742a4fdf779df9738d58ab96171fa2a956fa79..33413482727d714437db3e3b856f898fbeceb6f1 100644 (file)
@@ -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.
index 75ae570c4da418db072483895dddc642ff4f4afa..29abe0f007830221ec10af316532f8ccfd35ff75 100644 (file)
@@ -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
index a52a54202d1212ddef9bc3ea2c12a2d6a58848c3..c5900d8dcd1d16a6436f229d7f2ba34423fd6bbd 100644 (file)
@@ -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