reflect: loosen unaddressable array rules for Copy()
Этот коммит содержится в:
родитель
e849901ad6
коммит
c6728643e6
1 изменённых файлов: 7 добавлений и 2 удалений
|
@ -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
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче