cutil

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxIdx is the maximum index on 32 bit systems
	MaxIdx = math.MaxInt32 // 2GB, max int32 value, should be safe

	// PtrSize is the size of a pointer
	PtrSize = C.sizeof_voidptr

	// SizeTSize is the size of C.size_t
	SizeTSize = C.sizeof_size_t
)

Variables

This section is empty.

Functions

func Free added in v0.8.0

func Free(p CPtr)

Free is C.free

func Memcpy added in v0.8.0

func Memcpy(dst, src CPtr, n SizeT)

Memcpy is C.memcpy

func SplitBuffer added in v0.5.0

func SplitBuffer(b []byte) []string

SplitBuffer splits a byte-slice buffer, typically returned from C code, into a slice of strings. The contents of the buffer are assumed to be null-byte separated. If the buffer contains a sequence of null-bytes it will assume that the "space" between the bytes are meant to be empty strings.

func SplitSparseBuffer added in v0.5.0

func SplitSparseBuffer(b []byte) []string

SplitSparseBuffer splits a byte-slice buffer, typically returned from C code, into a slice of strings. The contents of the buffer are assumed to be null-byte separated. This function assumes that buffer to be "sparse" such that only non-null-byte strings will be returned, and no "empty" strings exist if null-bytes are found adjacent to each other.

Types

type CPtr added in v0.8.0

type CPtr unsafe.Pointer

CPtr is an unsafe.Pointer to C allocated memory

func CBytes added in v0.8.0

func CBytes(b []byte) CPtr

CBytes is C.CBytes

func Malloc added in v0.8.0

func Malloc(s SizeT) CPtr

Malloc is C.malloc

type CPtrCSlice added in v0.10.0

type CPtrCSlice []CPtr

CPtrCSlice is a C allocated slice of C pointers.

func NewCPtrCSlice added in v0.10.0

func NewCPtrCSlice(size int) CPtrCSlice

NewCPtrCSlice returns a CPtrSlice. Similar to CString it must be freed with slice.Free()

func (*CPtrCSlice) Free added in v0.10.0

func (v *CPtrCSlice) Free()

Free frees a CPtrSlice

func (*CPtrCSlice) Ptr added in v0.10.0

func (v *CPtrCSlice) Ptr() CPtr

Ptr returns a pointer to CPtrSlice

type CharPtr

type CharPtr unsafe.Pointer

CharPtr is an unsafe pointer wrapping C's `char*`.

func CString added in v0.8.0

func CString(s string) CharPtr

CString is C.CString

type CharPtrPtr

type CharPtrPtr unsafe.Pointer

CharPtrPtr is an unsafe pointer wrapping C's `char**`.

type CommandInput

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

CommandInput can be used to manage the input to ceph's *_command functions.

func NewCommandInput

func NewCommandInput(cmd [][]byte, inputBuffer []byte) *CommandInput

NewCommandInput creates C-level pointers from go byte buffers suitable for passing off to ceph's *_command functions.

func (*CommandInput) Cmd

func (ci *CommandInput) Cmd() CharPtrPtr

Cmd returns an unsafe wrapper around an array of C-strings.

func (*CommandInput) CmdLen

func (ci *CommandInput) CmdLen() SizeT

CmdLen returns the length of the array of C-strings returned by Cmd.

func (*CommandInput) Free

func (ci *CommandInput) Free()

Free any C memory managed by this CommandInput.

func (*CommandInput) InBuf

func (ci *CommandInput) InBuf() CharPtr

InBuf returns an unsafe wrapper to a C char*.

func (*CommandInput) InBufLen

func (ci *CommandInput) InBufLen() SizeT

InBufLen returns the length of the buffer returned by InBuf.

type CommandOutput

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

CommandOutput can be used to manage the outputs of ceph's *_command functions.

func NewCommandOutput

func NewCommandOutput() *CommandOutput

NewCommandOutput returns an empty CommandOutput. The pointers that a CommandOutput provides can be used to get the results of ceph's *_command functions.

func (*CommandOutput) Free

func (co *CommandOutput) Free()

Free any C memory tracked by this object.

func (*CommandOutput) GoValues

func (co *CommandOutput) GoValues() (buf []byte, status string)

GoValues returns native go values converted from the internal C-language values tracked by this object.

func (*CommandOutput) OutBuf

func (co *CommandOutput) OutBuf() CharPtrPtr

OutBuf returns an unsafe wrapper around a pointer to a `char*`.

func (*CommandOutput) OutBufLen

func (co *CommandOutput) OutBufLen() SizeTPtr

OutBufLen returns an unsafe wrapper around a pointer to a size_t.

func (*CommandOutput) Outs

func (co *CommandOutput) Outs() CharPtrPtr

Outs returns an unsafe wrapper around a pointer to a `char*`.

func (*CommandOutput) OutsLen

func (co *CommandOutput) OutsLen() SizeTPtr

OutsLen returns an unsafe wrapper around a pointer to a size_t.

func (*CommandOutput) SetFreeFunc

func (co *CommandOutput) SetFreeFunc(f FreeFunc) *CommandOutput

SetFreeFunc sets the function used to free memory held by CommandOutput. Not all uses of CommandOutput expect to use the basic C.free function and either require or prefer the use of a custom deallocation function. Use SetFreeFunc to change the free function and return the modified CommandOutput object.

type FreeFunc

type FreeFunc func(unsafe.Pointer)

FreeFunc is a wrapper around calls to, or act like, C's free function.

type Iovec added in v0.6.0

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

Iovec is a slice of iovec structs. Might have allocated C memory, so it must be freed with the Free() method.

func ByteSlicesToIovec added in v0.6.0

func ByteSlicesToIovec(data [][]byte) (v Iovec)

ByteSlicesToIovec creates an Iovec and links it to Go buffers in data.

func (*Iovec) Free added in v0.6.0

func (v *Iovec) Free()

Free the C memory in the Iovec.

func (*Iovec) Len added in v0.6.0

func (v *Iovec) Len() int

Len returns a pointer to the iovec

func (*Iovec) Pointer added in v0.6.0

func (v *Iovec) Pointer() unsafe.Pointer

Pointer returns a pointer to the iovec

func (*Iovec) Sync added in v0.8.0

func (v *Iovec) Sync()

Sync makes sure the slices contain the same as the C buffers

type PtrGuard added in v0.8.0

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

PtrGuard respresents a guarded Go pointer (pointing to memory allocated by Go runtime) stored in C memory (allocated by C)

func NewPtrGuard added in v0.8.0

func NewPtrGuard(cPtr CPtr, goPtr unsafe.Pointer) *PtrGuard

NewPtrGuard writes the goPtr (pointing to Go memory) into C memory at the position cPtr, and returns a PtrGuard object.

func (*PtrGuard) Release added in v0.8.0

func (v *PtrGuard) Release()

Release removes the guarded Go pointer from the C memory by overwriting it with NULL.

type SizeT

type SizeT C.size_t

SizeT wraps size_t from C.

type SizeTCSlice added in v0.10.0

type SizeTCSlice []SizeT

SizeTCSlice is a C allocated slice of C.size_t.

func NewSizeTCSlice added in v0.10.0

func NewSizeTCSlice(size int) SizeTCSlice

NewSizeTCSlice returns a SizeTCSlice. Similar to CString it must be freed with slice.Free()

func (*SizeTCSlice) Free added in v0.10.0

func (v *SizeTCSlice) Free()

Free frees a SizeTCSlice

func (*SizeTCSlice) Ptr added in v0.10.0

func (v *SizeTCSlice) Ptr() CPtr

Ptr returns a pointer to SizeTCSlice

type SizeTPtr

type SizeTPtr unsafe.Pointer

SizeTPtr is an unsafe pointer wrapping C's `size_t*`.

type SyncBuffer added in v0.8.0

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

SyncBuffer is a C buffer connected to a data slice

func NewSyncBuffer added in v0.8.0

func NewSyncBuffer(cPtr CPtr, data []byte) *SyncBuffer

NewSyncBuffer creates a C buffer from a data slice and stores it at CPtr

func (*SyncBuffer) Release added in v0.8.0

func (v *SyncBuffer) Release()

Release releases the C buffer and nulls its stored pointer

func (*SyncBuffer) Sync added in v0.8.0

func (v *SyncBuffer) Sync()

Sync asserts that changes in the C buffer are available in the data slice

Jump to

Keyboard shortcuts

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