Skip to content

nix-bindings: improve C API ergonomics and safety - #95

Open
NotAShelf wants to merge 8 commits into
mainfrom
notashelf/push-pmvwmlsumzxy
Open

NotAShelf wants to merge 8 commits into
mainfrom
notashelf/push-pmvwmlsumzxy

Conversation

@NotAShelf

Copy link
Copy Markdown
Owner

Slight improvements and classification to both workspace components. Mainly I've decided to finish the feature gating and thread safety work I've initiated earlier, alongside some initialization and error handling which I thought was lacking. Some highlights:

  • Features like expr, flake, main, and store have correct transitive dependencies for the sake of improving build correctness and reducing unnecessary code inclusion.
  • Changed the thread safety contract a little bit. Contexts and wrappers are now explicitly neither Send nor Sync, requiring construction, use, and drop on the same thread.
  • Initialization is now run once per process and errors are retained, with feature-specific gating for library initialization.
  • Added a new method get_attr_lazy to Value for retrieving attributes without evaluating their values,.
  • Made Error type Clone, implemented source() for error chaining, and added a catch_callback utility to prevent Rust panics from crossing the FFI boundary.
  • Updated is_pure_eval to use the context API and provide a safer, more robust implementation.

Updated docs & tests too. Evix will probably need updating for this. CC @amaanq

Signed-off-by: NotAShelf [email protected]
Change-Id: Ic4f0eb4c62a7a3918ef99905ffd73a5a6a6a6964

Signed-off-by: NotAShelf <[email protected]>
Change-Id: Ic4f0eb4c62a7a3918ef99905ffd73a5a6a6a6964
Signed-off-by: NotAShelf <[email protected]>
Change-Id: Ia593e899709467f8f5229b4bc8369fd36a6a6964
Keep external declarations available with expr and parse compiler include flags
without collecting an intermediate vector. Preserve Nix C signatures.

Signed-off-by: NotAShelf <[email protected]>
Change-Id: Ie439562e4be7d58dd7d28f4f45f36dea6a6a6964
Accept borrowed C strings for evaluation and keep up to eight call arguments
on the stack. Add lazy member access, raw strings, and shared deep forcing.
Release allocated values and realised strings on error paths, and remove
the evaluator Send implementation.

Signed-off-by: NotAShelf <[email protected]>
Change-Id: If2556247d946af2b03adc823be265c386a6a6964
Make feature dependencies explicit and gate tests and examples accordingly.
Retain initialization failures, preserve error sources, and use Nix error
accessors only for their supported error codes.

Contain callback and finalizer panics, add lazy primop member access, and
remove the remaining context-backed Send implementations. Update public
exports and document same-thread ownership and reduced-feature support.

Signed-off-by: NotAShelf <[email protected]>
Change-Id: I04c73790ef3a41f4bdefa73df63435016a6a6964
Expose callback-scoped string dependencies and context-aware coercion and
JSON conversion. Check foreign payload identity without dereferencing
unknown memory, and release Rust payloads through GC finalization.

Contain callback and destructor panics and preserve ownership on
construction failures.

Signed-off-by: NotAShelf <[email protected]>
Change-Id: Iad43de75d021a3f0e56d5e4b4550d1c86a6a6964
Signed-off-by: NotAShelf <[email protected]>
Change-Id: I18cdb647df01391dcbca2102b1aeb8a96a6a6964
Signed-off-by: NotAShelf <[email protected]>
Change-Id: I59fc6493932651f70c7a7758753e9d286a6a6964
@NotAShelf
NotAShelf force-pushed the notashelf/push-pmvwmlsumzxy branch from 348fe6a to 23e28ba Compare October 14, 2026 16:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant