Expand description
C ABI over keyrill_core for native input-method adapters.
Built as a static library and linked into each platform adapter. include/keyrill.h is the
caller contract: struct layouts, ownership, threading, versioning and every status code. The
exports here implement it. Native Rust adapters use the same entry points and bounded views.
The boundary keeps everything Rust owns out of native reach. Events are copied into owned
values before the session sees them, and plans are copied out into fixed-size #[repr(C)]
structs whose arrays belong to the caller, so no Rust allocation, borrow or lifetime crosses
the interface and the adapter frees nothing but handles. Every export that can fail runs
inside std::panic::catch_unwind: a panic marks the handle poisoned, and every later call
on it returns KR_POISONED rather than touch state the panic may have left half-updated.
Rust never calls back into the adapter, so no Rust borrow is live while native code runs.
adapter (C, Objective-C++, ...) keyrill-ffi keyrill-core
kr_event, caller-owned --copy--> decode_event --Event--> Session::propose*
kr_plan, caller-owned <--copy-- NativePlan <--Plan---
kr_commit(plan_id, outcome) ------------------------------------> Session::acknowledge- Engine handles (
kr_engine_*,kr_plan_event,kr_commit) wrap onekeyrill_core::session::Sessioneach, copy every buffer across the boundary, catch panics and poison the handle on one. - Configuration (
kr_set_automatic_policy,kr_set_keyboard) applies while idle. - Dictionaries (
kr_dictionary_parse_utf8,kr_adopt_dictionaries,kr_set_dictionary_utf8,kr_clear_dictionary,kr_dictionary_skipped_lines) publish and describe immutable snapshots; reading files stays in the adapter. - The compatibility family (
kr_plan_compatibility_event,kr_commit_compatibility) tracks observed input for the macOS synthetic-rewrite backend, separately from verified edits. vocabulary_sourceandkr_vocabulary_*read and settle dictionary files on a serial queue for the adapter, and name Vim’s default spell files under a home directory.
docs/porting.md explains how a new platform adapter uses these calls.
Modules§
- vocabulary_
host kr_vocabulary: dictionary sources that engines adopt, without scheduling or native editing authority.- vocabulary_
source - Bounded reading of one dictionary file into an immutable vocabulary, outside input callbacks.
Structs§
- Compatibility
Plan - Best-effort committed-input proposal; submission is not document verification.
- Dictionary
- Opaque immutable dictionary. Its owner must drain all borrows before freeing it.
- Engine
kr_engine: one word session for one input context, owned by the native adapter.- Native
Event kr_event: one key or command, read by value;lencounts the UTF-16 units in use.- Native
Event View - Read-only bounded wire event. The engine remains responsible for tag validation.
- Native
Plan kr_plan: a proposal copied into caller-owned arrays; no Rust allocation crosses the interface.- Native
Plan View - Read-only view of a successfully initialized proposal.
Functions§
- kr_
abi_ version - Return the major/minor ABI version. No allocation or panicking work occurs.
- kr_
adopt_ ⚠dictionaries - Adopt both immutable dictionaries together without changing policy or session state. Null means missing; a parsed empty dictionary means ready. A pending proposal refuses adoption.
- kr_
clear_ ⚠dictionary - Explicitly make a protection source missing, without reviving editing authority. Apply outside input callbacks; an outstanding proposal rejects the operation.
- kr_
commit ⚠ - Acknowledge the latest plan; refused and unknown outcomes invalidate the session until
kr_reset. A stale token changes nothing. - kr_
dictionary_ ⚠free - Free an immutable dictionary once, after all borrows drain. Null is a no-op.
- kr_
dictionary_ ⚠parse_ utf8 - Parse bounded UTF-8 Vim data without an engine, retaining no input buffer. Every failure leaves a non-null output object holding null.
- kr_
dictionary_ ⚠skipped_ lines - Write the skipped-line count of a language’s current source; a missing source is STATE.
- kr_
engine_ ⚠free - Free once, after every call on the engine has returned and no callback can reach it. Null is a no-op.
- kr_
engine_ ⚠new - Allocate an engine in Idle with the OFF policy, the Apple keyboard and both dictionaries
missing.
*outis set to null first and receives the handle only onKR_OK. - kr_
plan_ ⚠event - Copy a proposal out without installing its state; it becomes the only plan
kr_commitaccepts, replacing an earlier unacknowledged one. - kr_
prepare_ model - Prepare the process-wide immutable embedded model without creating or changing an engine. Call off the input thread before enabling MODEL. Concurrent preparation may wait on the cache.
- kr_
reset ⚠ - Drop the word, its receipt, pending plans and history, and clear an invalidated session, as the adapter does on each generation change. Configuration and the selected backend survive; poisoning is permanent.
- kr_
set_ ⚠automatic_ policy - Select OFF, the test FIXTURE, or the frozen MODEL policy while idle, outside input callbacks.
- kr_
set_ ⚠dictionary_ utf8 - Publish a complete bounded UTF-8 protection source, retaining last-good on parse failure. Prepare accepted updates outside input callbacks; an outstanding proposal rejects publication.
- kr_
set_ ⚠keyboard - Select the APPLE or PC Russian map while idle, outside input callbacks.