lib

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToInt

func BoolToInt(b bool) uintptr

BoolToInt converts a Go bool to C int (0 or 1)

func CString

func CString(s string) []byte

CString converts a Go string to a null-terminated byte slice. The caller must keep the slice alive during the C call and use &buf[0] as the pointer.

func Free

func Free(ptr uintptr)

Free releases memory allocated by libc malloc.

func IntToBool

func IntToBool(i uintptr) bool

IntToBool converts a C int to Go bool

func LoadLibrary

func LoadLibrary(libalpmPath string) error

LoadLibrary loads the ALPM library. It's safe to call multiple times.

func PtrToString

func PtrToString(ptr uintptr) string

PtrToString converts a C string pointer to a Go string This function finds the null terminator to determine the length

func PtrToStringWithLen

func PtrToStringWithLen(ptr uintptr, length int) string

PtrToStringWithLen converts a C string pointer with known length to Go string

func Syscall

func Syscall(fn uintptr, args ...uintptr) uintptr

Syscall calls a function and returns only the first return value (r1) This is a convenience wrapper for purego.SyscallN

func SyscallWithError

func SyscallWithError(fn uintptr, args ...uintptr) (uintptr, uintptr)

SyscallWithError calls a function and returns r1 and errno

Types

type FunctionCaller

type FunctionCaller interface {
	// GetFunc returns a function pointer by name
	GetFunc(name string) (uintptr, error)
	// CallFunc calls a function by name with the given arguments
	CallFunc(name string, args ...uintptr) (uintptr, error)
}

FunctionCaller is an interface for calling C functions. This abstraction allows for mocking in unit tests.

type FunctionRegistry

type FunctionRegistry struct {
	// contains filtered or unexported fields
}

FunctionRegistry manages lazy loading of ALPM functions

func GetRegistry

func GetRegistry() (*FunctionRegistry, error)

GetRegistry returns the global function registry

func (*FunctionRegistry) CallFunc

func (r *FunctionRegistry) CallFunc(name string, args ...uintptr) (uintptr, error)

CallFunc calls a function with the given arguments using purego.SyscallN

func (*FunctionRegistry) GetFunc

func (r *FunctionRegistry) GetFunc(name string) (uintptr, error)

GetFunc lazily loads and returns a function pointer

type MockFunctionRegistry

type MockFunctionRegistry struct {
	// contains filtered or unexported fields
}

MockFunctionRegistry is a mock implementation of FunctionCaller for testing.

func NewMockRegistry

func NewMockRegistry() *MockFunctionRegistry

NewMockRegistry creates a new mock function registry.

func (*MockFunctionRegistry) CallFunc

func (m *MockFunctionRegistry) CallFunc(name string, args ...uintptr) (uintptr, error)

CallFunc returns a mock result for the function call.

func (*MockFunctionRegistry) GetCallCount

func (m *MockFunctionRegistry) GetCallCount(name string) int

GetCallCount returns how many times a function was called.

func (*MockFunctionRegistry) GetFunc

func (m *MockFunctionRegistry) GetFunc(name string) (uintptr, error)

GetFunc returns a mock function pointer.

func (*MockFunctionRegistry) RegisterFunc

func (m *MockFunctionRegistry) RegisterFunc(name string, ptr uintptr)

RegisterFunc registers a mock function pointer.

func (*MockFunctionRegistry) Reset

func (m *MockFunctionRegistry) Reset()

Reset clears all mock data.

func (*MockFunctionRegistry) SetCallError

func (m *MockFunctionRegistry) SetCallError(name string, err error)

SetCallError sets an error that CallFunc should return for a function.

func (*MockFunctionRegistry) SetCallResult

func (m *MockFunctionRegistry) SetCallResult(name string, result uintptr)

SetCallResult sets the result that CallFunc should return for a function.

Jump to

Keyboard shortcuts

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