unsafe

package
v4.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[T any](ptr uintptr) *T

Cast is used to centralize unsafe use C of allocated pointer. We take the address and then dereference it to trick go vet from creating a possible misuse of unsafe.Pointer

func CastNative

func CastNative[N Native, T Native](ptr *N) *T

func CastWithOffset

func CastWithOffset[T any](ptr uintptr, offset uint64) *T

CastWithOffset is the same as cast but adding an offset to the pointer by a multiple of the size of the type pointed.

func Cstring

func Cstring(pinner *runtime.Pinner, name string) *byte

Cstring converts a go string to *byte that can be passed to C code.

func Gostring

func Gostring(ptr *byte) string

Gostring copies a char* to a Go string.

func GostringSized

func GostringSized(ptr *byte, size uint64) string

func NativeToUintptr

func NativeToUintptr[T any](x T) uintptr

NativeToUintptr is a helper used by populate WafObject values with Go values

func PtrToUintptr

func PtrToUintptr[T any](arg *T) uintptr

PtrToUintptr is a helper to centralize of usage of unsafe.Pointer do not use this function to cast interfaces

func Slice added in v4.2.0

func Slice[T any](ptr *T, length uint64) []T

func SliceData

func SliceData[E any, T ~[]E](slice T) *E

func SliceToUintptr

func SliceToUintptr[T any](arg []T) uintptr

func String added in v4.2.0

func String(ptr *byte, length uint64) string

func StringData added in v4.2.0

func StringData(str string) *byte

func UintptrToNative

func UintptrToNative[T any](x uintptr) T

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 | ~bool | ~uintptr
}

type Pointer

type Pointer = unsafe.Pointer

type StringHeader

type StringHeader struct {
	Len  int
	Data *byte
}

func NativeStringUnwrap

func NativeStringUnwrap(str string) StringHeader

NativeStringUnwrap cast a native string type into it's runtime value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL