From 15a6c779b8bd96311862d723f3e80cdf8574a7ef Mon Sep 17 00:00:00 2001 From: visualfc Date: Thu, 14 Nov 2024 10:20:04 +0800 Subject: [PATCH] internal/lib/reflect: Value.New --- internal/lib/reflect/value.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/internal/lib/reflect/value.go b/internal/lib/reflect/value.go index 2a85ed77..ea6641c6 100644 --- a/internal/lib/reflect/value.go +++ b/internal/lib/reflect/value.go @@ -1799,21 +1799,18 @@ const maxZero = runtime.MaxZero // New returns a Value representing a pointer to a new zero value // for the specified type. That is, the returned Value's Type is PointerTo(typ). func New(typ Type) Value { - /* - if typ == nil { - panic("reflect: New(nil)") - } - t := &typ.(*rtype).t - pt := ptrTo(t) - if ifaceIndir(pt) { - // This is a pointer to a not-in-heap type. - panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)") - } - ptr := unsafe_New(t) - fl := flag(Pointer) - return Value{pt, ptr, fl} - */ - panic("todo: reflect.New") + if typ == nil { + panic("reflect: New(nil)") + } + t := &typ.(*rtype).t + pt := ptrTo(t) + if ifaceIndir(pt) { + // This is a pointer to a not-in-heap type. + panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)") + } + ptr := unsafe_New(t) + fl := flag(Pointer) + return Value{pt, ptr, fl} } // NewAt returns a Value representing a pointer to a value of the