setCAllocator

Replace custom malloc functions in netsurf libs with a global Zig allocator.

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-03-20 15:46:33 +01:00
committed by Pierre Tachoire
parent f0773a3ca2
commit 76c88d049f
9 changed files with 190 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ const jsruntime = @import("jsruntime");
const generate = @import("generate.zig");
const pretty = @import("pretty");
const setCAllocator = @import("calloc.zig").setCAllocator;
const parser = @import("netsurf.zig");
const apiweb = @import("apiweb.zig");
const Window = @import("html/window.zig").Window;
@@ -87,6 +88,7 @@ fn testsAllExecFn(
inline for (testFns) |testFn| {
try testExecFn(alloc, js_env, testFn);
_ = c_arena.reset(.retain_capacity);
}
}
@@ -115,6 +117,8 @@ const Run = enum {
unit,
};
var c_arena: std.heap.ArenaAllocator = undefined;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
@@ -148,6 +152,10 @@ pub fn main() !void {
}
}
c_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer c_arena.deinit();
setCAllocator(c_arena.allocator());
// run js tests
if (run == .all or run == .browser) try run_js(out);