Documentation
¶
Index ¶
- Constants
- func CBool(b bool) int8
- func CSlice[S ~[]E, E any](s S) unsafe.Pointer
- func CString(s string) unsafe.Pointer
- func CStringTemp(s string) unsafe.Pointer
- func Call[F ~uintptr](fn F, args ...any)
- func CallRaw(fn uintptr, args ...uintptr) (r1, r2 uintptr, err syscall.Errno)
- func CallRet[T any, F ~uintptr](fn F, args ...any) (ret T)
- func Dlclose(handle uintptr) error
- func Dlopen(path string, mode int) (uintptr, error)
- func Dlsym(handle uintptr, name string) (uintptr, error)
- func Free(p Pointer)
- func GetExternVariant[T any, L ~uintptr](lib L, name string) (pv *T, err error)
- func GoBool[T comparable](v T) bool
- func GoPointer[T any](p uintptr) *T
- func GoSlice[T comparable](p unsafe.Pointer) []T
- func GoSliceN[T any](p unsafe.Pointer, n int) []T
- func GoSliceNTemp[T any](p unsafe.Pointer, n int) []T
- func GoSliceTemp[T comparable](p unsafe.Pointer) []T
- func GoString(s unsafe.Pointer) string
- func GoStringN(s unsafe.Pointer, n int) string
- func GoStringNTemp(s unsafe.Pointer, n int) string
- func GoStringTemp(s unsafe.Pointer) string
- func Length[T comparable](p unsafe.Pointer) (n int)
- func Memcpy(dst, src Pointer, size Sizet)
- func Memset(p Pointer, val int, size Sizet)
- func NewCallback(fn any) uintptr
- func RegisterFunc(pf any, cfn uintptr) (err error)
- func RegisterLibFunc(pf any, lib uintptr, symbol string) (err error)
- func Strlen(s unsafe.Pointer) (n int)
- type Char
- type Double
- type Float
- type Int
- type Intptr
- type LazyLibrary
- type LazySymbol
- type Library
- type Long
- type LongLong
- type Pointer
- type Short
- type Sizet
- type Ssize
- type Symbol
- type Uchar
- type Uint
- type Uintptr
- type Ulong
- type UlongLong
- type Ushort
Constants ¶
const ( RTLD_DEFAULT = purego.RTLD_DEFAULT RTLD_LAZY = purego.RTLD_LAZY RTLD_NOW = purego.RTLD_NOW RTLD_LOCAL = purego.RTLD_LOCAL RTLD_GLOBAL = purego.RTLD_GLOBAL )
Variables ¶
This section is empty.
Functions ¶
func CString ¶
CString converts a Go string to a NUL-terminated C string allocated on the C heap with Malloc. The caller owns the memory and must release it with Free once it is no longer needed. A fresh copy is always made, even when s already ends with a NUL byte. CString("") returns a pointer to a single NUL byte. It panics when the allocation fails.
func CStringTemp ¶ added in v0.1.0
CStringTemp returns a borrowed pointer to a NUL-terminated copy of s backed by Go memory. It is valid only while s is kept alive (e.g. with runtime.KeepAlive) and must not be freed. When s already ends with a NUL byte the pointer aliases s's data without copying; otherwise a temporary Go buffer is allocated. CStringTemp("") returns nil.
func Call ¶
Call calls a C function synchronously. Pass pointer arguments as pointers, not uintptr: typed arguments preserve Go ownership through the native call. Native retention beyond the call needs a separate owner and lifetime.
func CallRaw ¶
CallRaw calls a native function synchronously. Convert Go pointers to uintptr directly in this call's arguments; they remain live and address-stable until it returns. Stored uintptr values and addresses retained by C after return require explicit ownership/lifetime management by the caller.
func CallRet ¶
CallRet calls a C function and returns a value. Pointer arguments have the same lifetime contract as Call.
func Dlopen ¶
Dlopen examines the dynamic library or bundle file specified by path.
The mode was ignored on Windows.
func GetExternVariant ¶
func GoBool ¶
func GoBool[T comparable](v T) bool
func GoSlice ¶
func GoSlice[T comparable](p unsafe.Pointer) []T
func GoSliceTemp ¶
func GoSliceTemp[T comparable](p unsafe.Pointer) []T
func GoStringTemp ¶
func Length ¶
func Length[T comparable](p unsafe.Pointer) (n int)
Length Get the length of an array ending with zero
func NewCallback ¶
NewCallback converts a Go function to a C function pointer that can be passed to C code as a callback.
On linux/amd64, linux/arm64, darwin/amd64 and darwin/arm64 the full C calling convention is supported, including float32/float64 and struct arguments and return values, following the System V AMD64 and AAPCS64 ABIs. Struct types must have the same memory layout as their C counterpart (add explicit padding fields if needed).
Only a limited number of callbacks may be created in a single Go process, and any memory allocated for these callbacks is never released.
func RegisterFunc ¶
Types ¶
type LazyLibrary ¶
type LazyLibrary struct {
// contains filtered or unexported fields
}
func NewLazyLibrary ¶
func NewLazyLibrary(name string, fallbacks ...string) (l *LazyLibrary)
func (*LazyLibrary) Handle ¶ added in v0.0.3
func (l *LazyLibrary) Handle() uintptr
func (*LazyLibrary) Load ¶
func (l *LazyLibrary) Load() error
func (*LazyLibrary) NewSymbol ¶
func (l *LazyLibrary) NewSymbol(name string) *LazySymbol
type LazySymbol ¶
type LazySymbol struct {
// contains filtered or unexported fields
}
func (*LazySymbol) Addr ¶
func (s *LazySymbol) Addr() uintptr
func (*LazySymbol) CallRaw ¶
func (s *LazySymbol) CallRaw(args ...uintptr) (r1, r2 uintptr, err error)
CallRaw resolves the symbol and calls it synchronously. It has the same pointer lifetime contract as the package function, including during symbol resolution, which may allocate or grow the Go stack before the native call.
func (*LazySymbol) Find ¶
func (s *LazySymbol) Find() error