| author | |
| committer | |
| log | 987c209b407f8379fd58381dcd3975982dfccdaf |
| tree | 6437a6aa96b60175c23a4eca8e9fad257ba440e2 |
| parent | be51511d295269851ea4128f0fd3db49fe96a661 |
it is now stateless, so the de/init are not necessary anymore28 files changed, 57 insertions(+), 177 deletions(-)
doc/docgen.zig+1-4| ... | @@ -16,10 +16,7 @@ const tmp_dir_name = "docgen_tmp"; | ... | @@ -16,10 +16,7 @@ const tmp_dir_name = "docgen_tmp"; |
| 16 | const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext; | 16 | const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext; |
| 17 | 17 | ||
| 18 | pub fn main() !void { | 18 | pub fn main() !void { |
| 19 | var direct_allocator = std.heap.DirectAllocator.init(); | 19 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 20 | defer direct_allocator.deinit(); | ||
| 21 | |||
| 22 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 23 | defer arena.deinit(); | 20 | defer arena.deinit(); |
| 24 | 21 | ||
| 25 | const allocator = &arena.allocator; | 22 | const allocator = &arena.allocator; |
doc/langref.html.in+1-4| ... | @@ -8505,10 +8505,7 @@ fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 { | ... | @@ -8505,10 +8505,7 @@ fn concat(allocator: *Allocator, a: []const u8, b: []const u8) ![]u8 { |
| 8505 | const std = @import("std"); | 8505 | const std = @import("std"); |
| 8506 | 8506 | ||
| 8507 | pub fn main() !void { | 8507 | pub fn main() !void { |
| 8508 | var direct_allocator = std.heap.DirectAllocator.init(); | 8508 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 8509 | defer direct_allocator.deinit(); | ||
| 8510 | |||
| 8511 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 8512 | defer arena.deinit(); | 8509 | defer arena.deinit(); |
| 8513 | 8510 | ||
| 8514 | const allocator = &arena.allocator; | 8511 | const allocator = &arena.allocator; |
libc/process_headers.zig+1-2| ... | @@ -707,8 +707,7 @@ const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTa | ... | @@ -707,8 +707,7 @@ const TargetToHash = std.HashMap(DestTarget, []const u8, DestTarget.hash, DestTa |
| 707 | const PathTable = std.AutoHashMap([]const u8, *TargetToHash); | 707 | const PathTable = std.AutoHashMap([]const u8, *TargetToHash); |
| 708 | 708 | ||
| 709 | pub fn main() !void { | 709 | pub fn main() !void { |
| 710 | var direct_allocator = std.heap.DirectAllocator.init(); | 710 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 711 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 712 | const allocator = &arena.allocator; | 711 | const allocator = &arena.allocator; |
| 713 | const args = try std.os.argsAlloc(allocator); | 712 | const args = try std.os.argsAlloc(allocator); |
| 714 | var search_paths = std.ArrayList([]const u8).init(allocator); | 713 | var search_paths = std.ArrayList([]const u8).init(allocator); |
src-self-hosted/dep_tokenizer.zig+2-3| ... | @@ -837,12 +837,11 @@ test "error prereq - continuation expecting end-of-line" { | ... | @@ -837,12 +837,11 @@ test "error prereq - continuation expecting end-of-line" { |
| 837 | 837 | ||
| 838 | // - tokenize input, emit textual representation, and compare to expect | 838 | // - tokenize input, emit textual representation, and compare to expect |
| 839 | fn depTokenizer(input: []const u8, expect: []const u8) !void { | 839 | fn depTokenizer(input: []const u8, expect: []const u8) !void { |
| 840 | var direct_allocator = std.heap.DirectAllocator.init(); | 840 | var arena_allocator = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 841 | var arena_allocator = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 842 | const arena = &arena_allocator.allocator; | 841 | const arena = &arena_allocator.allocator; |
| 843 | defer arena_allocator.deinit(); | 842 | defer arena_allocator.deinit(); |
| 844 | 843 | ||
| 845 | var it = Tokenizer.init(&direct_allocator.allocator, input); | 844 | var it = Tokenizer.init(arena, input); |
| 846 | var buffer = try std.Buffer.initSize(arena, 0); | 845 | var buffer = try std.Buffer.initSize(arena, 0); |
| 847 | var i: usize = 0; | 846 | var i: usize = 0; |
| 848 | while (true) { | 847 | while (true) { |
std/atomic/queue.zig+2-5| ... | @@ -152,11 +152,8 @@ const puts_per_thread = 500; | ... | @@ -152,11 +152,8 @@ const puts_per_thread = 500; |
| 152 | const put_thread_count = 3; | 152 | const put_thread_count = 3; |
| 153 | 153 | ||
| 154 | test "std.atomic.Queue" { | 154 | test "std.atomic.Queue" { |
| 155 | var direct_allocator = std.heap.DirectAllocator.init(); | 155 | var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024); |
| 156 | defer direct_allocator.deinit(); | 156 | defer std.heap.direct_allocator.free(plenty_of_memory); |
| 157 | |||
| 158 | var plenty_of_memory = try direct_allocator.allocator.alloc(u8, 300 * 1024); | ||
| 159 | defer direct_allocator.allocator.free(plenty_of_memory); | ||
| 160 | 157 | ||
| 161 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 158 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); |
| 162 | var a = &fixed_buffer_allocator.allocator; | 159 | var a = &fixed_buffer_allocator.allocator; |
std/atomic/stack.zig+2-5| ... | @@ -86,11 +86,8 @@ const puts_per_thread = 500; | ... | @@ -86,11 +86,8 @@ const puts_per_thread = 500; |
| 86 | const put_thread_count = 3; | 86 | const put_thread_count = 3; |
| 87 | 87 | ||
| 88 | test "std.atomic.stack" { | 88 | test "std.atomic.stack" { |
| 89 | var direct_allocator = std.heap.DirectAllocator.init(); | 89 | var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024); |
| 90 | defer direct_allocator.deinit(); | 90 | defer std.heap.direct_allocator.free(plenty_of_memory); |
| 91 | |||
| 92 | var plenty_of_memory = try direct_allocator.allocator.alloc(u8, 300 * 1024); | ||
| 93 | defer direct_allocator.allocator.free(plenty_of_memory); | ||
| 94 | 91 | ||
| 95 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 92 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); |
| 96 | var a = &fixed_buffer_allocator.allocator; | 93 | var a = &fixed_buffer_allocator.allocator; |
std/buf_map.zig+1-4| ... | @@ -83,10 +83,7 @@ pub const BufMap = struct { | ... | @@ -83,10 +83,7 @@ pub const BufMap = struct { |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | test "BufMap" { | 85 | test "BufMap" { |
| 86 | var direct_allocator = std.heap.DirectAllocator.init(); | 86 | var bufmap = BufMap.init(std.heap.direct_allocator); |
| 87 | defer direct_allocator.deinit(); | ||
| 88 | |||
| 89 | var bufmap = BufMap.init(&direct_allocator.allocator); | ||
| 90 | defer bufmap.deinit(); | 87 | defer bufmap.deinit(); |
| 91 | 88 | ||
| 92 | try bufmap.set("x", "1"); | 89 | try bufmap.set("x", "1"); |
std/buf_set.zig+1-4| ... | @@ -65,10 +65,7 @@ pub const BufSet = struct { | ... | @@ -65,10 +65,7 @@ pub const BufSet = struct { |
| 65 | }; | 65 | }; |
| 66 | 66 | ||
| 67 | test "BufSet" { | 67 | test "BufSet" { |
| 68 | var direct_allocator = std.heap.DirectAllocator.init(); | 68 | var bufset = BufSet.init(std.heap.direct_allocator); |
| 69 | defer direct_allocator.deinit(); | ||
| 70 | |||
| 71 | var bufset = BufSet.init(&direct_allocator.allocator); | ||
| 72 | defer bufset.deinit(); | 69 | defer bufset.deinit(); |
| 73 | 70 | ||
| 74 | try bufset.put("x"); | 71 | try bufset.put("x"); |
std/debug.zig+1-3| ... | @@ -2283,13 +2283,11 @@ var global_allocator_mem: [100 * 1024]u8 = undefined; | ... | @@ -2283,13 +2283,11 @@ var global_allocator_mem: [100 * 1024]u8 = undefined; |
| 2283 | 2283 | ||
| 2284 | /// TODO multithreaded awareness | 2284 | /// TODO multithreaded awareness |
| 2285 | var debug_info_allocator: ?*mem.Allocator = null; | 2285 | var debug_info_allocator: ?*mem.Allocator = null; |
| 2286 | var debug_info_direct_allocator: std.heap.DirectAllocator = undefined; | ||
| 2287 | var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined; | 2286 | var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined; |
| 2288 | fn getDebugInfoAllocator() *mem.Allocator { | 2287 | fn getDebugInfoAllocator() *mem.Allocator { |
| 2289 | if (debug_info_allocator) |a| return a; | 2288 | if (debug_info_allocator) |a| return a; |
| 2290 | 2289 | ||
| 2291 | debug_info_direct_allocator = std.heap.DirectAllocator.init(); | 2290 | debug_info_arena_allocator = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 2292 | debug_info_arena_allocator = std.heap.ArenaAllocator.init(&debug_info_direct_allocator.allocator); | ||
| 2293 | debug_info_allocator = &debug_info_arena_allocator.allocator; | 2291 | debug_info_allocator = &debug_info_arena_allocator.allocator; |
| 2294 | return &debug_info_arena_allocator.allocator; | 2292 | return &debug_info_arena_allocator.allocator; |
| 2295 | } | 2293 | } |
std/event/channel.zig+1-4| ... | @@ -324,10 +324,7 @@ test "std.event.Channel" { | ... | @@ -324,10 +324,7 @@ test "std.event.Channel" { |
| 324 | // https://github.com/ziglang/zig/issues/1908 | 324 | // https://github.com/ziglang/zig/issues/1908 |
| 325 | if (builtin.single_threaded) return error.SkipZigTest; | 325 | if (builtin.single_threaded) return error.SkipZigTest; |
| 326 | 326 | ||
| 327 | var da = std.heap.DirectAllocator.init(); | 327 | const allocator = std.heap.direct_allocator; |
| 328 | defer da.deinit(); | ||
| 329 | |||
| 330 | const allocator = &da.allocator; | ||
| 331 | 328 | ||
| 332 | var loop: Loop = undefined; | 329 | var loop: Loop = undefined; |
| 333 | // TODO make a multi threaded test | 330 | // TODO make a multi threaded test |
std/event/fs.zig+1-4| ... | @@ -1310,10 +1310,7 @@ const test_tmp_dir = "std_event_fs_test"; | ... | @@ -1310,10 +1310,7 @@ const test_tmp_dir = "std_event_fs_test"; |
| 1310 | // TODO this test is disabled until the coroutine rewrite is finished. | 1310 | // TODO this test is disabled until the coroutine rewrite is finished. |
| 1311 | //test "write a file, watch it, write it again" { | 1311 | //test "write a file, watch it, write it again" { |
| 1312 | // return error.SkipZigTest; | 1312 | // return error.SkipZigTest; |
| 1313 | // var da = std.heap.DirectAllocator.init(); | 1313 | // const allocator = std.heap.direct_allocator; |
| 1314 | // defer da.deinit(); | ||
| 1315 | // | ||
| 1316 | // const allocator = &da.allocator; | ||
| 1317 | // | 1314 | // |
| 1318 | // // TODO move this into event loop too | 1315 | // // TODO move this into event loop too |
| 1319 | // try os.makePath(allocator, test_tmp_dir); | 1316 | // try os.makePath(allocator, test_tmp_dir); |
std/event/future.zig+1-4| ... | @@ -88,10 +88,7 @@ test "std.event.Future" { | ... | @@ -88,10 +88,7 @@ test "std.event.Future" { |
| 88 | // https://github.com/ziglang/zig/issues/1908 | 88 | // https://github.com/ziglang/zig/issues/1908 |
| 89 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; | 89 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; |
| 90 | 90 | ||
| 91 | var da = std.heap.DirectAllocator.init(); | 91 | const allocator = std.heap.direct_allocator; |
| 92 | defer da.deinit(); | ||
| 93 | |||
| 94 | const allocator = &da.allocator; | ||
| 95 | 92 | ||
| 96 | var loop: Loop = undefined; | 93 | var loop: Loop = undefined; |
| 97 | try loop.initMultiThreaded(allocator); | 94 | try loop.initMultiThreaded(allocator); |
std/event/group.zig+1-4| ... | @@ -125,10 +125,7 @@ test "std.event.Group" { | ... | @@ -125,10 +125,7 @@ test "std.event.Group" { |
| 125 | // https://github.com/ziglang/zig/issues/1908 | 125 | // https://github.com/ziglang/zig/issues/1908 |
| 126 | if (builtin.single_threaded) return error.SkipZigTest; | 126 | if (builtin.single_threaded) return error.SkipZigTest; |
| 127 | 127 | ||
| 128 | var da = std.heap.DirectAllocator.init(); | 128 | const allocator = std.heap.direct_allocator; |
| 129 | defer da.deinit(); | ||
| 130 | |||
| 131 | const allocator = &da.allocator; | ||
| 132 | 129 | ||
| 133 | var loop: Loop = undefined; | 130 | var loop: Loop = undefined; |
| 134 | try loop.initMultiThreaded(allocator); | 131 | try loop.initMultiThreaded(allocator); |
std/event/lock.zig+1-4| ... | @@ -126,10 +126,7 @@ test "std.event.Lock" { | ... | @@ -126,10 +126,7 @@ test "std.event.Lock" { |
| 126 | // https://github.com/ziglang/zig/issues/1908 | 126 | // https://github.com/ziglang/zig/issues/1908 |
| 127 | if (builtin.single_threaded) return error.SkipZigTest; | 127 | if (builtin.single_threaded) return error.SkipZigTest; |
| 128 | 128 | ||
| 129 | var da = std.heap.DirectAllocator.init(); | 129 | const allocator = std.heap.direct_allocator; |
| 130 | defer da.deinit(); | ||
| 131 | |||
| 132 | const allocator = &da.allocator; | ||
| 133 | 130 | ||
| 134 | var loop: Loop = undefined; | 131 | var loop: Loop = undefined; |
| 135 | try loop.initMultiThreaded(allocator); | 132 | try loop.initMultiThreaded(allocator); |
std/event/loop.zig+2-8| ... | @@ -866,10 +866,7 @@ test "std.event.Loop - basic" { | ... | @@ -866,10 +866,7 @@ test "std.event.Loop - basic" { |
| 866 | // https://github.com/ziglang/zig/issues/1908 | 866 | // https://github.com/ziglang/zig/issues/1908 |
| 867 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; | 867 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; |
| 868 | 868 | ||
| 869 | var da = std.heap.DirectAllocator.init(); | 869 | const allocator = std.heap.direct_allocator; |
| 870 | defer da.deinit(); | ||
| 871 | |||
| 872 | const allocator = &da.allocator; | ||
| 873 | 870 | ||
| 874 | var loop: Loop = undefined; | 871 | var loop: Loop = undefined; |
| 875 | try loop.initMultiThreaded(allocator); | 872 | try loop.initMultiThreaded(allocator); |
| ... | @@ -882,10 +879,7 @@ test "std.event.Loop - call" { | ... | @@ -882,10 +879,7 @@ test "std.event.Loop - call" { |
| 882 | // https://github.com/ziglang/zig/issues/1908 | 879 | // https://github.com/ziglang/zig/issues/1908 |
| 883 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; | 880 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; |
| 884 | 881 | ||
| 885 | var da = std.heap.DirectAllocator.init(); | 882 | const allocator = std.heap.direct_allocator; |
| 886 | defer da.deinit(); | ||
| 887 | |||
| 888 | const allocator = &da.allocator; | ||
| 889 | 883 | ||
| 890 | var loop: Loop = undefined; | 884 | var loop: Loop = undefined; |
| 891 | try loop.initMultiThreaded(allocator); | 885 | try loop.initMultiThreaded(allocator); |
std/event/rwlock.zig+1-4| ... | @@ -215,10 +215,7 @@ test "std.event.RwLock" { | ... | @@ -215,10 +215,7 @@ test "std.event.RwLock" { |
| 215 | // https://github.com/ziglang/zig/issues/1908 | 215 | // https://github.com/ziglang/zig/issues/1908 |
| 216 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; | 216 | if (builtin.single_threaded or builtin.os != builtin.Os.linux) return error.SkipZigTest; |
| 217 | 217 | ||
| 218 | var da = std.heap.DirectAllocator.init(); | 218 | const allocator = std.heap.direct_allocator; |
| 219 | defer da.deinit(); | ||
| 220 | |||
| 221 | const allocator = &da.allocator; | ||
| 222 | 219 | ||
| 223 | var loop: Loop = undefined; | 220 | var loop: Loop = undefined; |
| 224 | try loop.initMultiThreaded(allocator); | 221 | try loop.initMultiThreaded(allocator); |
std/hash_map.zig+3-12| ... | @@ -397,10 +397,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 | ... | @@ -397,10 +397,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | test "basic hash map usage" { | 399 | test "basic hash map usage" { |
| 400 | var direct_allocator = std.heap.DirectAllocator.init(); | 400 | var map = AutoHashMap(i32, i32).init(std.heap.direct_allocator); |
| 401 | defer direct_allocator.deinit(); | ||
| 402 | |||
| 403 | var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); | ||
| 404 | defer map.deinit(); | 401 | defer map.deinit(); |
| 405 | 402 | ||
| 406 | testing.expect((try map.put(1, 11)) == null); | 403 | testing.expect((try map.put(1, 11)) == null); |
| ... | @@ -444,10 +441,7 @@ test "basic hash map usage" { | ... | @@ -444,10 +441,7 @@ test "basic hash map usage" { |
| 444 | } | 441 | } |
| 445 | 442 | ||
| 446 | test "iterator hash map" { | 443 | test "iterator hash map" { |
| 447 | var direct_allocator = std.heap.DirectAllocator.init(); | 444 | var reset_map = AutoHashMap(i32, i32).init(std.heap.direct_allocator); |
| 448 | defer direct_allocator.deinit(); | ||
| 449 | |||
| 450 | var reset_map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); | ||
| 451 | defer reset_map.deinit(); | 445 | defer reset_map.deinit(); |
| 452 | 446 | ||
| 453 | try reset_map.putNoClobber(1, 11); | 447 | try reset_map.putNoClobber(1, 11); |
| ... | @@ -491,10 +485,7 @@ test "iterator hash map" { | ... | @@ -491,10 +485,7 @@ test "iterator hash map" { |
| 491 | } | 485 | } |
| 492 | 486 | ||
| 493 | test "ensure capacity" { | 487 | test "ensure capacity" { |
| 494 | var direct_allocator = std.heap.DirectAllocator.init(); | 488 | var map = AutoHashMap(i32, i32).init(std.heap.direct_allocator); |
| 495 | defer direct_allocator.deinit(); | ||
| 496 | |||
| 497 | var map = AutoHashMap(i32, i32).init(&direct_allocator.allocator); | ||
| 498 | defer map.deinit(); | 489 | defer map.deinit(); |
| 499 | 490 | ||
| 500 | try map.ensureCapacity(20); | 491 | try map.ensureCapacity(20); |
std/heap.zig+8-22| ... | @@ -31,22 +31,14 @@ fn cShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new | ... | @@ -31,22 +31,14 @@ fn cShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new |
| 31 | 31 | ||
| 32 | /// This allocator makes a syscall directly for every allocation and free. | 32 | /// This allocator makes a syscall directly for every allocation and free. |
| 33 | /// Thread-safe and lock-free. | 33 | /// Thread-safe and lock-free. |
| 34 | pub const DirectAllocator = struct { | 34 | pub const direct_allocator = &direct_allocator_state; |
| 35 | allocator: Allocator, | 35 | var direct_allocator_state = Allocator{ |
| 36 | 36 | .reallocFn = DirectAllocator.realloc, | |
| 37 | pub fn init() DirectAllocator { | 37 | .shrinkFn = DirectAllocator.shrink, |
| 38 | return DirectAllocator{ | 38 | }; |
| 39 | .allocator = Allocator{ | ||
| 40 | .reallocFn = realloc, | ||
| 41 | .shrinkFn = shrink, | ||
| 42 | }, | ||
| 43 | }; | ||
| 44 | } | ||
| 45 | |||
| 46 | pub fn deinit(self: *DirectAllocator) void {} | ||
| 47 | 39 | ||
| 40 | const DirectAllocator = struct { | ||
| 48 | fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 { | 41 | fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 { |
| 49 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | ||
| 50 | if (n == 0) | 42 | if (n == 0) |
| 51 | return (([*]u8)(undefined))[0..0]; | 43 | return (([*]u8)(undefined))[0..0]; |
| 52 | 44 | ||
| ... | @@ -730,10 +722,7 @@ test "c_allocator" { | ... | @@ -730,10 +722,7 @@ test "c_allocator" { |
| 730 | } | 722 | } |
| 731 | 723 | ||
| 732 | test "DirectAllocator" { | 724 | test "DirectAllocator" { |
| 733 | var direct_allocator = DirectAllocator.init(); | 725 | const allocator = direct_allocator; |
| 734 | defer direct_allocator.deinit(); | ||
| 735 | |||
| 736 | const allocator = &direct_allocator.allocator; | ||
| 737 | try testAllocator(allocator); | 726 | try testAllocator(allocator); |
| 738 | try testAllocatorAligned(allocator, 16); | 727 | try testAllocatorAligned(allocator, 16); |
| 739 | try testAllocatorLargeAlignment(allocator); | 728 | try testAllocatorLargeAlignment(allocator); |
| ... | @@ -765,10 +754,7 @@ test "HeapAllocator" { | ... | @@ -765,10 +754,7 @@ test "HeapAllocator" { |
| 765 | } | 754 | } |
| 766 | 755 | ||
| 767 | test "ArenaAllocator" { | 756 | test "ArenaAllocator" { |
| 768 | var direct_allocator = DirectAllocator.init(); | 757 | var arena_allocator = ArenaAllocator.init(direct_allocator); |
| 769 | defer direct_allocator.deinit(); | ||
| 770 | |||
| 771 | var arena_allocator = ArenaAllocator.init(&direct_allocator.allocator); | ||
| 772 | defer arena_allocator.deinit(); | 758 | defer arena_allocator.deinit(); |
| 773 | 759 | ||
| 774 | try testAllocator(&arena_allocator.allocator); | 760 | try testAllocator(&arena_allocator.allocator); |
std/mutex.zig+2-5| ... | @@ -130,11 +130,8 @@ const TestContext = struct { | ... | @@ -130,11 +130,8 @@ const TestContext = struct { |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | test "std.Mutex" { | 132 | test "std.Mutex" { |
| 133 | var direct_allocator = std.heap.DirectAllocator.init(); | 133 | var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024); |
| 134 | defer direct_allocator.deinit(); | 134 | defer std.heap.direct_allocator.free(plenty_of_memory); |
| 135 | |||
| 136 | var plenty_of_memory = try direct_allocator.allocator.alloc(u8, 300 * 1024); | ||
| 137 | defer direct_allocator.allocator.free(plenty_of_memory); | ||
| 138 | 135 | ||
| 139 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 136 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); |
| 140 | var a = &fixed_buffer_allocator.allocator; | 137 | var a = &fixed_buffer_allocator.allocator; |
std/packed_int_array.zig+5-8| ... | @@ -603,8 +603,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -603,8 +603,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 603 | } | 603 | } |
| 604 | 604 | ||
| 605 | //@NOTE: Need to manually update this list as more posix os's get | 605 | //@NOTE: Need to manually update this list as more posix os's get |
| 606 | // added to DirectAllocator. Windows can be added too when DirectAllocator | 606 | // added to DirectAllocator. |
| 607 | // switches to VirtualAlloc. | ||
| 608 | 607 | ||
| 609 | //These tests prove we aren't accidentally accessing memory past | 608 | //These tests prove we aren't accidentally accessing memory past |
| 610 | // the end of the array/slice by placing it at the end of a page | 609 | // the end of the array/slice by placing it at the end of a page |
| ... | @@ -613,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" { | ... | @@ -613,7 +612,7 @@ test "PackedInt(Array/Slice)Endian" { |
| 613 | // don't account for the bounds. | 612 | // don't account for the bounds. |
| 614 | test "PackedIntArray at end of available memory" { | 613 | test "PackedIntArray at end of available memory" { |
| 615 | switch (builtin.os) { | 614 | switch (builtin.os) { |
| 616 | .linux, .macosx, .ios, .freebsd, .netbsd => {}, | 615 | .linux, .macosx, .ios, .freebsd, .netbsd, .windows => {}, |
| 617 | else => return, | 616 | else => return, |
| 618 | } | 617 | } |
| 619 | const PackedArray = PackedIntArray(u3, 8); | 618 | const PackedArray = PackedIntArray(u3, 8); |
| ... | @@ -623,8 +622,7 @@ test "PackedIntArray at end of available memory" { | ... | @@ -623,8 +622,7 @@ test "PackedIntArray at end of available memory" { |
| 623 | p: PackedArray, | 622 | p: PackedArray, |
| 624 | }; | 623 | }; |
| 625 | 624 | ||
| 626 | var da = std.heap.DirectAllocator.init(); | 625 | const allocator = std.heap.direct_allocator; |
| 627 | const allocator = &da.allocator; | ||
| 628 | 626 | ||
| 629 | var pad = try allocator.create(Padded); | 627 | var pad = try allocator.create(Padded); |
| 630 | defer allocator.destroy(pad); | 628 | defer allocator.destroy(pad); |
| ... | @@ -633,13 +631,12 @@ test "PackedIntArray at end of available memory" { | ... | @@ -633,13 +631,12 @@ test "PackedIntArray at end of available memory" { |
| 633 | 631 | ||
| 634 | test "PackedIntSlice at end of available memory" { | 632 | test "PackedIntSlice at end of available memory" { |
| 635 | switch (builtin.os) { | 633 | switch (builtin.os) { |
| 636 | .linux, .macosx, .ios, .freebsd, .netbsd => {}, | 634 | .linux, .macosx, .ios, .freebsd, .netbsd, .windows => {}, |
| 637 | else => return, | 635 | else => return, |
| 638 | } | 636 | } |
| 639 | const PackedSlice = PackedIntSlice(u11); | 637 | const PackedSlice = PackedIntSlice(u11); |
| 640 | 638 | ||
| 641 | var da = std.heap.DirectAllocator.init(); | 639 | const allocator = std.heap.direct_allocator; |
| 642 | const allocator = &da.allocator; | ||
| 643 | 640 | ||
| 644 | var page = try allocator.alloc(u8, std.mem.page_size); | 641 | var page = try allocator.alloc(u8, std.mem.page_size); |
| 645 | defer allocator.free(page); | 642 | defer allocator.free(page); |
std/segmented_list.zig+1-3| ... | @@ -334,9 +334,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type | ... | @@ -334,9 +334,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | test "std.SegmentedList" { | 336 | test "std.SegmentedList" { |
| 337 | var da = std.heap.DirectAllocator.init(); | 337 | var a = std.heap.direct_allocator; |
| 338 | defer da.deinit(); | ||
| 339 | var a = &da.allocator; | ||
| 340 | 338 | ||
| 341 | try testSegmentedList(0, a); | 339 | try testSegmentedList(0, a); |
| 342 | try testSegmentedList(1, a); | 340 | try testSegmentedList(1, a); |
std/special/build_runner.zig+1-4| ... | @@ -17,10 +17,7 @@ pub fn main() !void { | ... | @@ -17,10 +17,7 @@ pub fn main() !void { |
| 17 | // one shot program. We don't need to waste time freeing memory and finding places to squish | 17 | // one shot program. We don't need to waste time freeing memory and finding places to squish |
| 18 | // bytes into. So we free everything all at once at the very end. | 18 | // bytes into. So we free everything all at once at the very end. |
| 19 | 19 | ||
| 20 | var direct_allocator = std.heap.DirectAllocator.init(); | 20 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 21 | defer direct_allocator.deinit(); | ||
| 22 | |||
| 23 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 24 | defer arena.deinit(); | 21 | defer arena.deinit(); |
| 25 | 22 | ||
| 26 | const allocator = &arena.allocator; | 23 | const allocator = &arena.allocator; |
std/statically_initialized_mutex.zig+2-5| ... | @@ -80,11 +80,8 @@ test "std.StaticallyInitializedMutex" { | ... | @@ -80,11 +80,8 @@ test "std.StaticallyInitializedMutex" { |
| 80 | } | 80 | } |
| 81 | }; | 81 | }; |
| 82 | 82 | ||
| 83 | var direct_allocator = std.heap.DirectAllocator.init(); | 83 | var plenty_of_memory = try std.heap.direct_allocator.alloc(u8, 300 * 1024); |
| 84 | defer direct_allocator.deinit(); | 84 | defer std.heap.direct_allocator.free(plenty_of_memory); |
| 85 | |||
| 86 | var plenty_of_memory = try direct_allocator.allocator.alloc(u8, 300 * 1024); | ||
| 87 | defer direct_allocator.allocator.free(plenty_of_memory); | ||
| 88 | 85 | ||
| 89 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 86 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); |
| 90 | var a = &fixed_buffer_allocator.allocator; | 87 | var a = &fixed_buffer_allocator.allocator; |
test/cli.zig+1-4| ... | @@ -8,10 +8,7 @@ const ChildProcess = std.ChildProcess; | ... | @@ -8,10 +8,7 @@ const ChildProcess = std.ChildProcess; |
| 8 | var a: *std.mem.Allocator = undefined; | 8 | var a: *std.mem.Allocator = undefined; |
| 9 | 9 | ||
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var direct_allocator = std.heap.DirectAllocator.init(); | 11 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 12 | defer direct_allocator.deinit(); | ||
| 13 | |||
| 14 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 15 | defer arena.deinit(); | 12 | defer arena.deinit(); |
| 16 | 13 | ||
| 17 | var arg_it = process.args(); | 14 | var arg_it = process.args(); |
test/stage1/behavior/cancel.zig+2-8| ... | @@ -5,10 +5,7 @@ var defer_f2: bool = false; | ... | @@ -5,10 +5,7 @@ var defer_f2: bool = false; |
| 5 | var defer_f3: bool = false; | 5 | var defer_f3: bool = false; |
| 6 | 6 | ||
| 7 | test "cancel forwards" { | 7 | test "cancel forwards" { |
| 8 | var da = std.heap.DirectAllocator.init(); | 8 | const p = async<std.heap.direct_allocator> f1() catch unreachable; |
| 9 | defer da.deinit(); | ||
| 10 | |||
| 11 | const p = async<&da.allocator> f1() catch unreachable; | ||
| 12 | cancel p; | 9 | cancel p; |
| 13 | std.testing.expect(defer_f1); | 10 | std.testing.expect(defer_f1); |
| 14 | std.testing.expect(defer_f2); | 11 | std.testing.expect(defer_f2); |
| ... | @@ -42,10 +39,7 @@ var defer_b3: bool = false; | ... | @@ -42,10 +39,7 @@ var defer_b3: bool = false; |
| 42 | var defer_b4: bool = false; | 39 | var defer_b4: bool = false; |
| 43 | 40 | ||
| 44 | test "cancel backwards" { | 41 | test "cancel backwards" { |
| 45 | var da = std.heap.DirectAllocator.init(); | 42 | const p = async<std.heap.direct_allocator> b1() catch unreachable; |
| 46 | defer da.deinit(); | ||
| 47 | |||
| 48 | const p = async<&da.allocator> b1() catch unreachable; | ||
| 49 | cancel p; | 43 | cancel p; |
| 50 | std.testing.expect(defer_b1); | 44 | std.testing.expect(defer_b1); |
| 51 | std.testing.expect(defer_b2); | 45 | std.testing.expect(defer_b2); |
test/stage1/behavior/coroutine_await_struct.zig+1-4| ... | @@ -10,11 +10,8 @@ var await_a_promise: promise = undefined; | ... | @@ -10,11 +10,8 @@ var await_a_promise: promise = undefined; |
| 10 | var await_final_result = Foo{ .x = 0 }; | 10 | var await_final_result = Foo{ .x = 0 }; |
| 11 | 11 | ||
| 12 | test "coroutine await struct" { | 12 | test "coroutine await struct" { |
| 13 | var da = std.heap.DirectAllocator.init(); | ||
| 14 | defer da.deinit(); | ||
| 15 | |||
| 16 | await_seq('a'); | 13 | await_seq('a'); |
| 17 | const p = async<&da.allocator> await_amain() catch unreachable; | 14 | const p = async<std.heap.direct_allocator> await_amain() catch unreachable; |
| 18 | await_seq('f'); | 15 | await_seq('f'); |
| 19 | resume await_a_promise; | 16 | resume await_a_promise; |
| 20 | await_seq('i'); | 17 | await_seq('i'); |
test/stage1/behavior/coroutines.zig+10-32| ... | @@ -1,14 +1,12 @@ | ... | @@ -1,14 +1,12 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const expect = std.testing.expect; | 3 | const expect = std.testing.expect; |
| 4 | const allocator = std.heap.direct_allocator; | ||
| 4 | 5 | ||
| 5 | var x: i32 = 1; | 6 | var x: i32 = 1; |
| 6 | 7 | ||
| 7 | test "create a coroutine and cancel it" { | 8 | test "create a coroutine and cancel it" { |
| 8 | var da = std.heap.DirectAllocator.init(); | 9 | const p = try async<allocator> simpleAsyncFn(); |
| 9 | defer da.deinit(); | ||
| 10 | |||
| 11 | const p = try async<&da.allocator> simpleAsyncFn(); | ||
| 12 | comptime expect(@typeOf(p) == promise->void); | 10 | comptime expect(@typeOf(p) == promise->void); |
| 13 | cancel p; | 11 | cancel p; |
| 14 | expect(x == 2); | 12 | expect(x == 2); |
| ... | @@ -20,11 +18,8 @@ async fn simpleAsyncFn() void { | ... | @@ -20,11 +18,8 @@ async fn simpleAsyncFn() void { |
| 20 | } | 18 | } |
| 21 | 19 | ||
| 22 | test "coroutine suspend, resume, cancel" { | 20 | test "coroutine suspend, resume, cancel" { |
| 23 | var da = std.heap.DirectAllocator.init(); | ||
| 24 | defer da.deinit(); | ||
| 25 | |||
| 26 | seq('a'); | 21 | seq('a'); |
| 27 | const p = try async<&da.allocator> testAsyncSeq(); | 22 | const p = try async<allocator> testAsyncSeq(); |
| 28 | seq('c'); | 23 | seq('c'); |
| 29 | resume p; | 24 | resume p; |
| 30 | seq('f'); | 25 | seq('f'); |
| ... | @@ -49,10 +44,7 @@ fn seq(c: u8) void { | ... | @@ -49,10 +44,7 @@ fn seq(c: u8) void { |
| 49 | } | 44 | } |
| 50 | 45 | ||
| 51 | test "coroutine suspend with block" { | 46 | test "coroutine suspend with block" { |
| 52 | var da = std.heap.DirectAllocator.init(); | 47 | const p = try async<allocator> testSuspendBlock(); |
| 53 | defer da.deinit(); | ||
| 54 | |||
| 55 | const p = try async<&da.allocator> testSuspendBlock(); | ||
| 56 | std.testing.expect(!result); | 48 | std.testing.expect(!result); |
| 57 | resume a_promise; | 49 | resume a_promise; |
| 58 | std.testing.expect(result); | 50 | std.testing.expect(result); |
| ... | @@ -78,11 +70,8 @@ var await_a_promise: promise = undefined; | ... | @@ -78,11 +70,8 @@ var await_a_promise: promise = undefined; |
| 78 | var await_final_result: i32 = 0; | 70 | var await_final_result: i32 = 0; |
| 79 | 71 | ||
| 80 | test "coroutine await" { | 72 | test "coroutine await" { |
| 81 | var da = std.heap.DirectAllocator.init(); | ||
| 82 | defer da.deinit(); | ||
| 83 | |||
| 84 | await_seq('a'); | 73 | await_seq('a'); |
| 85 | const p = async<&da.allocator> await_amain() catch unreachable; | 74 | const p = async<allocator> await_amain() catch unreachable; |
| 86 | await_seq('f'); | 75 | await_seq('f'); |
| 87 | resume await_a_promise; | 76 | resume await_a_promise; |
| 88 | await_seq('i'); | 77 | await_seq('i'); |
| ... | @@ -117,11 +106,8 @@ fn await_seq(c: u8) void { | ... | @@ -117,11 +106,8 @@ fn await_seq(c: u8) void { |
| 117 | var early_final_result: i32 = 0; | 106 | var early_final_result: i32 = 0; |
| 118 | 107 | ||
| 119 | test "coroutine await early return" { | 108 | test "coroutine await early return" { |
| 120 | var da = std.heap.DirectAllocator.init(); | ||
| 121 | defer da.deinit(); | ||
| 122 | |||
| 123 | early_seq('a'); | 109 | early_seq('a'); |
| 124 | const p = async<&da.allocator> early_amain() catch @panic("out of memory"); | 110 | const p = async<allocator> early_amain() catch @panic("out of memory"); |
| 125 | early_seq('f'); | 111 | early_seq('f'); |
| 126 | expect(early_final_result == 1234); | 112 | expect(early_final_result == 1234); |
| 127 | expect(std.mem.eql(u8, early_points, "abcdef")); | 113 | expect(std.mem.eql(u8, early_points, "abcdef")); |
| ... | @@ -166,9 +152,7 @@ test "async function with dot syntax" { | ... | @@ -166,9 +152,7 @@ test "async function with dot syntax" { |
| 166 | suspend; | 152 | suspend; |
| 167 | } | 153 | } |
| 168 | }; | 154 | }; |
| 169 | var da = std.heap.DirectAllocator.init(); | 155 | const p = try async<allocator> S.foo(); |
| 170 | defer da.deinit(); | ||
| 171 | const p = try async<&da.allocator> S.foo(); | ||
| 172 | cancel p; | 156 | cancel p; |
| 173 | expect(S.y == 2); | 157 | expect(S.y == 2); |
| 174 | } | 158 | } |
| ... | @@ -179,9 +163,7 @@ test "async fn pointer in a struct field" { | ... | @@ -179,9 +163,7 @@ test "async fn pointer in a struct field" { |
| 179 | bar: async<*std.mem.Allocator> fn (*i32) void, | 163 | bar: async<*std.mem.Allocator> fn (*i32) void, |
| 180 | }; | 164 | }; |
| 181 | var foo = Foo{ .bar = simpleAsyncFn2 }; | 165 | var foo = Foo{ .bar = simpleAsyncFn2 }; |
| 182 | var da = std.heap.DirectAllocator.init(); | 166 | const p = (async<allocator> foo.bar(&data)) catch unreachable; |
| 183 | defer da.deinit(); | ||
| 184 | const p = (async<&da.allocator> foo.bar(&data)) catch unreachable; | ||
| 185 | expect(data == 2); | 167 | expect(data == 2); |
| 186 | cancel p; | 168 | cancel p; |
| 187 | expect(data == 4); | 169 | expect(data == 4); |
| ... | @@ -193,9 +175,7 @@ async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void { | ... | @@ -193,9 +175,7 @@ async<*std.mem.Allocator> fn simpleAsyncFn2(y: *i32) void { |
| 193 | } | 175 | } |
| 194 | 176 | ||
| 195 | test "async fn with inferred error set" { | 177 | test "async fn with inferred error set" { |
| 196 | var da = std.heap.DirectAllocator.init(); | 178 | const p = (async<allocator> failing()) catch unreachable; |
| 197 | defer da.deinit(); | ||
| 198 | const p = (async<&da.allocator> failing()) catch unreachable; | ||
| 199 | resume p; | 179 | resume p; |
| 200 | cancel p; | 180 | cancel p; |
| 201 | } | 181 | } |
| ... | @@ -208,9 +188,7 @@ async fn failing() !void { | ... | @@ -208,9 +188,7 @@ async fn failing() !void { |
| 208 | test "error return trace across suspend points - early return" { | 188 | test "error return trace across suspend points - early return" { |
| 209 | const p = nonFailing(); | 189 | const p = nonFailing(); |
| 210 | resume p; | 190 | resume p; |
| 211 | var da = std.heap.DirectAllocator.init(); | 191 | const p2 = try async<allocator> printTrace(p); |
| 212 | defer da.deinit(); | ||
| 213 | const p2 = try async<&da.allocator> printTrace(p); | ||
| 214 | cancel p2; | 192 | cancel p2; |
| 215 | } | 193 | } |
| 216 | 194 |
test/standalone/brace_expansion/main.zig+1-4| ... | @@ -182,10 +182,7 @@ pub fn main() !void { | ... | @@ -182,10 +182,7 @@ pub fn main() !void { |
| 182 | var stdin_file = try io.getStdIn(); | 182 | var stdin_file = try io.getStdIn(); |
| 183 | var stdout_file = try io.getStdOut(); | 183 | var stdout_file = try io.getStdOut(); |
| 184 | 184 | ||
| 185 | var direct_allocator = std.heap.DirectAllocator.init(); | 185 | var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator); |
| 186 | defer direct_allocator.deinit(); | ||
| 187 | |||
| 188 | var arena = std.heap.ArenaAllocator.init(&direct_allocator.allocator); | ||
| 189 | defer arena.deinit(); | 186 | defer arena.deinit(); |
| 190 | 187 | ||
| 191 | global_allocator = &arena.allocator; | 188 | global_allocator = &arena.allocator; |