Mojo · Design

Design

from ucall import Library 1.0.0-rc.1 · 60202332

  • A thin layer over the C ABI. Every name follows c/ucall/, and enums mirror C enums, never strings. Every one of the 55 exported functions is bound, and so are both callback types, the log sink and the peer authorizer; typed JSON handlers stay Python’s, and Mojo handlers read and write bytes.
  • Handlers are compile-time parameters. One thin abi("C") trampoline is instantiated per handler, and the context the library passes back addresses the Server, which is not Movable for that reason.
  • Pointers keep their types and their borrows. A C pointer that may be null is an Optional[Pointer], a view carries the origin of what it borrows, and only opaque handles and void * state cross as an integer Address.

API

StructLibraryA reference to the loaded library, cheap to copy and shared by everything it creates.13
struct Library

Every handle carries one, which is what keeps the shared object mapped for as long as anything can still call into it.

Fields

sharedArcPointer[_Loaded]The handle and its symbols, refcounted so the last holder unmaps the object.

Conforms to

Copyable, Deinitable, ImplicitlyCopyable, Movable
__init__Opens the shared object and resolves it, which every handle then shares.
def __init__(out self)

Raises

With LIBRARY_MISSING, when nothing is on the loader path, with VERSION_MISMATCH when what loaded is another major version, or with SYMBOL_MISSING when it does not export an entry point the binding needs.
symbolsThe resolved entry points, borrowed rather than copied on every call.
def symbols(self) -> ref[self.shared.symbols] Symbols

Returns

A reference that stays valid for as long as this Library is held.
versionThe linked library's major, minor and patch. Calls ucall_version.
def version(self) -> Tuple[Int, Int, Int]

Returns

The three numbers, which may differ from the ones this binding was written against.
version_nameThe linked library's version, including a release-candidate suffix. Calls ucall_version_name.
def version_name(self) -> String

Returns

The version string the shared object reports for itself.
status_nameThe library's spelling of a status, as OUT_OF_MEMORY spells "out-of-memory". Calls ucall_status_name.
def status_name(self, status: Status) -> String
status_from_nameReads a spelling back; INVALID_ARGUMENT when unrecognized. Calls ucall_status_from_name.
def status_from_name(self, name: StringSpan) -> Status
io_backend_nameThe library's spelling of an I/O backend, as LINUX_URING618 spells "linux-uring618". Calls ucall_io_backend_name.
def io_backend_name(self, backend: Backend) -> String
io_backend_from_nameReads a spelling back; AUTOMATIC when unrecognized. Calls ucall_io_backend_from_name.
def io_backend_from_name(self, name: StringSpan) -> Backend
cpu_class_nameThe library's spelling of a CPU class, as AWS_G5 spells "aws-g5". Calls ucall_cpu_class_name.
def cpu_class_name(self, cpu_class: CPUClass) -> String
cpu_class_from_nameReads a spelling back; UNKNOWN when unrecognized. Calls ucall_cpu_class_from_name.
def cpu_class_from_name(self, name: StringSpan) -> CPUClass
decode_percentDecodes the %XX escapes of encoded, like a query value, and '+' as a space in QUERY mode. Calls ucall_decode_percent.
def decode_percent(self, encoded: Span[UInt8], mode: PercentMode) -> List[UInt8]

Parameters

encodedSpan[UInt8]A path or a query value, still percent-encoded.
modePercentModeWhether a '+' is itself or a space.

Returns

The decoded bytes.

Raises

Error with INVALID_ARGUMENT on a '%' without two hexadecimal digits.
generate_noise_keypairDraws a fresh static keypair from the operating system's entropy. Calls ucall_noise_key_generate.
def generate_noise_keypair(self) -> Tuple[SIMD[.uint8, 32], SIMD[.uint8, 32]]

Returns

The private key, then the public key matching it.

Raises

Error if the operating system offers no entropy.
derive_noise_public_keyThe public key of a stored private key, as peers see it during the handshake. Calls ucall_noise_key_derive.
def derive_noise_public_key(self, private_key: SIMD[.uint8, 32]) -> NoiseKey

Parameters

private_keySIMD[.uint8, 32]The secret scalar.

Returns

The matching Curve25519 public key.

Raises

Error if the library refuses the key.