unsafe

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 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(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 KeepAlive

func KeepAlive[T any](x T)

KeepAlive is a copy of runtime.KeepAlive keepAlive has 2 usages: - It forces the deallocation of the memory to take place later than expected (just like runtime.KeepAlive) - It forces the given argument x to be escaped on the heap by saving it into a global value (Go doesn't provide a standard way to do it as of today) It is implemented so that the compiler cannot optimize it.

func NativeStringUnwrap

func NativeStringUnwrap(str string) reflect.StringHeader

NativeStringUnwrap cast a native string type into it's runtime value. Exported as the struct reflect.StringHeader

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 SliceToUintptr

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

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
}

Jump to

Keyboard shortcuts

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