mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-21 12:59:04 +00:00
reflect: loosen unaddressable array rules for Copy()
This commit is contained in:
committed by
Damian Gryski
parent
e849901ad6
commit
c6728643e6
@@ -1199,6 +1199,11 @@ func Copy(dst, src Value) int {
|
|||||||
panic("Copy: type mismatch: " + dst.typecode.String() + "/" + src.typecode.String())
|
panic("Copy: type mismatch: " + dst.typecode.String() + "/" + src.typecode.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Can read from an unaddressable array but not write to one.
|
||||||
|
if dst.typecode.Kind() == Array && !dst.isIndirect() {
|
||||||
|
panic("reflect.Copy: unaddressable array value")
|
||||||
|
}
|
||||||
|
|
||||||
dstbuf, dstlen := buflen(dst)
|
dstbuf, dstlen := buflen(dst)
|
||||||
srcbuf, srclen := buflen(src)
|
srcbuf, srclen := buflen(src)
|
||||||
|
|
||||||
@@ -1216,10 +1221,10 @@ func buflen(v Value) (unsafe.Pointer, uintptr) {
|
|||||||
case Array:
|
case Array:
|
||||||
if v.isIndirect() {
|
if v.isIndirect() {
|
||||||
buf = v.value
|
buf = v.value
|
||||||
len = uintptr(v.Len())
|
|
||||||
} else {
|
} else {
|
||||||
panic("reflect.Copy: unaddressable array value")
|
buf = unsafe.Pointer(&v.value)
|
||||||
}
|
}
|
||||||
|
len = uintptr(v.Len())
|
||||||
case String:
|
case String:
|
||||||
hdr := (*stringHeader)(v.value)
|
hdr := (*stringHeader)(v.value)
|
||||||
buf = hdr.data
|
buf = hdr.data
|
||||||
|
|||||||
Reference in New Issue
Block a user