| ... | ... | @@ -21,12 +21,11 @@ test "compile errors" { |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | const file1 = "1.zig"; |
| 24 | const allocator = std.heap.c_allocator; |
| 24 | 25 | |
| 25 | 26 | const TestContext = struct { |
| 26 | 27 | loop: std.event.Loop, |
| 27 | 28 | zig_lib_dir: []u8, |
| 28 | | direct_allocator: std.heap.DirectAllocator, |
| 29 | | arena: std.heap.ArenaAllocator, |
| 30 | 29 | zig_cache_dir: []u8, |
| 31 | 30 | file_index: std.atomic.Int(usize), |
| 32 | 31 | group: std.event.Group(error!void), |
| ... | ... | @@ -37,8 +36,6 @@ const TestContext = struct { |
| 37 | 36 | fn init(self: *TestContext) !void { |
| 38 | 37 | self.* = TestContext{ |
| 39 | 38 | .any_err = {}, |
| 40 | | .direct_allocator = undefined, |
| 41 | | .arena = undefined, |
| 42 | 39 | .loop = undefined, |
| 43 | 40 | .zig_lib_dir = undefined, |
| 44 | 41 | .zig_cache_dir = undefined, |
| ... | ... | @@ -46,36 +43,27 @@ const TestContext = struct { |
| 46 | 43 | .file_index = std.atomic.Int(usize).init(0), |
| 47 | 44 | }; |
| 48 | 45 | |
| 49 | | self.direct_allocator = std.heap.DirectAllocator.init(); |
| 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); |
| 46 | try self.loop.initMultiThreaded(allocator); |
| 57 | 47 | errdefer self.loop.deinit(); |
| 58 | 48 | |
| 59 | 49 | self.group = std.event.Group(error!void).init(&self.loop); |
| 60 | 50 | errdefer self.group.cancelAll(); |
| 61 | 51 | |
| 62 | | self.zig_lib_dir = try introspect.resolveZigLibDir(&self.arena.allocator); |
| 63 | | errdefer self.arena.allocator.free(self.zig_lib_dir); |
| 52 | self.zig_lib_dir = try introspect.resolveZigLibDir(allocator); |
| 53 | errdefer allocator.free(self.zig_lib_dir); |
| 64 | 54 | |
| 65 | | self.zig_cache_dir = try introspect.resolveZigCacheDir(&self.arena.allocator); |
| 66 | | errdefer self.arena.allocator.free(self.zig_cache_dir); |
| 55 | self.zig_cache_dir = try introspect.resolveZigCacheDir(allocator); |
| 56 | errdefer allocator.free(self.zig_cache_dir); |
| 67 | 57 | |
| 68 | | try std.os.makePath(&self.arena.allocator, tmp_dir_name); |
| 69 | | errdefer std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {}; |
| 58 | try std.os.makePath(allocator, tmp_dir_name); |
| 59 | errdefer std.os.deleteTree(allocator, tmp_dir_name) catch {}; |
| 70 | 60 | } |
| 71 | 61 | |
| 72 | 62 | fn deinit(self: *TestContext) void { |
| 73 | | std.os.deleteTree(&self.arena.allocator, tmp_dir_name) catch {}; |
| 74 | | self.arena.allocator.free(self.zig_cache_dir); |
| 75 | | self.arena.allocator.free(self.zig_lib_dir); |
| 63 | std.os.deleteTree(allocator, tmp_dir_name) catch {}; |
| 64 | allocator.free(self.zig_cache_dir); |
| 65 | allocator.free(self.zig_lib_dir); |
| 76 | 66 | self.loop.deinit(); |
| 77 | | self.arena.deinit(); |
| 78 | | self.direct_allocator.deinit(); |
| 79 | 67 | } |
| 80 | 68 | |
| 81 | 69 | fn run(self: *TestContext) !void { |
| ... | ... | @@ -99,14 +87,14 @@ const TestContext = struct { |
| 99 | 87 | ) !void { |
| 100 | 88 | var file_index_buf: [20]u8 = undefined; |
| 101 | 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); |
| 103 | 91 | |
| 104 | 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 | } |
| 107 | 95 | |
| 108 | 96 | // TODO async I/O |
| 109 | | try std.io.writeFile(&self.arena.allocator, file1_path, source); |
| 97 | try std.io.writeFile(allocator, file1_path, source); |
| 110 | 98 | |
| 111 | 99 | var module = try Module.create( |
| 112 | 100 | &self.loop, |