mirror of
https://github.com/golang/go
synced 2024-11-19 04:04:47 -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.
|
||||
type gcProg struct {
|
||||
gc []byte
|
||||
size uintptr // size of type in bytes
|
||||
gc []byte
|
||||
size uintptr // size of type in bytes
|
||||
hasPtr bool
|
||||
}
|
||||
|
||||
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] |= v << ((nptr%2)*4 + 2)
|
||||
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 {
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
ptrsize := unsafe.Sizeof(uintptr(0))
|
||||
gc.align(ptrsize)
|
||||
@ -1602,7 +1606,7 @@ func (gc *gcProg) finalize() unsafe.Pointer {
|
||||
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 {
|
||||
@ -1662,7 +1666,7 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
|
||||
|
||||
b := new(rtype)
|
||||
b.size = gc.size
|
||||
b.gc[0] = gc.finalize()
|
||||
b.gc[0], _ = gc.finalize()
|
||||
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
|
||||
b.string = &s
|
||||
return b
|
||||
@ -1863,7 +1867,11 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin
|
||||
// build dummy rtype holding gc program
|
||||
x := new(rtype)
|
||||
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
|
||||
if rcvr != nil {
|
||||
s = "methodargs(" + *rcvr.string + ")(" + *t.string + ")"
|
||||
|
Loading…
Reference in New Issue
Block a user