Documentation
¶
Overview ¶
Package blocks manages the CGo trampolines that allow ObjC block callbacks to invoke Go functions.
ObjC blocks are typed function-pointer closures. When generated code passes a Go func value to an ObjC API that expects a block, the trampoline layer bridges the two calling conventions:
- The Go func is registered in a thread-safe registry and assigned a numeric handle.
- A C block is constructed that, when called by ObjC, looks up the handle and dispatches to the stored Go func.
- The registry uses atomic reference counting so the Go func is not garbage-collected while ObjC holds a reference to the block.
Block type signatures are collected across all frameworks during generation and deduplicated; the resulting Go func types are emitted into blocks_generated.go by the code generator.
Index ¶
- func BlockRegister(fn any) uint64
- func FreeBlock(block unsafe.Pointer)
- func MakeBlock_bool_ptr_ptr(fn func(unsafe.Pointer, unsafe.Pointer) bool) unsafe.Pointer
- func MakeBlock_bool_ptr_uint64_ptr_uint64(fn func(unsafe.Pointer, uint64, unsafe.Pointer, uint64) bool) unsafe.Pointer
- func MakeBlock_bool_uint64_ptr(fn func(uint64, unsafe.Pointer) bool) unsafe.Pointer
- func MakeBlock_void(fn func()) unsafe.Pointer
- func MakeBlock_void_bool_ptr_int32(fn func(bool, unsafe.Pointer, int32)) unsafe.Pointer
- func MakeBlock_void_int32(fn func(int32)) unsafe.Pointer
- func MakeBlock_void_ptr(fn func(unsafe.Pointer)) unsafe.Pointer
- func MakeBlock_void_ptr_int32(fn func(unsafe.Pointer, int32)) unsafe.Pointer
- func MakeBlock_void_ptr_ptr(fn func(unsafe.Pointer, unsafe.Pointer)) unsafe.Pointer
- func MakeBlock_void_uint64(fn func(uint64)) unsafe.Pointer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockRegister ¶
BlockRegister stores fn in the block registry and returns a unique key. The reference count starts at 1. ObjC's Block_copy increments it via the copy helper; Block_release decrements it via the dispose helper. Call FreeBlock after the CGo call returns to release the initial reference.
func FreeBlock ¶
FreeBlock decrements the reference count on block's goKey and frees the GoBlock heap allocation. Call this after the CGo call returns for every block created by a MakeBlock_* factory.
func MakeBlock_bool_ptr_ptr ¶
MakeBlock_bool_ptr_ptr creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_bool_ptr_uint64_ptr_uint64 ¶
func MakeBlock_bool_ptr_uint64_ptr_uint64(fn func(unsafe.Pointer, uint64, unsafe.Pointer, uint64) bool) unsafe.Pointer
MakeBlock_bool_ptr_uint64_ptr_uint64 creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_bool_uint64_ptr ¶
MakeBlock_bool_uint64_ptr creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void ¶
MakeBlock_void creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_bool_ptr_int32 ¶
MakeBlock_void_bool_ptr_int32 creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_int32 ¶
MakeBlock_void_int32 creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_ptr ¶
MakeBlock_void_ptr creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_ptr_int32 ¶
MakeBlock_void_ptr_int32 creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_ptr_ptr ¶
MakeBlock_void_ptr_ptr creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
func MakeBlock_void_uint64 ¶
MakeBlock_void_uint64 creates an ObjC block that calls fn when invoked. The returned block is owned by the caller; pass it to FreeBlock after use.
Types ¶
This section is empty.