This was added in Go 1.20 and is required by encoding/json starting with
Go 1.21.
Этот коммит содержится в:
Ayke van Laethem 2023-07-07 15:58:08 +02:00 коммит произвёл Ron Evans
родитель e075e0591d
коммит fffad84a63
2 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -1559,8 +1559,6 @@ func TestIsZero(t *testing.T) {
t.Errorf("%d: IsZero(Zero(TypeOf((%s)(%+v)))) is false", i, x.Kind(), tt.x)
}
/* // TODO(tinygo): missing SetZero support
p := New(x.Type()).Elem()
p.Set(x)
p.SetZero()
@ -1568,7 +1566,6 @@ func TestIsZero(t *testing.T) {
t.Errorf("%d: IsZero((%s)(%+v)) is true after SetZero", i, p.Kind(), tt.x)
}
*/
}

Просмотреть файл

@ -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