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 {
8383};
8484
8585test "BufMap" {
86 // TODO: uncomment and fix the leak
8687 var bufmap = BufMap.init(std.heap.page_allocator);
8788 defer bufmap.deinit();
8889
lib/std/buf_set.zig+1-1
......@@ -65,7 +65,7 @@ pub const BufSet = struct {
6565};
6666
6767test "BufSet" {
68 var bufset = BufSet.init(std.heap.page_allocator);
68 var bufset = BufSet.init(std.testing.allocator);
6969 defer bufset.deinit();
7070
7171 try bufset.put("x");
lib/std/build.zig+3
......@@ -1059,7 +1059,10 @@ pub const Builder = struct {
10591059};
10601060
10611061test "builder.findProgram compiles" {
1062 // TODO: uncomment and fix the leak
1063 // const builder = try Builder.create(std.testing.allocator, "zig", "zig-cache", "zig-cache");
10621064 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
1065 defer builder.destroy();
10631066 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
10641067}
10651068
lib/std/hash/auto_hash.zig+5-5
......@@ -234,8 +234,8 @@ test "hash pointer" {
234234test "hash slice shallow" {
235235 // Allocate one array dynamically so that we're assured it is not merged
236236 // with the other by the optimization passes.
237 const array1 = try std.heap.page_allocator.create([6]u32);
238 defer std.heap.page_allocator.destroy(array1);
237 const array1 = try std.testing.allocator.create([6]u32);
238 defer std.testing.allocator.destroy(array1);
239239 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };
240240 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
241241 const a = array1[0..];
......@@ -250,8 +250,8 @@ test "hash slice shallow" {
250250test "hash slice deep" {
251251 // Allocate one array dynamically so that we're assured it is not merged
252252 // with the other by the optimization passes.
253 const array1 = try std.heap.page_allocator.create([6]u32);
254 defer std.heap.page_allocator.destroy(array1);
253 const array1 = try std.testing.allocator.create([6]u32);
254 defer std.testing.allocator.destroy(array1);
255255 array1.* = [_]u32{ 1, 2, 3, 4, 5, 6 };
256256 const array2 = [_]u32{ 1, 2, 3, 4, 5, 6 };
257257 const a = array1[0..];
......@@ -278,7 +278,7 @@ test "hash struct deep" {
278278 }
279279 };
280280
281 const allocator = std.heap.page_allocator;
281 const allocator = std.testing.allocator;
282282 const foo = try Foo.init(allocator, 123, 1.0, true);
283283 const bar = try Foo.init(allocator, 123, 1.0, true);
284284 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
419419}
420420
421421test "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);
423423 defer map.deinit();
424424
425425 testing.expect((try map.put(1, 11)) == null);
......@@ -463,7 +463,7 @@ test "basic hash map usage" {
463463}
464464
465465test "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);
467467 defer reset_map.deinit();
468468
469469 try reset_map.putNoClobber(1, 11);
......@@ -509,7 +509,7 @@ test "iterator hash map" {
509509}
510510
511511test "ensure capacity" {
512 var map = AutoHashMap(i32, i32).init(std.heap.page_allocator);
512 var map = AutoHashMap(i32, i32).init(std.testing.allocator);
513513 defer map.deinit();
514514
515515 try map.ensureCapacity(20);
lib/std/os/test.zig+2-2
......@@ -235,8 +235,8 @@ test "pipe" {
235235}
236236
237237test "argsAlloc" {
238 var args = try std.process.argsAlloc(std.heap.page_allocator);
239 std.process.argsFree(std.heap.page_allocator, args);
238 var args = try std.process.argsAlloc(std.testing.allocator);
239 std.process.argsFree(std.testing.allocator, args);
240240}
241241
242242test "memfd_create" {
lib/std/packed_int_array.zig+2-2
......@@ -604,7 +604,7 @@ test "PackedIntArray at end of available memory" {
604604 p: PackedArray,
605605 };
606606
607 const allocator = std.heap.page_allocator;
607 const allocator = std.testing.allocator;
608608
609609 var pad = try allocator.create(Padded);
610610 defer allocator.destroy(pad);
......@@ -618,7 +618,7 @@ test "PackedIntSlice at end of available memory" {
618618 }
619619 const PackedSlice = PackedIntSlice(u11);
620620
621 const allocator = std.heap.page_allocator;
621 const allocator = std.testing.allocator;
622622
623623 var page = try allocator.alloc(u8, std.mem.page_size);
624624 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
339339}
340340
341341test "std.SegmentedList" {
342 var a = std.heap.page_allocator;
342 var a = std.testing.allocator;
343343
344344 try testSegmentedList(0, a);
345345 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 {
866866}
867867
868868test "tokenize macro" {
869 var tl = TokenList.init(std.heap.page_allocator);
869 var tl = TokenList.init(std.testing.allocator);
870870 defer tl.deinit();
871871
872872 expectTokens(&tl, "TEST(0\n", &[_]CToken{
......@@ -904,7 +904,7 @@ test "tokenize macro" {
904904}
905905
906906test "tokenize macro ops" {
907 var tl = TokenList.init(std.heap.page_allocator);
907 var tl = TokenList.init(std.testing.allocator);
908908 defer tl.deinit();
909909
910910 expectTokens(&tl, "ADD A + B", &[_]CToken{
test/stage1/behavior/async_fn.zig+3-3
......@@ -410,8 +410,8 @@ test "heap allocated async function frame" {
410410 var x: i32 = 42;
411411
412412 fn doTheTest() !void {
413 const frame = try std.heap.page_allocator.create(@Frame(someFunc));
414 defer std.heap.page_allocator.destroy(frame);
413 const frame = try std.testing.allocator.create(@Frame(someFunc));
414 defer std.testing.allocator.destroy(frame);
415415
416416 expect(x == 42);
417417 frame.* = async someFunc();
......@@ -671,7 +671,7 @@ fn testAsyncAwaitTypicalUsage(
671671 }
672672
673673 fn amain() !void {
674 const allocator = std.heap.page_allocator; // TODO once we have the debug allocator, use that, so that this can detect leaks
674 const allocator = std.testing.allocator;
675675 var download_frame = async fetchUrl(allocator, "https://example.com/");
676676 var download_awaited = false;
677677 errdefer if (!download_awaited) {