reflect: add SetZero

This was added in Go 1.20 and is required by encoding/json starting with
Go 1.21.
This commit is contained in:
Ayke van Laethem
2023-07-07 15:58:08 +02:00
committed by Ron Evans
parent e075e0591d
commit fffad84a63
2 changed files with 10 additions and 3 deletions
+10
View File
@@ -1068,6 +1068,13 @@ func (v Value) Set(x Value) {
memcpy(v.value, xptr, size)
}
func (v Value) SetZero() {
v.checkAddressable()
v.checkRO()
size := v.typecode.Size()
memzero(v.value, size)
}
func (v Value) SetBool(x bool) {
v.checkAddressable()
v.checkRO()
@@ -1569,6 +1576,9 @@ func (e *ValueError) Error() string {
//go:linkname memcpy runtime.memcpy
func memcpy(dst, src unsafe.Pointer, size uintptr)
//go:linkname memzero runtime.memzero
func memzero(ptr unsafe.Pointer, size uintptr)
//go:linkname alloc runtime.alloc
func alloc(size uintptr, layout unsafe.Pointer) unsafe.Pointer