Merge pull request #1121 from visualfc/closure

fix reflect.pointer  for closure; fix runtime unsafe.pointer ptrBytes
This commit is contained in:
xushiwei
2025-05-17 01:19:40 +08:00
committed by GitHub
4 changed files with 275 additions and 4 deletions

View File

@@ -124,6 +124,9 @@ func (v Value) typ() *abi.Type {
// v.Kind() must be Pointer, Map, Chan, Func, or UnsafePointer
// if v.Kind() == Pointer, the base type must not be not-in-heap.
func (v Value) pointer() unsafe.Pointer {
if v.typ_.IsClosure() {
return v.ptr
}
if v.typ().Size() != goarch.PtrSize || !v.typ().Pointers() {
panic("can't call pointer on a non-pointer Value")
}

View File

@@ -72,13 +72,13 @@ func Basic(_kind Kind) *Type {
kind := _kind & abi.KindMask
if tyBasic[kind] == nil {
name, size, align := basicTypeInfo(kind)
var bytes uintptr
if kind == abi.String {
bytes = pointerSize
var ptrBytes uintptr
if kind == abi.String || kind == abi.UnsafePointer {
ptrBytes = pointerSize
}
tyBasic[kind] = &Type{
Size_: size,
PtrBytes: bytes,
PtrBytes: ptrBytes,
Hash: uint32(kind),
Align_: uint8(align),
FieldAlign_: uint8(align),