authorgravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-29 22:06:26-06:00
committergravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-01-29 22:22:01-06:00
logb7a236d68e042ffcf2b0642e951ecca33ed842a4
tree82e7b1f9602039be4ca878e95b74e74f7bc8900f
parentad93ad3e6077cdaa7111c7aefbfb1305ae3edfb5

Convert a bunch of page_allocator to testing.allocator


10 files changed, 23 insertions(+), 19 deletions(-)

lib/std/buf_map.zig+1
...@@ -83,6 +83,7 @@ pub const BufMap = struct {...@@ -83,6 +83,7 @@ pub const BufMap = struct {
83};83};
8484
85test "BufMap" {85test "BufMap" {
86 // TODO: uncomment and fix the leak
86 var bufmap = BufMap.init(std.heap.page_allocator);87 var bufmap = BufMap.init(std.heap.page_allocator);
87 defer bufmap.deinit();88 defer bufmap.deinit();
8889
lib/std/buf_set.zig+1-1
...@@ -65,7 +65,7 @@ pub const BufSet = struct {...@@ -65,7 +65,7 @@ pub const BufSet = struct {
65};65};
6666
67test "BufSet" {67test "BufSet" {
68 var bufset = BufSet.init(std.heap.page_allocator);68 var bufset = BufSet.init(std.testing.allocator);
69 defer bufset.deinit();69 defer bufset.deinit();
7070
71 try bufset.put("x");71 try bufset.put("x");
lib/std/build.zig+3
...@@ -1059,7 +1059,10 @@ pub const Builder = struct {...@@ -1059,7 +1059,10 @@ pub const Builder = struct {
1059};1059};
10601060
1061test "builder.findProgram compiles" {1061test "builder.findProgram compiles" {
1062 // TODO: uncomment and fix the leak
1063 // const builder = try Builder.create(std.testing.allocator, "zig", "zig-cache", "zig-cache");
1062 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");1064 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
1065 defer builder.destroy();
1063 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;1066 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
1064}1067}
10651068
lib/std/hash/auto_hash.zig+5-5
...@@ -234,8 +234,8 @@ test "hash pointer" {...@@ -234,8 +234,8 @@ test "hash pointer" {
234test "hash slice shallow" {234test "hash slice shallow" {
235 // Allocate one array dynamically so that we're assured it is not merged235 // Allocate one array dynamically so that we're assured it is not merged
236 // with the other by the optimization passes.236 // with the other by the optimization passes.
237 const array1 = try std.heap.page_allocator.create([6]u32);237 const array1 = try std.testing.allocator.create([6]u32);
238 defer std.heap.page_allocator.destroy(array1);238 defer std.testing.allocator.destroy(array1);
239 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };239 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };
240 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };240 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
241 const a = array1[0..];241 const a = array1[0..];
...@@ -250,8 +250,8 @@ test "hash slice shallow" {...@@ -250,8 +250,8 @@ test "hash slice shallow" {
250test "hash slice deep" {250test "hash slice deep" {
251 // Allocate one array dynamically so that we're assured it is not merged251 // Allocate one array dynamically so that we're assured it is not merged
252 // with the other by the optimization passes.252 // with the other by the optimization passes.
253 const array1 = try std.heap.page_allocator.create([6]u32);253 const array1 = try std.testing.allocator.create([6]u32);
254 defer std.heap.page_allocator.destroy(array1);254 defer std.testing.allocator.destroy(array1);
255 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };255 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };
256 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };256 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
257 const a = array1[0..];257 const a = array1[0..];
...@@ -278,7 +278,7 @@ test "hash struct deep" {...@@ -278,7 +278,7 @@ test "hash struct deep" {
278 }278 }
279 };279 };
280280
281 const allocator = std.heap.page_allocator;281 const allocator = std.testing.allocator;
282 const foo = try Foo.init(allocator, 123, 1.0, true);282 const foo = try Foo.init(allocator, 123, 1.0, true);
283 const bar = try Foo.init(allocator, 123, 1.0, true);283 const bar = try Foo.init(allocator, 123, 1.0, true);
284 const baz = try Foo.init(allocator, 123, 1.0, false);284 const baz = try Foo.init(allocator, 123, 1.0, false);
lib/std/hash_map.zig+3-3
...@@ -419,7 +419,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -419,7 +419,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
419}419}
420420
421test "basic hash map usage" {421test "basic hash map usage" {
422 var map = AutoHashMap(i32, i32).init(std.heap.page_allocator);422 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
423 defer map.deinit();423 defer map.deinit();
424424
425 testing.expect((try map.put(1, 11)) == null);425 testing.expect((try map.put(1, 11)) == null);
...@@ -463,7 +463,7 @@ test "basic hash map usage" {...@@ -463,7 +463,7 @@ test "basic hash map usage" {
463}463}
464464
465test "iterator hash map" {465test "iterator hash map" {
466 var reset_map = AutoHashMap(i32, i32).init(std.heap.page_allocator);466 var reset_map = AutoHashMap(i32, i32).init(std.testing.allocator);
467 defer reset_map.deinit();467 defer reset_map.deinit();
468468
469 try reset_map.putNoClobber(1, 11);469 try reset_map.putNoClobber(1, 11);
...@@ -509,7 +509,7 @@ test "iterator hash map" {...@@ -509,7 +509,7 @@ test "iterator hash map" {
509}509}
510510
511test "ensure capacity" {511test "ensure capacity" {
512 var map = AutoHashMap(i32, i32).init(std.heap.page_allocator);512 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
513 defer map.deinit();513 defer map.deinit();
514514
515 try map.ensureCapacity(20);515 try map.ensureCapacity(20);
lib/std/os/test.zig+2-2
...@@ -235,8 +235,8 @@ test "pipe" {...@@ -235,8 +235,8 @@ test "pipe" {
235}235}
236236
237test "argsAlloc" {237test "argsAlloc" {
238 var args = try std.process.argsAlloc(std.heap.page_allocator);238 var args = try std.process.argsAlloc(std.testing.allocator);
239 std.process.argsFree(std.heap.page_allocator, args);239 std.process.argsFree(std.testing.allocator, args);
240}240}
241241
242test "memfd_create" {242test "memfd_create" {
lib/std/packed_int_array.zig+2-2
...@@ -604,7 +604,7 @@ test "PackedIntArray at end of available memory" {...@@ -604,7 +604,7 @@ test "PackedIntArray at end of available memory" {
604 p: PackedArray,604 p: PackedArray,
605 };605 };
606606
607 const allocator = std.heap.page_allocator;607 const allocator = std.testing.allocator;
608608
609 var pad = try allocator.create(Padded);609 var pad = try allocator.create(Padded);
610 defer allocator.destroy(pad);610 defer allocator.destroy(pad);
...@@ -618,7 +618,7 @@ test "PackedIntSlice at end of available memory" {...@@ -618,7 +618,7 @@ test "PackedIntSlice at end of available memory" {
618 }618 }
619 const PackedSlice = PackedIntSlice(u11);619 const PackedSlice = PackedIntSlice(u11);
620620
621 const allocator = std.heap.page_allocator;621 const allocator = std.testing.allocator;
622622
623 var page = try allocator.alloc(u8, std.mem.page_size);623 var page = try allocator.alloc(u8, std.mem.page_size);
624 defer allocator.free(page);624 defer allocator.free(page);
lib/std/segmented_list.zig+1-1
...@@ -339,7 +339,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -339,7 +339,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
339}339}
340340
341test "std.SegmentedList" {341test "std.SegmentedList" {
342 var a = std.heap.page_allocator;342 var a = std.testing.allocator;
343343
344 try testSegmentedList(0, a);344 try testSegmentedList(0, a);
345 try testSegmentedList(1, a);345 try testSegmentedList(1, a);
src-self-hosted/c_tokenizer.zig+2-2
...@@ -866,7 +866,7 @@ fn expectTokens(tl: *TokenList, src: [*:0]const u8, expected: []CToken) void {...@@ -866,7 +866,7 @@ fn expectTokens(tl: *TokenList, src: [*:0]const u8, expected: []CToken) void {
866}866}
867867
868test "tokenize macro" {868test "tokenize macro" {
869 var tl = TokenList.init(std.heap.page_allocator);869 var tl = TokenList.init(std.testing.allocator);
870 defer tl.deinit();870 defer tl.deinit();
871871
872 expectTokens(&tl, "TEST(0\n", &[_]CToken{872 expectTokens(&tl, "TEST(0\n", &[_]CToken{
...@@ -904,7 +904,7 @@ test "tokenize macro" {...@@ -904,7 +904,7 @@ test "tokenize macro" {
904}904}
905905
906test "tokenize macro ops" {906test "tokenize macro ops" {
907 var tl = TokenList.init(std.heap.page_allocator);907 var tl = TokenList.init(std.testing.allocator);
908 defer tl.deinit();908 defer tl.deinit();
909909
910 expectTokens(&tl, "ADD A + B", &[_]CToken{910 expectTokens(&tl, "ADD A + B", &[_]CToken{
test/stage1/behavior/async_fn.zig+3-3
...@@ -410,8 +410,8 @@ test "heap allocated async function frame" {...@@ -410,8 +410,8 @@ test "heap allocated async function frame" {
410 var x: i32 = 42;410 var x: i32 = 42;
411411
412 fn doTheTest() !void {412 fn doTheTest() !void {
413 const frame = try std.heap.page_allocator.create(@Frame(someFunc));413 const frame = try std.testing.allocator.create(@Frame(someFunc));
414 defer std.heap.page_allocator.destroy(frame);414 defer std.testing.allocator.destroy(frame);
415415
416 expect(x == 42);416 expect(x == 42);
417 frame.* = async someFunc();417 frame.* = async someFunc();
...@@ -671,7 +671,7 @@ fn testAsyncAwaitTypicalUsage(...@@ -671,7 +671,7 @@ fn testAsyncAwaitTypicalUsage(
671 }671 }
672672
673 fn amain() !void {673 fn amain() !void {
674 const allocator = std.heap.page_allocator; // TODO once we have the debug allocator, use that, so that this can detect leaks674 const allocator = std.testing.allocator;
675 var download_frame = async fetchUrl(allocator, "https://example.com/");675 var download_frame = async fetchUrl(allocator, "https://example.com/");
676 var download_awaited = false;676 var download_awaited = false;
677 errdefer if (!download_awaited) {677 errdefer if (!download_awaited) {