Rename all example tests/companions to the XXXX-category-test-name scheme (per-category 100-blocks: basic 0010, types 0100, ... errors 1000, diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500, platform 1600). Companions and dir/C fixtures move in lockstep with their parent test; #import/#source/#include paths rewritten to match. Expected output now lives in examples/expected/ (a sibling dir of the tests) split into three streams per the new convention: <name>.exit / <name>.stdout / <name>.stderr (+ optional <name>.ir) run_examples.sh rewritten: scans examples/ and issues/ for an expected/<name>.exit marker, captures stdout and stderr separately (no more 2>&1), compares each stream + exit + optional IR snapshot. Behavior validated unchanged: every renamed test reproduces its prior merged output + exit (diffs limited to file paths/basenames embedded in diagnostics + traces, which correctly reflect the new names). Suite: 292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow in subsequent commits.
88 lines
3.3 KiB
Plaintext
88 lines
3.3 KiB
Plaintext
// ffi-objc-arc-00 — M4.0 end-to-end allocator threading regression.
|
|
//
|
|
// Verifies that the per-instance allocator design from M1.2 A.5 + M4.0
|
|
// is actually wired:
|
|
// 1. `push Context.{ allocator = xx tracker } { SxFoo.alloc(); }` →
|
|
// the state struct is allocated via tracker (not libc).
|
|
// 2. The state struct's first field is `__sx_allocator` (captures the
|
|
// tracker so -dealloc can free through it).
|
|
// 3. `f.release()` drives refcount → 0 → -dealloc fires → reads the
|
|
// captured allocator → calls tracker.dealloc(state).
|
|
// 4. The alloc/dealloc deltas around the call pair balance to (+1, +1)
|
|
// — exactly one sx-defined-class state struct round-trips.
|
|
//
|
|
// Pre-M4.0 the +alloc IMP used libc `malloc` and -dealloc used libc
|
|
// `free`, both bypassing context.allocator — tracker would have
|
|
// observed (+0, +0) deltas, missing the leak silently.
|
|
//
|
|
// Important: capture tracker counters BEFORE and AFTER the
|
|
// alloc/release with NOTHING else allocating in between. `print`
|
|
// allocates strings (NSString-backed), which would also route through
|
|
// tracker and pollute the deltas.
|
|
|
|
#import "modules/std.sx";
|
|
#import "modules/allocators.sx";
|
|
#import "modules/std/objc.sx";
|
|
#import "modules/compiler.sx";
|
|
|
|
SxAllocProbe :: #objc_class("SxAllocProbe") {
|
|
#extends NSObject;
|
|
counter: s32;
|
|
alloc :: () -> *SxAllocProbe;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
inline if OS == .macos {
|
|
gpa := GPA.init();
|
|
tracker := TrackingAllocator.init(xx gpa);
|
|
|
|
push Context.{ allocator = xx tracker, data = null } {
|
|
// Snapshot BEFORE the sx-defined alloc.
|
|
alloc_before := tracker.alloc_count;
|
|
dealloc_before := tracker.dealloc_count;
|
|
|
|
f := SxAllocProbe.alloc();
|
|
|
|
// Snapshot AFTER alloc, BEFORE release.
|
|
alloc_after_alloc := tracker.alloc_count;
|
|
dealloc_after_alloc := tracker.dealloc_count;
|
|
|
|
f.release();
|
|
|
|
// Snapshot AFTER release.
|
|
alloc_after_release := tracker.alloc_count;
|
|
dealloc_after_release := tracker.dealloc_count;
|
|
|
|
// Verify deltas (do all asserts before any print).
|
|
alloc_delta_a := alloc_after_alloc - alloc_before;
|
|
dealloc_delta_a := dealloc_after_alloc - dealloc_before;
|
|
alloc_delta_r := alloc_after_release - alloc_after_alloc;
|
|
dealloc_delta_r := dealloc_after_release - dealloc_after_alloc;
|
|
|
|
if alloc_delta_a < 1 {
|
|
print("FAIL: alloc didn't fire through tracker; delta={}\n", alloc_delta_a);
|
|
return 1;
|
|
}
|
|
if dealloc_delta_a != 0 {
|
|
print("FAIL: dealloc fired prematurely; delta={}\n", dealloc_delta_a);
|
|
return 1;
|
|
}
|
|
if dealloc_delta_r < 1 {
|
|
print("FAIL: release→-dealloc didn't route through tracker; delta={}\n", dealloc_delta_r);
|
|
return 1;
|
|
}
|
|
if dealloc_delta_r != alloc_delta_a {
|
|
print("FAIL: alloc/dealloc deltas mismatched; alloc={} dealloc={}\n",
|
|
alloc_delta_a, dealloc_delta_r);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
print("allocator round-trip: ok\n");
|
|
}
|
|
inline if OS != .macos {
|
|
print("skipped (not macos)\n");
|
|
}
|
|
0;
|
|
}
|