lib: α-batch-2 rt.malloc → alloc([], N)! (path/shlex/fmt/ostest)
Phase 0 #8 second α-batch. 7 sites: lib/path/path.ww `join` ×4, lib/shlex/shlex.ww `dupstr`, lib/fmt/fmt.ww `asprintf` tight-copy, lib/os/ostest.ww `test_alloc_free_roundtrip`. Same dup-pilot pattern (4c07ef0,47918d3): `alloc([], N)!` + `buf.len = N;` + `return strings.frombytes(buf);`. Side effects: - path/shlex/fmt: import switches `rt` → `strings` (callers now reference `strings.frombytes`, not `rt.malloc` direct). - ostest.ww: `import rt;` retained — the alloc builtin lowers to `CALL malloc(SB)` which resolves via rt's @symbol("rt_malloc") decl. Other files reach rt transitively via `import strings`; ostest only imports os, so it needs the explicit rt import. - shlex stale comment "avoid strings dep" stripped — strings is now in scope. Verified make test 132/132 + 995_self_rebuild byte-identity. Advances #43.
This commit is contained in:
@@ -97,22 +97,18 @@ fn streq(a: str, b: str) bool = {
|
||||
|
||||
// ---- alloc/free: mmap-backed runtime allocator ----------------------
|
||||
//
|
||||
// Direct round-trip. memio's dynamic-buffer tests already exercise
|
||||
// os.alloc / os.free transitively; the row here pins the FFI shape
|
||||
// at the lib/os layer (write+read-back proves the returned page is
|
||||
// dereferenceable, not just non-nil).
|
||||
// Direct round-trip. Write-then-read-back proves the returned page is
|
||||
// dereferenceable. A miscompiled binding (wrong arg order, wrong ABI,
|
||||
// etc.) would either fault or return zero here.
|
||||
|
||||
@test fn test_alloc_free_roundtrip() void = {
|
||||
let p: *u8 = rt.malloc(4096u64): *u8;
|
||||
if (p == nil: *u8) { fail(); };
|
||||
// Write a sentinel at the head and tail of the page, read it
|
||||
// back. A miscompiled binding (wrong arg order, wrong ABI, etc.)
|
||||
// would either fault or return zero here.
|
||||
let p: []u8 = alloc([], 4096u64)!;
|
||||
p.len = 4096;
|
||||
p[0] = 90u8; // 0x5a
|
||||
p[4095] = 165u8; // 0xa5
|
||||
if (p[0] != 90u8) { fail(); };
|
||||
if (p[4095] != 165u8) { fail(); };
|
||||
os.free(p: *void, 4096u64);
|
||||
os.free(p.ptr: *void, 4096u64);
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
|
||||
Reference in New Issue
Block a user