mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-24 10:09:01 -06:00
Never crash: move the one unsafe FFI call into crates/sysmem
The macOS malloc_zone_pressure_relief call (returns freed allocator pages after raw decodes) lived in identical copies inside the desktop app and the CLI. It now lives in lightcraft-sysmem, an isolated L0 helper crate and the workspace's only crate allowed unsafe: one #[allow(unsafe_code)] module, a SAFETY comment, a safe API that returns bytes released (0 off macOS), and tests (repeat calls, release after large frees, concurrent calls). Both apps' alloc_release.rs now just install the safe hook, and their crate roots gain #![forbid(unsafe_code)], so every production crate except sysmem forbids it. AGENTS.md/CLAUDE.md name the exception, per craftrules standards/never-crash.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5525ae667a
commit
1ef74a787d
@@ -28,6 +28,10 @@ of it. Full standard: `../craftrules/standards/never-crash.md`
|
||||
fallback (`unwrap_or…`) only where it can't silently corrupt a document. An unfinished feature returns an
|
||||
"unsupported" error or is disabled. Sole exception: a provably infallible literal, as `#[allow(clippy::expect_used)]`
|
||||
+ `.expect("why it can't fail")`.
|
||||
- **`unsafe` lives only in `crates/sysmem`** (one FFI call, `malloc_zone_pressure_relief`, that returns freed
|
||||
allocator pages to macOS after raw decodes). Every other production crate root has `#![forbid(unsafe_code)]`. A new
|
||||
unsafe need goes in an isolated, well-tested helper crate like it: `// SAFETY:` on every block, a safe API, a safe
|
||||
fallback where possible, and a line here naming it.
|
||||
- **Input-derived numbers are hostile:** `get()` instead of `[i]`/`[a..b]` for offsets from files, users, agents or
|
||||
arithmetic on them; checked/saturating math for lengths, offsets and counts; no division by zero, NaN/inf or negative
|
||||
casts to `usize`; cap allocations sized by input; slice strings only at char boundaries.
|
||||
|
||||
Reference in New Issue
Block a user