mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: use go:notinheap for anonymous structs
They can't reasonably be allocated on the heap. Not a huge deal, but it has an interesting and useful side effect. After CL 249917, the compiler and runtime treat pointers to go:notinheap types as uintptrs instead of real pointers (no write barrier, not processed during stack scanning, ...). That feature is exactly what we want for cgo to fix #40954. All the cases we have of pointers declared in C, but which might actually be filled with non-pointer data, are of this form (JNI's jobject heirarch, Darwin's CFType heirarchy, ...). Fixes #40954 Change-Id: I44a3b9bc2513d4287107e39d0cbbd0efd46a3aae Reviewed-on: https://go-review.googlesource.com/c/go/+/250940 Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
4f915911e8
commit
42b023d7b9
4 changed files with 55 additions and 1 deletions
|
|
@ -108,6 +108,9 @@ func (p *Package) writeDefs() {
|
|||
sort.Strings(typedefNames)
|
||||
for _, name := range typedefNames {
|
||||
def := typedef[name]
|
||||
if def.NotInHeap {
|
||||
fmt.Fprintf(fgo2, "//go:notinheap\n")
|
||||
}
|
||||
fmt.Fprintf(fgo2, "type %s ", name)
|
||||
// We don't have source info for these types, so write them out without source info.
|
||||
// Otherwise types would look like:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue