mirror of
https://github.com/golang/go
synced 2024-11-23 15:20:03 -07:00
encoding/gob: do not hide an unsafe.Pointer in a uintptr
R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/23320044
This commit is contained in:
parent
48279bd567
commit
77913e9aab
@ -654,21 +654,20 @@ func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) {
|
|||||||
|
|
||||||
// decodeSlice decodes a slice and stores the slice header through p.
|
// decodeSlice decodes a slice and stores the slice header through p.
|
||||||
// Slices are encoded as an unsigned length followed by the elements.
|
// Slices are encoded as an unsigned length followed by the elements.
|
||||||
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl error) {
|
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p unsafe.Pointer, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl error) {
|
||||||
nr := state.decodeUint()
|
nr := state.decodeUint()
|
||||||
n := int(nr)
|
n := int(nr)
|
||||||
if indir > 0 {
|
if indir > 0 {
|
||||||
up := unsafe.Pointer(p)
|
if *(*unsafe.Pointer)(p) == nil {
|
||||||
if *(*unsafe.Pointer)(up) == nil {
|
|
||||||
// Allocate the slice header.
|
// Allocate the slice header.
|
||||||
*(*unsafe.Pointer)(up) = unsafe.Pointer(new([]unsafe.Pointer))
|
*(*unsafe.Pointer)(p) = unsafe.Pointer(new([]unsafe.Pointer))
|
||||||
}
|
}
|
||||||
p = *(*uintptr)(up)
|
p = *(*unsafe.Pointer)(p)
|
||||||
}
|
}
|
||||||
// Allocate storage for the slice elements, that is, the underlying array,
|
// Allocate storage for the slice elements, that is, the underlying array,
|
||||||
// if the existing slice does not have the capacity.
|
// if the existing slice does not have the capacity.
|
||||||
// Always write a header at p.
|
// Always write a header at p.
|
||||||
hdrp := (*reflect.SliceHeader)(unsafe.Pointer(p))
|
hdrp := (*reflect.SliceHeader)(p)
|
||||||
if hdrp.Cap < n {
|
if hdrp.Cap < n {
|
||||||
hdrp.Data = reflect.MakeSlice(atyp, n, n).Pointer()
|
hdrp.Data = reflect.MakeSlice(atyp, n, n).Pointer()
|
||||||
hdrp.Cap = n
|
hdrp.Cap = n
|
||||||
@ -887,7 +886,7 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
|
|||||||
elemOp, elemIndir := dec.decOpFor(elemId, t.Elem(), name, inProgress)
|
elemOp, elemIndir := dec.decOpFor(elemId, t.Elem(), name, inProgress)
|
||||||
ovfl := overflow(name)
|
ovfl := overflow(name)
|
||||||
op = func(i *decInstr, state *decoderState, p unsafe.Pointer) {
|
op = func(i *decInstr, state *decoderState, p unsafe.Pointer) {
|
||||||
state.dec.decodeSlice(t, state, uintptr(p), *elemOp, t.Elem().Size(), i.indir, elemIndir, ovfl)
|
state.dec.decodeSlice(t, state, p, *elemOp, t.Elem().Size(), i.indir, elemIndir, ovfl)
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
|
Loading…
Reference in New Issue
Block a user