cptr

package
v0.0.0-...-c2e30b8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: NIST-PD-fallback Imports: 4 Imported by: 3

Documentation

Overview

Package cptr handles C void* pointers.

Index

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 CtxClear

func CtxClear(ctx unsafe.Pointer)

CtxClear deallocates void* pointer.

func CtxGet

func CtxGet(ctx unsafe.Pointer) interface{}

CtxGet returns the object associated with void* pointer. Panics if the object is not found.

func CtxPop

func CtxPop(ctx unsafe.Pointer) interface{}

CtxPop is equivalent to CtxGet followed by CtxClear.

func CtxPut

func CtxPut(obj interface{}) (ctx unsafe.Pointer)

CtxPut allocates void* pointer for an arbitrary Go object.

func ParseCptrArray

func ParseCptrArray(arr interface{}) (ptr unsafe.Pointer, count int)

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.

func NewCArgs

func NewCArgs(args []string) *CArgs

NewCArgs constructs CArgs.

func (*CArgs) Close

func (a *CArgs) Close() error

Close releases C memory in CArgs.

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.

func (FunctionType) Invoke

func (ft FunctionType) Invoke(fn Function, param ...unsafe.Pointer) int

Invoke invokes the function. fn and param must be consistent with ft.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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