mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +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())
|
||||
}
|
||||
|
||||
// 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)
|
||||
srcbuf, srclen := buflen(src)
|
||||
|
||||
@@ -1216,10 +1221,10 @@ func buflen(v Value) (unsafe.Pointer, uintptr) {
|
||||
case Array:
|
||||
if v.isIndirect() {
|
||||
buf = v.value
|
||||
len = uintptr(v.Len())
|
||||
} else {
|
||||
panic("reflect.Copy: unaddressable array value")
|
||||
buf = unsafe.Pointer(&v.value)
|
||||
}
|
||||
len = uintptr(v.Len())
|
||||
case String:
|
||||
hdr := (*stringHeader)(v.value)
|
||||
buf = hdr.data
|
||||
|
||||
Reference in New Issue
Block a user