authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-10 20:27:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-07-10 20:27:15-04:00
log8197a14ceb2938c64526c7b84e2ac8da343960fa
tree4cab564fe918fcc167bfcd52c3a619607f0fc364
parent574e31f0a046aa6e6fad73fff2cbbb3617fe1bae

self-hosted test: use C allocator since we depend on libc


1 files changed, 14 insertions(+), 26 deletions(-)

src-self-hosted/test.zig+14-26
...@@ -21,12 +21,11 @@ test "compile errors" {...@@ -21,12 +21,11 @@ test "compile errors" {
21}21}
2222
23const file1 = "1.zig";23const file1 = "1.zig";
24const allocator = std.heap.c_allocator;
2425
25const TestContext = struct {26const TestContext = struct {
26 loop: std.event.Loop,27 loop: std.event.Loop,
27 zig_lib_dir: []u8,28 zig_lib_dir: []u8,
28 direct_allocator: std.heap.DirectAllocator,
29 arena: std.heap.ArenaAllocator,
30 zig_cache_dir: []u8,29 zig_cache_dir: []u8,
31 file_index: std.atomic.Int(usize),30 file_index: std.atomic.Int(usize),
32 group: std.event.Group(error!void),31 group: std.event.Group(error!void),
...@@ -37,8 +36,6 @@ const TestContext = struct {...@@ -37,8 +36,6 @@ const TestContext = struct {
37 fn init(self: *TestContext) !void {36 fn init(self: *TestContext) !void {
38 self.* = TestContext{37 self.* = TestContext{
39 .any_err = {},38 .any_err = {},
40 .direct_allocator = undefined,
41 .arena = undefined,
42 .loop = undefined,39 .loop = undefined,
43 .zig_lib_dir = undefined,40 .zig_lib_dir = undefined,
44 .zig_cache_dir = undefined,41 .zig_cache_dir = undefined,
...@@ -46,36 +43,27 @@ const TestContext = struct {...@@ -46,36 +43,27 @@ const TestContext = struct {
46 .file_index = std.atomic.Int(usize).init(0),43 .file_index = std.atomic.Int(usize).init(0),
47 };44 };
4845
49 self.direct_allocator = std.heap.DirectAllocator.init();46 try self.loop.initMultiThreaded(allocator);
50 errdefer self.direct_allocator.deinit();
51
52 self.arena = std.heap.ArenaAllocator.init(&self.direct_allocator.allocator);
53 errdefer self.arena.deinit();
54
55 // TODO faster allocator for coroutines that is thread-safe/lock-free
56 try self.loop.initMultiThreaded(&self.direct_allocator.allocator);
57 errdefer self.loop.deinit();47 errdefer self.loop.deinit();
5848
59 self.group = std.event.Group(error!void).init(&self.loop);49 self.group = std.event.Group(error!void).init(&self.loop);
60 errdefer self.group.cancelAll();50 errdefer self.group.cancelAll();
6151
62 self.zig_lib_dir = try introspect.resolveZigLibDir(&self.arena.allocator);52 self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);
63 errdefer self.arena.allocator.free(self.zig_lib_dir);53 errdefer allocator.free(self.zig_lib_dir);
6454
65 self.zig_cache_dir = try introspect.resolveZigCacheDir(&self.arena.allocator);55 self.zig_cache_dir = try introspect.resolveZigCacheDir(allocator);
66 errdefer self.arena.allocator.free(self.zig_cache_dir);56 errdefer allocator.free(self.zig_cache_dir);
6757
68 try std.os.makePath(&self.arena.allocator, tmp_dir_name);58 try std.os.makePath(allocator, tmp_dir_name);
69 errdefer std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {};59 errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {};
70 }60 }
7161
72 fn deinit(self: *TestContext) void {62 fn deinit(self: *TestContext) void {
73 std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {};63 std.os.deleteTree(allocator, tmp_dir_name) catch {};
74 self.arena.allocator.free(self.zig_cache_dir);64 allocator.free(self.zig_cache_dir);
75 self.arena.allocator.free(self.zig_lib_dir);65 allocator.free(self.zig_lib_dir);
76 self.loop.deinit();66 self.loop.deinit();
77 self.arena.deinit();
78 self.direct_allocator.deinit();
79 }67 }
8068
81 fn run(self: *TestContext) !void {69 fn run(self: *TestContext) !void {
...@@ -99,14 +87,14 @@ const TestContext = struct {...@@ -99,14 +87,14 @@ const TestContext = struct {
99 ) !void {87 ) !void {
100 var file_index_buf: [20]u8 = undefined;88 var file_index_buf: [20]u8 = undefined;
101 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.next());89 const file_index = try std.fmt.bufPrint(file_index_buf[0..], "{}", self.file_index.next());
102 const file1_path = try std.os.path.join(&self.arena.allocator, tmp_dir_name, file_index, file1);90 const file1_path = try std.os.path.join(allocator, tmp_dir_name, file_index, file1);
10391
104 if (std.os.path.dirname(file1_path)) |dirname| {92 if (std.os.path.dirname(file1_path)) |dirname| {
105 try std.os.makePath(&self.arena.allocator, dirname);93 try std.os.makePath(allocator, dirname);
106 }94 }
10795
108 // TODO async I/O96 // TODO async I/O
109 try std.io.writeFile(&self.arena.allocator, file1_path, source);97 try std.io.writeFile(allocator, file1_path, source);
11098
111 var module = try Module.create(99 var module = try Module.create(
112 &self.loop,100 &self.loop,