Fix checkptr error

This commit is contained in:
Masaaki Goshima 2021-04-30 23:49:04 +09:00
parent e647dafb41
commit 6444a1b057
1 changed files with 18 additions and 26 deletions

View File

@ -121,18 +121,17 @@ func (d *sliceDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) er
ep := unsafe.Pointer(uintptr(data) + uintptr(idx)*d.size) ep := unsafe.Pointer(uintptr(data) + uintptr(idx)*d.size)
if d.isElemUnmarshalJSONType { if d.isElemUnmarshalJSONType {
receiver := unsafe_New(d.elemType) receiver := unsafe_New(d.elemType)
if err := d.valueDecoder.decodeStream(s, depth, receiver); err != nil { if d.elemType.Kind() == reflect.Slice {
return err **(**unsafe.Pointer)(unsafe.Pointer(&ep)) = receiver
}
*(*unsafe.Pointer)(ep) = **(**unsafe.Pointer)(unsafe.Pointer(&receiver))
} else { } else {
if d.isElemPointerType { **(**unsafe.Pointer)(unsafe.Pointer(&ep)) = **(**unsafe.Pointer)(unsafe.Pointer(&receiver))
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer }
} else if d.isElemPointerType {
**(**unsafe.Pointer)(unsafe.Pointer(&ep)) = nil // initialize elem pointer
} }
if err := d.valueDecoder.decodeStream(s, depth, ep); err != nil { if err := d.valueDecoder.decodeStream(s, depth, ep); err != nil {
return err return err
} }
}
s.skipWhiteSpace() s.skipWhiteSpace()
RETRY: RETRY:
switch s.char() { switch s.char() {
@ -244,25 +243,18 @@ func (d *sliceDecoder) decode(buf []byte, cursor, depth int64, p unsafe.Pointer)
if d.isElemUnmarshalJSONType { if d.isElemUnmarshalJSONType {
receiver := unsafe_New(d.elemType) receiver := unsafe_New(d.elemType)
if d.elemType.Kind() == reflect.Slice { if d.elemType.Kind() == reflect.Slice {
*(*unsafe.Pointer)(ep) = receiver **(**unsafe.Pointer)(unsafe.Pointer(&ep)) = receiver
} else { } else {
*(*unsafe.Pointer)(ep) = *(*unsafe.Pointer)(receiver) **(**unsafe.Pointer)(unsafe.Pointer(&ep)) = **(**unsafe.Pointer)(unsafe.Pointer(&receiver))
}
} else if d.isElemPointerType {
**(**unsafe.Pointer)(unsafe.Pointer(&ep)) = nil // initialize elem pointer
} }
c, err := d.valueDecoder.decode(buf, cursor, depth, ep) c, err := d.valueDecoder.decode(buf, cursor, depth, ep)
if err != nil { if err != nil {
return 0, err return 0, err
} }
cursor = c cursor = c
} else {
if d.isElemPointerType {
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer
}
c, err := d.valueDecoder.decode(buf, cursor, depth, ep)
if err != nil {
return 0, err
}
cursor = c
}
cursor = skipWhiteSpace(buf, cursor) cursor = skipWhiteSpace(buf, cursor)
switch buf[cursor] { switch buf[cursor] {
case ']': case ']':