@@ -132,12 +132,11 @@ func (p *Package) addToFlag(flag string, args []string) {
132
132
//
133
133
// For example, the following string:
134
134
//
135
- // `a b:"c d" 'e''f' "g\""`
135
+ // `a b:"c d" 'e''f' "g\""`
136
136
//
137
137
// Would be parsed as:
138
138
//
139
- // []string{"a", "b:c d", "ef", `g"`}
140
- //
139
+ // []string{"a", "b:c d", "ef", `g"`}
141
140
func splitQuoted (s string ) (r []string , err error ) {
142
141
var args []string
143
142
arg := make ([]rune , len (s ))
@@ -1156,13 +1155,19 @@ func (p *Package) mangle(f *File, arg *ast.Expr, addPosition bool) (ast.Expr, bo
1156
1155
1157
1156
// checkIndex checks whether arg has the form &a[i], possibly inside
1158
1157
// type conversions. If so, then in the general case it writes
1159
- // _cgoIndexNN := a
1160
- // _cgoNN := &cgoIndexNN[i] // with type conversions, if any
1158
+ //
1159
+ // _cgoIndexNN := a
1160
+ // _cgoNN := &cgoIndexNN[i] // with type conversions, if any
1161
+ //
1161
1162
// to sb, and writes
1162
- // _cgoCheckPointer(_cgoNN, _cgoIndexNN)
1163
+ //
1164
+ // _cgoCheckPointer(_cgoNN, _cgoIndexNN)
1165
+ //
1163
1166
// to sbCheck, and returns true. If a is a simple variable or field reference,
1164
1167
// it writes
1165
- // _cgoIndexNN := &a
1168
+ //
1169
+ // _cgoIndexNN := &a
1170
+ //
1166
1171
// and dereferences the uses of _cgoIndexNN. Taking the address avoids
1167
1172
// making a copy of an array.
1168
1173
//
@@ -1210,10 +1215,14 @@ func (p *Package) checkIndex(sb, sbCheck *bytes.Buffer, arg ast.Expr, i int) boo
1210
1215
1211
1216
// checkAddr checks whether arg has the form &x, possibly inside type
1212
1217
// conversions. If so, it writes
1213
- // _cgoBaseNN := &x
1214
- // _cgoNN := _cgoBaseNN // with type conversions, if any
1218
+ //
1219
+ // _cgoBaseNN := &x
1220
+ // _cgoNN := _cgoBaseNN // with type conversions, if any
1221
+ //
1215
1222
// to sb, and writes
1216
- // _cgoCheckPointer(_cgoBaseNN, true)
1223
+ //
1224
+ // _cgoCheckPointer(_cgoBaseNN, true)
1225
+ //
1217
1226
// to sbCheck, and returns true. This tells _cgoCheckPointer to check
1218
1227
// just the contents of the pointer being passed, not any other part
1219
1228
// of the memory allocation. This is run after checkIndex, which looks
@@ -2131,8 +2140,8 @@ type typeConv struct {
2131
2140
// Type names X for which there exists an XGetTypeID function with type func() CFTypeID.
2132
2141
getTypeIDs map [string ]bool
2133
2142
2134
- // badStructs contains C structs that should be marked NotInHeap .
2135
- notInHeapStructs map [string ]bool
2143
+ // incompleteStructs contains C structs that should be marked Incomplete .
2144
+ incompleteStructs map [string ]bool
2136
2145
2137
2146
// Predeclared types.
2138
2147
bool ast.Expr
@@ -2145,7 +2154,6 @@ type typeConv struct {
2145
2154
string ast.Expr
2146
2155
goVoid ast.Expr // _Ctype_void, denotes C's void
2147
2156
goVoidPtr ast.Expr // unsafe.Pointer or *byte
2148
- goVoidPtrNoHeap ast.Expr // *_Ctype_void_notinheap, like goVoidPtr but marked NotInHeap
2149
2157
2150
2158
ptrSize int64
2151
2159
intSize int64
@@ -2169,7 +2177,7 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
2169
2177
c .m = make (map [string ]* Type )
2170
2178
c .ptrs = make (map [string ][]* Type )
2171
2179
c .getTypeIDs = make (map [string ]bool )
2172
- c .notInHeapStructs = make (map [string ]bool )
2180
+ c .incompleteStructs = make (map [string ]bool )
2173
2181
c .bool = c .Ident ("bool" )
2174
2182
c .byte = c .Ident ("byte" )
2175
2183
c .int8 = c .Ident ("int8" )
@@ -2188,7 +2196,6 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
2188
2196
c .void = c .Ident ("void" )
2189
2197
c .string = c .Ident ("string" )
2190
2198
c .goVoid = c .Ident ("_Ctype_void" )
2191
- c .goVoidPtrNoHeap = c .Ident ("*_Ctype_void_notinheap" )
2192
2199
2193
2200
// Normally cgo translates void* to unsafe.Pointer,
2194
2201
// but for historical reasons -godefs uses *byte instead.
@@ -2531,19 +2538,13 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
2531
2538
// other than try to determine a Go representation.
2532
2539
tt := * t
2533
2540
tt .C = & TypeRepr {"%s %s" , []interface {}{dt .Kind , tag }}
2534
- tt .Go = c .Ident ("struct{}" )
2535
- if dt .Kind == "struct" {
2536
- // We don't know what the representation of this struct is, so don't let
2537
- // anyone allocate one on the Go side. As a side effect of this annotation,
2538
- // pointers to this type will not be considered pointers in Go. They won't
2539
- // get writebarrier-ed or adjusted during a stack copy. This should handle
2540
- // all the cases badPointerTypedef used to handle, but hopefully will
2541
- // continue to work going forward without any more need for cgo changes.
2542
- tt .NotInHeap = true
2543
- // TODO: we should probably do the same for unions. Unions can't live
2544
- // on the Go heap, right? It currently doesn't work for unions because
2545
- // they are defined as a type alias for struct{}, not a defined type.
2546
- }
2541
+ // We don't know what the representation of this struct is, so don't let
2542
+ // anyone allocate one on the Go side. As a side effect of this annotation,
2543
+ // pointers to this type will not be considered pointers in Go. They won't
2544
+ // get writebarrier-ed or adjusted during a stack copy. This should handle
2545
+ // all the cases badPointerTypedef used to handle, but hopefully will
2546
+ // continue to work going forward without any more need for cgo changes.
2547
+ tt .Go = c .Ident ("_cgopackage.Incomplete" )
2547
2548
typedef [name .Name ] = & tt
2548
2549
break
2549
2550
}
@@ -2569,7 +2570,9 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
2569
2570
tt .C = & TypeRepr {"struct %s" , []interface {}{tag }}
2570
2571
}
2571
2572
tt .Go = g
2572
- tt .NotInHeap = c .notInHeapStructs [tag ]
2573
+ if c .incompleteStructs [tag ] {
2574
+ tt .Go = c .Ident ("_cgopackage.Incomplete" )
2575
+ }
2573
2576
typedef [name .Name ] = & tt
2574
2577
}
2575
2578
@@ -2614,32 +2617,31 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
2614
2617
}
2615
2618
}
2616
2619
if c .badVoidPointerTypedef (dt ) {
2617
- // Treat this typedef as a pointer to a NotInHeap void .
2620
+ // Treat this typedef as a pointer to a _cgopackage.Incomplete .
2618
2621
s := * sub
2619
- s .Go = c .goVoidPtrNoHeap
2622
+ s .Go = c .Ident ( "*_cgopackage.Incomplete" )
2620
2623
sub = & s
2621
2624
// Make sure we update any previously computed type.
2622
2625
if oldType := typedef [name .Name ]; oldType != nil {
2623
2626
oldType .Go = sub .Go
2624
2627
}
2625
2628
}
2626
2629
// Check for non-pointer "struct <tag>{...}; typedef struct <tag> *<name>"
2627
- // typedefs that should be marked NotInHeap .
2630
+ // typedefs that should be marked Incomplete .
2628
2631
if ptr , ok := dt .Type .(* dwarf.PtrType ); ok {
2629
2632
if strct , ok := ptr .Type .(* dwarf.StructType ); ok {
2630
2633
if c .badStructPointerTypedef (dt .Name , strct ) {
2631
- c .notInHeapStructs [strct .StructName ] = true
2634
+ c .incompleteStructs [strct .StructName ] = true
2632
2635
// Make sure we update any previously computed type.
2633
2636
name := "_Ctype_struct_" + strct .StructName
2634
2637
if oldType := typedef [name ]; oldType != nil {
2635
- oldType .NotInHeap = true
2638
+ oldType .Go = c . Ident ( "_cgopackage.Incomplete" )
2636
2639
}
2637
2640
}
2638
2641
}
2639
2642
}
2640
2643
t .Go = name
2641
2644
t .BadPointer = sub .BadPointer
2642
- t .NotInHeap = sub .NotInHeap
2643
2645
if unionWithPointer [sub .Go ] {
2644
2646
unionWithPointer [t .Go ] = true
2645
2647
}
@@ -2650,7 +2652,6 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
2650
2652
tt := * t
2651
2653
tt .Go = sub .Go
2652
2654
tt .BadPointer = sub .BadPointer
2653
- tt .NotInHeap = sub .NotInHeap
2654
2655
typedef [name .Name ] = & tt
2655
2656
}
2656
2657
@@ -3174,7 +3175,7 @@ func (c *typeConv) anonymousStructTypedef(dt *dwarf.TypedefType) bool {
3174
3175
// non-pointers in this type.
3175
3176
// TODO: Currently our best solution is to find these manually and list them as
3176
3177
// they come up. A better solution is desired.
3177
- // Note: DEPRECATED. There is now a better solution. Search for NotInHeap in this file.
3178
+ // Note: DEPRECATED. There is now a better solution. Search for _cgopackage.Incomplete in this file.
3178
3179
func (c * typeConv ) badPointerTypedef (dt * dwarf.TypedefType ) bool {
3179
3180
if c .badCFType (dt ) {
3180
3181
return true
@@ -3188,7 +3189,7 @@ func (c *typeConv) badPointerTypedef(dt *dwarf.TypedefType) bool {
3188
3189
return false
3189
3190
}
3190
3191
3191
- // badVoidPointerTypedef is like badPointerTypeDef, but for "void *" typedefs that should be NotInHeap .
3192
+ // badVoidPointerTypedef is like badPointerTypeDef, but for "void *" typedefs that should be _cgopackage.Incomplete .
3192
3193
func (c * typeConv ) badVoidPointerTypedef (dt * dwarf.TypedefType ) bool {
3193
3194
// Match the Windows HANDLE type (#42018).
3194
3195
if goos != "windows" || dt .Name != "HANDLE" {
0 commit comments