Documentation ¶
Overview ¶
Package cptr handles C void* pointers.
Index ¶
- func AsByteSlice[T ~uint8 | ~int8, A ~[]T](value A) (b []byte)
- func Call(post func(fn Function), f any) any
- func CaptureFileDump(f func(fp unsafe.Pointer)) (data []byte, e error)
- func FirstPtr[R, T any, A ~[]T](value A) *R
- func GetString[T ~uint8 | ~int8, A ~[]T](value A) string
- type CArgs
- type FilePipeCGo
- type FilePipeConfig
- type Function
- type FunctionType
- func (ft FunctionType) Assert(fn Function)
- func (ft FunctionType) C(f unsafe.Pointer, arg any) Function
- func (ft FunctionType) CallbackOnce(fn Function) (f unsafe.Pointer, ctx uintptr)
- func (ft FunctionType) CallbackReuse(fn Function) (f unsafe.Pointer, ctx uintptr, revoke func())
- func (ft FunctionType) Invoke(fn Function, param ...unsafe.Pointer) int
- type ZeroFunctionType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsByteSlice ¶
AsByteSlice converts []C.uint8_t or []C.char to []byte.
func Call ¶
Call wraps a Go function as Function and immediately uses it. post is a function that asynchronously invokes fn (this must be asynchronous). f must be a function with zero parameters and zero or one return values. Returns f's return value, or nil if f does not have a return value.
func CaptureFileDump ¶
CaptureFileDump invokes a function that writes to *C.FILE, and returns what's been written.
Types ¶
type CArgs ¶
type CArgs struct { Argc int // argc for C code (cast to C.int) Argv unsafe.Pointer // argv for C code (cast to **C.char) // contains filtered or unexported fields }
CArgs rearranges args so that they can be provided to C code.
type FilePipeCGo ¶
FilePipeCGo is a pipe from *C.FILE writer to *os.File reader.
func NewFilePipeCGo ¶
func NewFilePipeCGo(cfg FilePipeConfig) (p *FilePipeCGo, e error)
NewFilePipeCGo creates a FilePipeCGo.
func (*FilePipeCGo) Close ¶
func (p *FilePipeCGo) Close() error
Close closes both reader and writer.
func (*FilePipeCGo) CloseReader ¶
func (p *FilePipeCGo) CloseReader() (e error)
CloseReader closes the reader.
func (*FilePipeCGo) CloseWriter ¶
func (p *FilePipeCGo) CloseWriter() error
CloseWriter closes the writer.
func (*FilePipeCGo) ReadAll ¶
func (p *FilePipeCGo) ReadAll() (data []byte, e error)
ReadAll reads from the pipe until EOF.
type FilePipeConfig ¶
type FilePipeConfig struct { // NonBlock sets O_NONBLOCK on the writer file descriptor. NonBlock bool }
FilePipeConfig configures FilePipe*.
type Function ¶
type Function interface {
// contains filtered or unexported methods
}
Function provides a C function with void* argument.
type FunctionType ¶
type FunctionType []string
FunctionType identifies the type of a C function. The zero FunctionType identifies `int f(uintptr_t ctx)`. FunctionType{"T1"} identifies `int f(T1* item1, uintptr_t ctx)`.
func (FunctionType) Assert ¶
func (ft FunctionType) Assert(fn Function)
Assert panics if fn is not created from ft.
func (FunctionType) C ¶
func (ft FunctionType) C(f unsafe.Pointer, arg any) Function
C wraps a C function as Function. f must be a C function consistent with ft.
func (FunctionType) CallbackOnce ¶
func (ft FunctionType) CallbackOnce(fn Function) (f unsafe.Pointer, ctx uintptr)
CallbackOnce returns C callback function and arg that can be invoked only once.
func (FunctionType) CallbackReuse ¶
func (ft FunctionType) CallbackReuse(fn Function) (f unsafe.Pointer, ctx uintptr, revoke func())
CallbackReuse returns C callback function and arg that can be invoked repeatedly. Use revoke() to avoid memory leak.
type ZeroFunctionType ¶
type ZeroFunctionType struct {
FunctionType
}
ZeroFunctionType is the `int f(uintptr_t ctx)` type.
var Func0 ZeroFunctionType
Func0 is the `int f(uintptr_t ctx)` type.
func (ZeroFunctionType) Int ¶
func (ZeroFunctionType) Int(f func() int) Function
Int wraps a Go function as Function.
func (ZeroFunctionType) Void ¶
func (ft ZeroFunctionType) Void(f func()) Function
Void wraps a Go function as Function.