| ... | @@ -4677,12 +4677,13 @@ test sanitizeExampleName { | ... | @@ -4677,12 +4677,13 @@ test sanitizeExampleName { |
| 4677 | const Templates = struct { | 4677 | const Templates = struct { |
| 4678 | zig_lib_directory: Cache.Directory, | 4678 | zig_lib_directory: Cache.Directory, |
| 4679 | dir: Io.Dir, | 4679 | dir: Io.Dir, |
| 4680 | buffer: std.array_list.Managed(u8), | 4680 | buffer: std.ArrayList(u8), |
| | 4681 | gpa: Allocator, |
| 4681 | | 4682 | |
| 4682 | fn deinit(templates: *Templates, io: Io) void { | 4683 | fn deinit(templates: *Templates, io: Io) void { |
| 4683 | templates.zig_lib_directory.handle.close(io); | 4684 | templates.zig_lib_directory.handle.close(io); |
| 4684 | templates.dir.close(io); | 4685 | templates.dir.close(io); |
| 4685 | templates.buffer.deinit(); | 4686 | templates.buffer.deinit(templates.gpa); |
| 4686 | templates.* = undefined; | 4687 | templates.* = undefined; |
| 4687 | } | 4688 | } |
| 4688 | | 4689 | |
| ... | @@ -4705,29 +4706,30 @@ const Templates = struct { | ... | @@ -4705,29 +4706,30 @@ const Templates = struct { |
| 4705 | const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| { | 4706 | const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| { |
| 4706 | fatal("unable to read template file {q}: {t}", .{ template_path, err }); | 4707 | fatal("unable to read template file {q}: {t}", .{ template_path, err }); |
| 4707 | }; | 4708 | }; |
| | 4709 | const gpa = templates.gpa; |
| 4708 | templates.buffer.clearRetainingCapacity(); | 4710 | templates.buffer.clearRetainingCapacity(); |
| 4709 | try templates.buffer.ensureUnusedCapacity(contents.len); | 4711 | try templates.buffer.ensureUnusedCapacity(gpa, contents.len); |
| 4710 | var i: usize = 0; | 4712 | var i: usize = 0; |
| 4711 | while (i < contents.len) { | 4713 | while (i < contents.len) { |
| 4712 | if (contents[i] == '_' or contents[i] == '.') { | 4714 | if (contents[i] == '_' or contents[i] == '.') { |
| 4713 | // Both '_' and '.' are allowed because depending on the context | 4715 | // Both '_' and '.' are allowed because depending on the context |
| 4714 | // one prefix will be valid, while the other might not. | 4716 | // one prefix will be valid, while the other might not. |
| 4715 | if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) { | 4717 | if (std.mem.startsWith(u8, contents[i + 1 ..], "NAME")) { |
| 4716 | try templates.buffer.appendSlice(root_name); | 4718 | try templates.buffer.appendSlice(gpa, root_name); |
| 4717 | i += "_NAME".len; | 4719 | i += "_NAME".len; |
| 4718 | continue; | 4720 | continue; |
| 4719 | } else if (std.mem.startsWith(u8, contents[i + 1 ..], "FINGERPRINT")) { | 4721 | } else if (std.mem.startsWith(u8, contents[i + 1 ..], "FINGERPRINT")) { |
| 4720 | try templates.buffer.print("0x{x}", .{fingerprint.int()}); | 4722 | try templates.buffer.print(gpa, "0x{x}", .{fingerprint.int()}); |
| 4721 | i += "_FINGERPRINT".len; | 4723 | i += "_FINGERPRINT".len; |
| 4722 | continue; | 4724 | continue; |
| 4723 | } else if (std.mem.startsWith(u8, contents[i + 1 ..], "ZIGVER")) { | 4725 | } else if (std.mem.startsWith(u8, contents[i + 1 ..], "ZIGVER")) { |
| 4724 | try templates.buffer.appendSlice(builtin.zig_version_string); | 4726 | try templates.buffer.appendSlice(gpa, builtin.zig_version_string); |
| 4725 | i += "_ZIGVER".len; | 4727 | i += "_ZIGVER".len; |
| 4726 | continue; | 4728 | continue; |
| 4727 | } | 4729 | } |
| 4728 | } | 4730 | } |
| 4729 | | 4731 | |
| 4730 | try templates.buffer.append(contents[i]); | 4732 | try templates.buffer.append(gpa, contents[i]); |
| 4731 | i += 1; | 4733 | i += 1; |
| 4732 | } | 4734 | } |
| 4733 | | 4735 | |
| ... | @@ -4748,7 +4750,8 @@ const Templates = struct { | ... | @@ -4748,7 +4750,8 @@ const Templates = struct { |
| 4748 | return .{ | 4750 | return .{ |
| 4749 | .zig_lib_directory = zig_lib_directory, | 4751 | .zig_lib_directory = zig_lib_directory, |
| 4750 | .dir = template_dir, | 4752 | .dir = template_dir, |
| 4751 | .buffer = std.array_list.Managed(u8).init(gpa), | 4753 | .buffer = .empty, |
| | 4754 | .gpa = gpa, |
| 4752 | }; | 4755 | }; |
| 4753 | } | 4756 | } |
| 4754 | | 4757 | |