mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
Move the allocator into scr_alloc.c with inline fast paths in scr_runtime.h;
strings, array headers/slot buffers, and emitted acyclic records/classes
(scr_rt_calloc/scr_rt_free) now use it. Adds scr_alloc.test.{c,ts}.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { promisify } from "node:util";
|
|
import { expect, test } from "vitest";
|
|
|
|
const exec = promisify(execFile);
|
|
|
|
// The size-class allocator is compiled out under AddressSanitizer, so the
|
|
// UBSan-only build is the one that exercises it; the ASan build pins the
|
|
// system-allocator bypass the sanitizer lane relies on.
|
|
test.each([
|
|
["size-class", ["-fsanitize=undefined"]],
|
|
["system", ["-fsanitize=address,undefined"]],
|
|
])("small-object allocator contracts hold (%s)", async (mode, sanitize) => {
|
|
const scratch = await mkdtemp(join(tmpdir(), "scriptc-alloc-"));
|
|
try {
|
|
const binary = join(scratch, "alloc");
|
|
await exec("clang", [
|
|
"-std=c11",
|
|
"-O1",
|
|
"-Wall",
|
|
"-Wextra",
|
|
...sanitize,
|
|
join(import.meta.dirname, "scr_alloc.test.c"),
|
|
join(import.meta.dirname, "scr_alloc.c"),
|
|
"-o",
|
|
binary,
|
|
]);
|
|
const result = await exec(binary, [], {
|
|
env: {
|
|
...process.env,
|
|
ASAN_OPTIONS: "halt_on_error=1",
|
|
UBSAN_OPTIONS: "halt_on_error=1",
|
|
},
|
|
});
|
|
expect(result.stdout).toBe(`allocator checks passed: ${mode}\n`);
|
|
expect(result.stderr).toBe("");
|
|
} finally {
|
|
await rm(scratch, { recursive: true, force: true });
|
|
}
|
|
});
|