mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 15:03:41 +00:00
reflect: add Value.UnsafePointer method
This was added in Go 1.18.
This commit is contained in:
+10
-4
@@ -135,16 +135,22 @@ func (v Value) IsNil() bool {
|
||||
// Pointer returns the underlying pointer of the given value for the following
|
||||
// types: chan, map, pointer, unsafe.Pointer, slice, func.
|
||||
func (v Value) Pointer() uintptr {
|
||||
return uintptr(v.UnsafePointer())
|
||||
}
|
||||
|
||||
// UnsafePointer returns the underlying pointer of the given value for the
|
||||
// following types: chan, map, pointer, unsafe.Pointer, slice, func.
|
||||
func (v Value) UnsafePointer() unsafe.Pointer {
|
||||
switch v.Kind() {
|
||||
case Chan, Map, Ptr, UnsafePointer:
|
||||
return uintptr(v.pointer())
|
||||
return v.pointer()
|
||||
case Slice:
|
||||
slice := (*sliceHeader)(v.value)
|
||||
return uintptr(slice.data)
|
||||
return slice.data
|
||||
case Func:
|
||||
panic("unimplemented: (reflect.Value).Pointer()")
|
||||
panic("unimplemented: (reflect.Value).UnsafePointer()")
|
||||
default: // not implemented: Func
|
||||
panic(&ValueError{Method: "Pointer"})
|
||||
panic(&ValueError{Method: "UnsafePointer"})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user