blocks

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Rendered for darwin/amd64

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:

  1. The Go func is registered in a thread-safe registry and assigned a numeric handle.
  2. A C block is constructed that, when called by ObjC, looks up the handle and dispatches to the stored Go func.
  3. 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockRegister

func BlockRegister(fn any) uint64

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

func FreeBlock(block unsafe.Pointer)

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

func MakeBlock_bool_ptr_ptr(fn func(unsafe.Pointer, unsafe.Pointer) bool) unsafe.Pointer

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

func MakeBlock_bool_uint64_ptr(fn func(uint64, unsafe.Pointer) bool) unsafe.Pointer

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

func MakeBlock_void(fn func()) unsafe.Pointer

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

func MakeBlock_void_bool_ptr_int32(fn func(bool, unsafe.Pointer, int32)) unsafe.Pointer

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

func MakeBlock_void_int32(fn func(int32)) unsafe.Pointer

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

func MakeBlock_void_ptr(fn func(unsafe.Pointer)) unsafe.Pointer

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

func MakeBlock_void_ptr_int32(fn func(unsafe.Pointer, int32)) unsafe.Pointer

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

func MakeBlock_void_ptr_ptr(fn func(unsafe.Pointer, unsafe.Pointer)) unsafe.Pointer

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

func MakeBlock_void_uint64(fn func(uint64)) unsafe.Pointer

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.

Jump to

Keyboard shortcuts

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