Documentation ¶
Overview ¶
Package cptr handles C void* pointers.
Index ¶
- func AsByteSlice(value interface{}) (b []byte)
- func Call(post func(fn Function), f interface{}) interface{}
- func CtxClear(ctx unsafe.Pointer)
- func CtxGet(ctx unsafe.Pointer) interface{}
- func CtxPop(ctx unsafe.Pointer) interface{}
- func CtxPut(obj interface{}) (ctx unsafe.Pointer)
- func ParseCptrArray(arr interface{}) (ptr unsafe.Pointer, count int)
- type CArgs
- type Function
- type FunctionType
- func (ft FunctionType) Assert(fn Function)
- func (ft FunctionType) C(f, arg unsafe.Pointer) Function
- func (ft FunctionType) CallbackOnce(fn Function) (f, arg unsafe.Pointer)
- func (ft FunctionType) CallbackReuse(fn Function) (f, arg unsafe.Pointer, 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 ¶
func AsByteSlice(value interface{}) (b []byte)
AsByteSlice converts *[n]C.uint8_t or *[n]C.char or []C.uint8_t or []C.char to []byte.
func Call ¶
func Call(post func(fn Function), f interface{}) interface{}
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 CtxGet ¶
CtxGet returns the object associated with void* pointer. Panics if the object is not found.
func ParseCptrArray ¶
ParseCptrArray converts any slice of pointer-sized items to C void*[] type.
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 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(void* arg)`. FunctionType{"T1"} identifies `int f(T1* item1, void* arg)`.
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, arg unsafe.Pointer) 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, arg unsafe.Pointer)
CallbackOnce returns C callback function and arg that can be invoked only once.
func (FunctionType) CallbackReuse ¶
func (ft FunctionType) CallbackReuse(fn Function) (f, arg unsafe.Pointer, 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(void* arg)` type.
var Func0 ZeroFunctionType
Func0 is the `int f(void* arg)` 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.