patch reflect: Zero/Len

This commit is contained in:
xushiwei
2024-06-20 23:40:35 +08:00
parent 28b3f6780c
commit 05031e0979
5 changed files with 505 additions and 1 deletions

View File

@@ -135,10 +135,12 @@ func TracePanic(v any) {
}
}
/*
func stringTracef(fp c.FilePtr, format *c.Char, s String) {
cs := c.Alloca(uintptr(s.len) + 1)
c.Fprintf(fp, format, CStrCopy(cs, s))
}
*/
// -----------------------------------------------------------------------------
@@ -147,4 +149,22 @@ func Zeroinit(p unsafe.Pointer, size uintptr) unsafe.Pointer {
return c.Memset(p, 0, size)
}
// New allocates memory and initializes it to zero.
func New(t *Type) unsafe.Pointer {
return AllocZ(t.Size_)
}
// NewArray allocates memory for an array and initializes it to zero.
func NewArray(t *Type, n int) unsafe.Pointer {
return AllocZ(uintptr(n) * t.Size_)
}
// -----------------------------------------------------------------------------
// TODO(xsw): check this
// must match declarations in runtime/map.go.
const MaxZero = 1024
var ZeroVal [MaxZero]byte
// -----------------------------------------------------------------------------