Documentation
¶
Index ¶
- func Cast[T any](ptr uintptr) *T
- func CastWithOffset[T any](ptr uintptr, offset uint64) *T
- func Cstring(pinner *runtime.Pinner, name string) *byte
- func Gostring(ptr *byte) string
- func GostringSized(ptr *byte, size uint64) string
- func NativeToUintptr[T Native](x T) uintptr
- func Slice[T any](ptr *T, length uint64) []T
- func SliceData[E any, T ~[]E](slice T) *E
- func String(ptr *byte, length uint64) string
- func StringData(str string) *byte
- func UintptrToNative[T Native](x uintptr) T
- type Native
- type StringHeader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cast ¶
Cast converts a uintptr obtained from C-allocated memory into a Go pointer of the desired type. The pointer must not originate from Go-allocated memory, as the uintptr argument is invisible to the garbage collector and violates the unsafe.Pointer conversion rules (the pointer-to-uintptr and uintptr-to-pointer conversions do not occur in the same expression).
The implementation bypasses go vet's unsafe.Pointer checks by reinterpreting the uintptr through its memory representation rather than using a direct unsafe.Pointer(ptr) conversion.
func CastWithOffset ¶
CastWithOffset is the same as Cast but advances the pointer by offset elements of type T (i.e., by offset * unsafe.Sizeof(T) bytes) before converting. The same C-allocated memory restriction as Cast applies.
func GostringSized ¶
GostringSized copies size bytes starting at ptr into a new Go string. Unlike Gostring, it does not scan for a NUL terminator. Returns "" if ptr is nil.
func NativeToUintptr ¶
NativeToUintptr is a helper used by populate WafObject values with Go values
func Slice ¶
Slice returns a []T whose backing array starts at ptr and has the given length. It is a generic wrapper around unsafe.Slice.
func SliceData ¶
func SliceData[E any, T ~[]E](slice T) *E
SliceData returns a pointer to the underlying array of the slice. It is a generic wrapper around unsafe.SliceData.
func String ¶
String returns a string whose bytes start at ptr and has the given length. It is a wrapper around unsafe.String.
func StringData ¶
StringData returns a pointer to the underlying bytes of str. It is a wrapper around unsafe.StringData.
func UintptrToNative ¶
UintToNative is a helper used retrieve Go values from an uintptr encoded value from a WafObject
Types ¶
type Native ¶
type Native interface {
~byte | ~float64 | ~float32 | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint16 | ~uint32 | ~uint64 | ~bool | ~uintptr
}
Native is a constraint that permits scalar types whose in-memory representation can safely be reinterpreted via NativeToUintptr and UintptrToNative. All permitted types have a well-defined, fixed-size layout with no pointers.
type StringHeader ¶
StringHeader is the runtime representation of a Go string value, mirroring the internal layout used by the compiler.
func NativeStringUnwrap ¶
func NativeStringUnwrap(str string) StringHeader
NativeStringUnwrap cast a native string type into it's runtime value.