mirror of
https://github.com/golang/go
synced 2024-11-19 08:34:39 -07:00
reflect: add kindNoPointers if a function layout has no pointers.
malloc checks kindNoPointers and if it is not set and the object is one pointer in size, it assumes it contains a pointer. So we must set kindNoPointers correctly; it isn't just a hint. Fixes #9425 Change-Id: Ia43da23cc3298d6e3d6dbdf66d32e9678f0aedcf Reviewed-on: https://go-review.googlesource.com/2055 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
7a524a1036
commit
d11f411181
@ -1525,8 +1525,9 @@ func isReflexive(t *rtype) bool {
|
|||||||
|
|
||||||
// gcProg is a helper type for generatation of GC pointer info.
|
// gcProg is a helper type for generatation of GC pointer info.
|
||||||
type gcProg struct {
|
type gcProg struct {
|
||||||
gc []byte
|
gc []byte
|
||||||
size uintptr // size of type in bytes
|
size uintptr // size of type in bytes
|
||||||
|
hasPtr bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *gcProg) append(v byte) {
|
func (gc *gcProg) append(v byte) {
|
||||||
@ -1583,11 +1584,14 @@ func (gc *gcProg) appendWord(v byte) {
|
|||||||
gc.gc[nptr/2] &= ^(3 << ((nptr%2)*4 + 2))
|
gc.gc[nptr/2] &= ^(3 << ((nptr%2)*4 + 2))
|
||||||
gc.gc[nptr/2] |= v << ((nptr%2)*4 + 2)
|
gc.gc[nptr/2] |= v << ((nptr%2)*4 + 2)
|
||||||
gc.size += ptrsize
|
gc.size += ptrsize
|
||||||
|
if v == bitsPointer {
|
||||||
|
gc.hasPtr = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *gcProg) finalize() unsafe.Pointer {
|
func (gc *gcProg) finalize() (unsafe.Pointer, bool) {
|
||||||
if gc.size == 0 {
|
if gc.size == 0 {
|
||||||
return nil
|
return nil, false
|
||||||
}
|
}
|
||||||
ptrsize := unsafe.Sizeof(uintptr(0))
|
ptrsize := unsafe.Sizeof(uintptr(0))
|
||||||
gc.align(ptrsize)
|
gc.align(ptrsize)
|
||||||
@ -1602,7 +1606,7 @@ func (gc *gcProg) finalize() unsafe.Pointer {
|
|||||||
gc.appendWord(extractGCWord(gc.gc, i))
|
gc.appendWord(extractGCWord(gc.gc, i))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unsafe.Pointer(&gc.gc[0])
|
return unsafe.Pointer(&gc.gc[0]), gc.hasPtr
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractGCWord(gc []byte, i uintptr) byte {
|
func extractGCWord(gc []byte, i uintptr) byte {
|
||||||
@ -1662,7 +1666,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
|||||||
|
|
||||||
b := new(rtype)
|
b := new(rtype)
|
||||||
b.size = gc.size
|
b.size = gc.size
|
||||||
b.gc[0] = gc.finalize()
|
b.gc[0], _ = gc.finalize()
|
||||||
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
|
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
|
||||||
b.string = &s
|
b.string = &s
|
||||||
return b
|
return b
|
||||||
@ -1863,7 +1867,11 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin
|
|||||||
// build dummy rtype holding gc program
|
// build dummy rtype holding gc program
|
||||||
x := new(rtype)
|
x := new(rtype)
|
||||||
x.size = gc.size
|
x.size = gc.size
|
||||||
x.gc[0] = gc.finalize()
|
var hasPtr bool
|
||||||
|
x.gc[0], hasPtr = gc.finalize()
|
||||||
|
if !hasPtr {
|
||||||
|
x.kind |= kindNoPointers
|
||||||
|
}
|
||||||
var s string
|
var s string
|
||||||
if rcvr != nil {
|
if rcvr != nil {
|
||||||
s = "methodargs(" + *rcvr.string + ")(" + *t.string + ")"
|
s = "methodargs(" + *rcvr.string + ")(" + *t.string + ")"
|
||||||
|
Loading…
Reference in New Issue
Block a user