Skip to main content

Crate keyrill_ffi

Crate keyrill_ffi 

Source
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 one keyrill_core::session::Session each, 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_source and kr_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§

CompatibilityPlan
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.
NativeEvent
kr_event: one key or command, read by value; len counts the UTF-16 units in use.
NativeEventView
Read-only bounded wire event. The engine remains responsible for tag validation.
NativePlan
kr_plan: a proposal copied into caller-owned arrays; no Rust allocation crosses the interface.
NativePlanView
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. *out is set to null first and receives the handle only on KR_OK.
kr_plan_event⚠
Copy a proposal out without installing its state; it becomes the only plan kr_commit accepts, 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.