// 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.
// 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
// 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