| author | |
| committer | |
| log | 71db8df5480f4d849480267574cd5491066e3868 |
| tree | 1842ce3024d7254022c66d5a00c5e53488fcbeb8 |
| parent | 457c0f0a7e424177e7d8d00f4429da292b7c67d5 |
11 files changed, 100 insertions(+), 122 deletions(-)
src-self-hosted/module.zig+11-13| ... | ... | @@ -110,11 +110,12 @@ pub const Module = struct { |
| 110 | 110 | parent: ?*CliPkg, |
| 111 | 111 | |
| 112 | 112 | pub fn init(allocator: *mem.Allocator, name: []const u8, path: []const u8, parent: ?*CliPkg) !*CliPkg { |
| 113 | var pkg = try allocator.create(CliPkg); | |
| 114 | pkg.name = name; | |
| 115 | pkg.path = path; | |
| 116 | pkg.children = ArrayList(*CliPkg).init(allocator); | |
| 117 | pkg.parent = parent; | |
| 113 | var pkg = try allocator.create(CliPkg{ | |
| 114 | .name = name, | |
| 115 | .path = path, | |
| 116 | .children = ArrayList(*CliPkg).init(allocator), | |
| 117 | .parent = parent | |
| 118 | }); | |
| 118 | 119 | return pkg; |
| 119 | 120 | } |
| 120 | 121 | |
| ... | ... | @@ -139,10 +140,7 @@ pub const Module = struct { |
| 139 | 140 | const builder = c.LLVMCreateBuilderInContext(context) orelse return error.OutOfMemory; |
| 140 | 141 | errdefer c.LLVMDisposeBuilder(builder); |
| 141 | 142 | |
| 142 | const module_ptr = try allocator.create(Module); | |
| 143 | errdefer allocator.destroy(module_ptr); | |
| 144 | ||
| 145 | module_ptr.* = Module{ | |
| 143 | const module_ptr = try allocator.create(Module{ | |
| 146 | 144 | .allocator = allocator, |
| 147 | 145 | .name = name_buffer, |
| 148 | 146 | .root_src_path = root_src_path, |
| ... | ... | @@ -196,7 +194,8 @@ pub const Module = struct { |
| 196 | 194 | .test_filters = [][]const u8{}, |
| 197 | 195 | .test_name_prefix = null, |
| 198 | 196 | .emit_file_type = Emit.Binary, |
| 199 | }; | |
| 197 | }); | |
| 198 | errdefer allocator.destroy(module_ptr); | |
| 200 | 199 | return module_ptr; |
| 201 | 200 | } |
| 202 | 201 | |
| ... | ... | @@ -279,13 +278,12 @@ pub const Module = struct { |
| 279 | 278 | } |
| 280 | 279 | } |
| 281 | 280 | |
| 282 | const link_lib = try self.allocator.create(LinkLib); | |
| 283 | link_lib.* = LinkLib{ | |
| 281 | const link_lib = try self.allocator.create(LinkLib{ | |
| 284 | 282 | .name = name, |
| 285 | 283 | .path = null, |
| 286 | 284 | .provided_explicitly = provided_explicitly, |
| 287 | 285 | .symbols = ArrayList([]u8).init(self.allocator), |
| 288 | }; | |
| 286 | }); | |
| 289 | 287 | try self.link_libs_list.append(link_lib); |
| 290 | 288 | if (is_libc) { |
| 291 | 289 | self.libc_link_lib = link_lib; |
std/atomic/queue.zig+4-2| ... | ... | @@ -114,8 +114,10 @@ fn startPuts(ctx: *Context) u8 { |
| 114 | 114 | while (put_count != 0) : (put_count -= 1) { |
| 115 | 115 | std.os.time.sleep(0, 1); // let the os scheduler be our fuzz |
| 116 | 116 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 117 | const node = ctx.allocator.create(Queue(i32).Node) catch unreachable; | |
| 118 | node.data = x; | |
| 117 | const node = ctx.allocator.create(Queue(i32).Node{ | |
| 118 | .next = null, | |
| 119 | .data = x | |
| 120 | }) catch unreachable; | |
| 119 | 121 | ctx.queue.put(node); |
| 120 | 122 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 121 | 123 | } |
std/atomic/stack.zig+4-2| ... | ... | @@ -117,8 +117,10 @@ fn startPuts(ctx: *Context) u8 { |
| 117 | 117 | while (put_count != 0) : (put_count -= 1) { |
| 118 | 118 | std.os.time.sleep(0, 1); // let the os scheduler be our fuzz |
| 119 | 119 | const x = @bitCast(i32, r.random.scalar(u32)); |
| 120 | const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; | |
| 121 | node.data = x; | |
| 120 | const node = ctx.allocator.create(Stack(i32).Node{ | |
| 121 | .next = null, | |
| 122 | .data = x | |
| 123 | }) catch unreachable; | |
| 122 | 124 | ctx.stack.push(node); |
| 123 | 125 | _ = @atomicRmw(isize, &ctx.put_sum, builtin.AtomicRmwOp.Add, x, AtomicOrder.SeqCst); |
| 124 | 126 | } |
std/build.zig+20-35| ... | ... | @@ -158,8 +158,7 @@ pub const Builder = struct { |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | pub fn addTest(self: *Builder, root_src: []const u8) *TestStep { |
| 161 | const test_step = self.allocator.create(TestStep) catch unreachable; | |
| 162 | test_step.* = TestStep.init(self, root_src); | |
| 161 | const test_step = self.allocator.create(TestStep.init(self, root_src)) catch unreachable; | |
| 163 | 162 | return test_step; |
| 164 | 163 | } |
| 165 | 164 | |
| ... | ... | @@ -191,21 +190,18 @@ pub const Builder = struct { |
| 191 | 190 | } |
| 192 | 191 | |
| 193 | 192 | pub fn addWriteFile(self: *Builder, file_path: []const u8, data: []const u8) *WriteFileStep { |
| 194 | const write_file_step = self.allocator.create(WriteFileStep) catch unreachable; | |
| 195 | write_file_step.* = WriteFileStep.init(self, file_path, data); | |
| 193 | const write_file_step = self.allocator.create(WriteFileStep.init(self, file_path, data)) catch unreachable; | |
| 196 | 194 | return write_file_step; |
| 197 | 195 | } |
| 198 | 196 | |
| 199 | 197 | pub fn addLog(self: *Builder, comptime format: []const u8, args: ...) *LogStep { |
| 200 | 198 | const data = self.fmt(format, args); |
| 201 | const log_step = self.allocator.create(LogStep) catch unreachable; | |
| 202 | log_step.* = LogStep.init(self, data); | |
| 199 | const log_step = self.allocator.create(LogStep.init(self, data)) catch unreachable; | |
| 203 | 200 | return log_step; |
| 204 | 201 | } |
| 205 | 202 | |
| 206 | 203 | pub fn addRemoveDirTree(self: *Builder, dir_path: []const u8) *RemoveDirStep { |
| 207 | const remove_dir_step = self.allocator.create(RemoveDirStep) catch unreachable; | |
| 208 | remove_dir_step.* = RemoveDirStep.init(self, dir_path); | |
| 204 | const remove_dir_step = self.allocator.create(RemoveDirStep.init(self, dir_path)) catch unreachable; | |
| 209 | 205 | return remove_dir_step; |
| 210 | 206 | } |
| 211 | 207 | |
| ... | ... | @@ -404,11 +400,10 @@ pub const Builder = struct { |
| 404 | 400 | } |
| 405 | 401 | |
| 406 | 402 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { |
| 407 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; | |
| 408 | step_info.* = TopLevelStep{ | |
| 403 | const step_info = self.allocator.create(TopLevelStep{ | |
| 409 | 404 | .step = Step.initNoOp(name, self.allocator), |
| 410 | 405 | .description = description, |
| 411 | }; | |
| 406 | }) catch unreachable; | |
| 412 | 407 | self.top_level_steps.append(step_info) catch unreachable; |
| 413 | 408 | return &step_info.step; |
| 414 | 409 | } |
| ... | ... | @@ -598,8 +593,7 @@ pub const Builder = struct { |
| 598 | 593 | const full_dest_path = os.path.resolve(self.allocator, self.prefix, dest_rel_path) catch unreachable; |
| 599 | 594 | self.pushInstalledFile(full_dest_path); |
| 600 | 595 | |
| 601 | const install_step = self.allocator.create(InstallFileStep) catch unreachable; | |
| 602 | install_step.* = InstallFileStep.init(self, src_path, full_dest_path); | |
| 596 | const install_step = self.allocator.create(InstallFileStep.init(self, src_path, full_dest_path)) catch unreachable; | |
| 603 | 597 | return install_step; |
| 604 | 598 | } |
| 605 | 599 | |
| ... | ... | @@ -837,51 +831,43 @@ pub const LibExeObjStep = struct { |
| 837 | 831 | }; |
| 838 | 832 | |
| 839 | 833 | pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8, ver: *const Version) *LibExeObjStep { |
| 840 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 841 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, false, ver); | |
| 834 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, false, ver)) catch unreachable; | |
| 842 | 835 | return self; |
| 843 | 836 | } |
| 844 | 837 | |
| 845 | 838 | pub fn createCSharedLibrary(builder: *Builder, name: []const u8, version: *const Version) *LibExeObjStep { |
| 846 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 847 | self.* = initC(builder, name, Kind.Lib, version, false); | |
| 839 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, version, false)) catch unreachable; | |
| 848 | 840 | return self; |
| 849 | 841 | } |
| 850 | 842 | |
| 851 | 843 | pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 852 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 853 | self.* = initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0)); | |
| 844 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Lib, true, builder.version(0, 0, 0))) catch unreachable; | |
| 854 | 845 | return self; |
| 855 | 846 | } |
| 856 | 847 | |
| 857 | 848 | pub fn createCStaticLibrary(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 858 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 859 | self.* = initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true); | |
| 849 | const self = builder.allocator.create(initC(builder, name, Kind.Lib, builder.version(0, 0, 0), true)) catch unreachable; | |
| 860 | 850 | return self; |
| 861 | 851 | } |
| 862 | 852 | |
| 863 | 853 | pub fn createObject(builder: *Builder, name: []const u8, root_src: []const u8) *LibExeObjStep { |
| 864 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 865 | self.* = initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0)); | |
| 854 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Obj, false, builder.version(0, 0, 0))) catch unreachable; | |
| 866 | 855 | return self; |
| 867 | 856 | } |
| 868 | 857 | |
| 869 | 858 | pub fn createCObject(builder: *Builder, name: []const u8, src: []const u8) *LibExeObjStep { |
| 870 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 871 | self.* = initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false); | |
| 859 | const self = builder.allocator.create(initC(builder, name, Kind.Obj, builder.version(0, 0, 0), false)) catch unreachable; | |
| 872 | 860 | self.object_src = src; |
| 873 | 861 | return self; |
| 874 | 862 | } |
| 875 | 863 | |
| 876 | 864 | pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep { |
| 877 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 878 | self.* = initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0)); | |
| 865 | const self = builder.allocator.create(initExtraArgs(builder, name, root_src, Kind.Exe, false, builder.version(0, 0, 0))) catch unreachable; | |
| 879 | 866 | return self; |
| 880 | 867 | } |
| 881 | 868 | |
| 882 | 869 | pub fn createCExecutable(builder: *Builder, name: []const u8) *LibExeObjStep { |
| 883 | const self = builder.allocator.create(LibExeObjStep) catch unreachable; | |
| 884 | self.* = initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false); | |
| 870 | const self = builder.allocator.create(initC(builder, name, Kind.Exe, builder.version(0, 0, 0), false)) catch unreachable; | |
| 885 | 871 | return self; |
| 886 | 872 | } |
| 887 | 873 | |
| ... | ... | @@ -1748,14 +1734,14 @@ pub const CommandStep = struct { |
| 1748 | 1734 | |
| 1749 | 1735 | /// ::argv is copied. |
| 1750 | 1736 | pub fn create(builder: *Builder, cwd: ?[]const u8, env_map: *const BufMap, argv: []const []const u8) *CommandStep { |
| 1751 | const self = builder.allocator.create(CommandStep) catch unreachable; | |
| 1752 | self.* = CommandStep{ | |
| 1737 | const self = builder.allocator.create(CommandStep{ | |
| 1753 | 1738 | .builder = builder, |
| 1754 | 1739 | .step = Step.init(argv[0], builder.allocator, make), |
| 1755 | 1740 | .argv = builder.allocator.alloc([]u8, argv.len) catch unreachable, |
| 1756 | 1741 | .cwd = cwd, |
| 1757 | 1742 | .env_map = env_map, |
| 1758 | }; | |
| 1743 | }) catch unreachable; | |
| 1744 | ||
| 1759 | 1745 | mem.copy([]const u8, self.argv, argv); |
| 1760 | 1746 | self.step.name = self.argv[0]; |
| 1761 | 1747 | return self; |
| ... | ... | @@ -1778,18 +1764,17 @@ const InstallArtifactStep = struct { |
| 1778 | 1764 | const Self = this; |
| 1779 | 1765 | |
| 1780 | 1766 | pub fn create(builder: *Builder, artifact: *LibExeObjStep) *Self { |
| 1781 | const self = builder.allocator.create(Self) catch unreachable; | |
| 1782 | 1767 | const dest_dir = switch (artifact.kind) { |
| 1783 | 1768 | LibExeObjStep.Kind.Obj => unreachable, |
| 1784 | 1769 | LibExeObjStep.Kind.Exe => builder.exe_dir, |
| 1785 | 1770 | LibExeObjStep.Kind.Lib => builder.lib_dir, |
| 1786 | 1771 | }; |
| 1787 | self.* = Self{ | |
| 1772 | const self = builder.allocator.create(Self{ | |
| 1788 | 1773 | .builder = builder, |
| 1789 | 1774 | .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make), |
| 1790 | 1775 | .artifact = artifact, |
| 1791 | 1776 | .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable, |
| 1792 | }; | |
| 1777 | }) catch unreachable; | |
| 1793 | 1778 | self.step.dependOn(&artifact.step); |
| 1794 | 1779 | builder.pushInstalledFile(self.dest_file); |
| 1795 | 1780 | if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) { |
std/debug/index.zig+7-10| ... | ... | @@ -249,9 +249,7 @@ fn printSourceAtAddress(debug_info: *ElfStackTrace, out_stream: var, address: us |
| 249 | 249 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 250 | 250 | switch (builtin.object_format) { |
| 251 | 251 | builtin.ObjectFormat.elf => { |
| 252 | const st = try allocator.create(ElfStackTrace); | |
| 253 | errdefer allocator.destroy(st); | |
| 254 | st.* = ElfStackTrace{ | |
| 252 | const st = try allocator.create(ElfStackTrace{ | |
| 255 | 253 | .self_exe_file = undefined, |
| 256 | 254 | .elf = undefined, |
| 257 | 255 | .debug_info = undefined, |
| ... | ... | @@ -261,7 +259,8 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 261 | 259 | .debug_ranges = null, |
| 262 | 260 | .abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator), |
| 263 | 261 | .compile_unit_list = ArrayList(CompileUnit).init(allocator), |
| 264 | }; | |
| 262 | }); | |
| 263 | errdefer allocator.destroy(st); | |
| 265 | 264 | st.self_exe_file = try os.openSelfExe(); |
| 266 | 265 | errdefer st.self_exe_file.close(); |
| 267 | 266 | |
| ... | ... | @@ -280,11 +279,10 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) !*ElfStackTrace { |
| 280 | 279 | var exe_file = try os.openSelfExe(); |
| 281 | 280 | defer exe_file.close(); |
| 282 | 281 | |
| 283 | const st = try allocator.create(ElfStackTrace); | |
| 282 | const st = try allocator.create(ElfStackTrace{ | |
| 283 | .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) | |
| 284 | }); | |
| 284 | 285 | errdefer allocator.destroy(st); |
| 285 | ||
| 286 | st.* = ElfStackTrace{ .symbol_table = try macho.loadSymbols(allocator, &io.FileInStream.init(&exe_file)) }; | |
| 287 | ||
| 288 | 286 | return st; |
| 289 | 287 | }, |
| 290 | 288 | builtin.ObjectFormat.coff => { |
| ... | ... | @@ -974,8 +972,7 @@ fn scanAllCompileUnits(st: *ElfStackTrace) !void { |
| 974 | 972 | |
| 975 | 973 | try st.self_exe_file.seekTo(compile_unit_pos); |
| 976 | 974 | |
| 977 | const compile_unit_die = try st.allocator().create(Die); | |
| 978 | compile_unit_die.* = try parseDie(st, abbrev_table, is_64); | |
| 975 | const compile_unit_die = try st.allocator().create( try parseDie(st, abbrev_table, is_64) ); | |
| 979 | 976 | |
| 980 | 977 | if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo; |
| 981 | 978 |
std/heap.zig+1-1| ... | ... | @@ -407,7 +407,7 @@ fn testAllocator(allocator: *mem.Allocator) !void { |
| 407 | 407 | var slice = try allocator.alloc(*i32, 100); |
| 408 | 408 | |
| 409 | 409 | for (slice) |*item, i| { |
| 410 | item.* = try allocator.create(i32); | |
| 410 | item.* = try allocator.create(i32(0)); | |
| 411 | 411 | item.*.* = @intCast(i32, i); |
| 412 | 412 | } |
| 413 | 413 |
std/io.zig+3-5| ... | ... | @@ -414,14 +414,12 @@ pub const BufferedAtomicFile = struct { |
| 414 | 414 | |
| 415 | 415 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 416 | 416 | // TODO with well defined copy elision we don't need this allocation |
| 417 | var self = try allocator.create(BufferedAtomicFile); | |
| 418 | errdefer allocator.destroy(self); | |
| 419 | ||
| 420 | self.* = BufferedAtomicFile{ | |
| 417 | var self = try allocator.create(BufferedAtomicFile{ | |
| 421 | 418 | .atomic_file = undefined, |
| 422 | 419 | .file_stream = undefined, |
| 423 | 420 | .buffered_stream = undefined, |
| 424 | }; | |
| 421 | }); | |
| 422 | errdefer allocator.destroy(self); | |
| 425 | 423 | |
| 426 | 424 | self.atomic_file = try os.AtomicFile.init(allocator, dest_path, os.default_file_mode); |
| 427 | 425 | errdefer self.atomic_file.deinit(); |
std/linked_list.zig+5-1| ... | ... | @@ -193,7 +193,11 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 193 | 193 | /// A pointer to the new node. |
| 194 | 194 | pub fn allocateNode(list: *Self, allocator: *Allocator) !*Node { |
| 195 | 195 | comptime assert(!isIntrusive()); |
| 196 | return allocator.create(Node); | |
| 196 | return allocator.create(Node{ | |
| 197 | .prev = null, | |
| 198 | .next = null, | |
| 199 | .data = undefined | |
| 200 | }); | |
| 197 | 201 | } |
| 198 | 202 | |
| 199 | 203 | /// Deallocate a node. |
std/os/child_process.zig+3-6| ... | ... | @@ -85,10 +85,7 @@ pub const ChildProcess = struct { |
| 85 | 85 | /// First argument in argv is the executable. |
| 86 | 86 | /// On success must call deinit. |
| 87 | 87 | pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess { |
| 88 | const child = try allocator.create(ChildProcess); | |
| 89 | errdefer allocator.destroy(child); | |
| 90 | ||
| 91 | child.* = ChildProcess{ | |
| 88 | const child = try allocator.create(ChildProcess{ | |
| 92 | 89 | .allocator = allocator, |
| 93 | 90 | .argv = argv, |
| 94 | 91 | .pid = undefined, |
| ... | ... | @@ -109,8 +106,8 @@ pub const ChildProcess = struct { |
| 109 | 106 | .stdin_behavior = StdIo.Inherit, |
| 110 | 107 | .stdout_behavior = StdIo.Inherit, |
| 111 | 108 | .stderr_behavior = StdIo.Inherit, |
| 112 | }; | |
| 113 | ||
| 109 | }); | |
| 110 | errdefer allocator.destroy(child); | |
| 114 | 111 | return child; |
| 115 | 112 | } |
| 116 | 113 |
std/os/index.zig+5-2| ... | ... | @@ -2582,8 +2582,11 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread |
| 2582 | 2582 | const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory; |
| 2583 | 2583 | errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); |
| 2584 | 2584 | const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; |
| 2585 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; | |
| 2586 | outer_context.inner = context; | |
| 2585 | const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext{ | |
| 2586 | .thread = undefined, | |
| 2587 | .inner = context | |
| 2588 | }) catch unreachable; | |
| 2589 | ||
| 2587 | 2590 | outer_context.thread.data.heap_handle = heap_handle; |
| 2588 | 2591 | outer_context.thread.data.alloc_start = bytes_ptr; |
| 2589 | 2592 |
test/tests.zig+37-45| ... | ... | @@ -48,13 +48,12 @@ const test_targets = []TestTarget{ |
| 48 | 48 | const max_stdout_size = 1 * 1024 * 1024; // 1 MB |
| 49 | 49 | |
| 50 | 50 | pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 51 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 52 | cases.* = CompareOutputContext{ | |
| 51 | const cases = b.allocator.create(CompareOutputContext{ | |
| 53 | 52 | .b = b, |
| 54 | 53 | .step = b.step("test-compare-output", "Run the compare output tests"), |
| 55 | 54 | .test_index = 0, |
| 56 | 55 | .test_filter = test_filter, |
| 57 | }; | |
| 56 | }) catch unreachable; | |
| 58 | 57 | |
| 59 | 58 | compare_output.addCases(cases); |
| 60 | 59 | |
| ... | ... | @@ -62,13 +61,12 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8) *build |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 65 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 66 | cases.* = CompareOutputContext{ | |
| 64 | const cases = b.allocator.create(CompareOutputContext{ | |
| 67 | 65 | .b = b, |
| 68 | 66 | .step = b.step("test-runtime-safety", "Run the runtime safety tests"), |
| 69 | 67 | .test_index = 0, |
| 70 | 68 | .test_filter = test_filter, |
| 71 | }; | |
| 69 | }) catch unreachable; | |
| 72 | 70 | |
| 73 | 71 | runtime_safety.addCases(cases); |
| 74 | 72 | |
| ... | ... | @@ -76,13 +74,12 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8) *build |
| 76 | 74 | } |
| 77 | 75 | |
| 78 | 76 | pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 79 | const cases = b.allocator.create(CompileErrorContext) catch unreachable; | |
| 80 | cases.* = CompileErrorContext{ | |
| 77 | const cases = b.allocator.create(CompileErrorContext{ | |
| 81 | 78 | .b = b, |
| 82 | 79 | .step = b.step("test-compile-errors", "Run the compile error tests"), |
| 83 | 80 | .test_index = 0, |
| 84 | 81 | .test_filter = test_filter, |
| 85 | }; | |
| 82 | }) catch unreachable; | |
| 86 | 83 | |
| 87 | 84 | compile_errors.addCases(cases); |
| 88 | 85 | |
| ... | ... | @@ -90,13 +87,12 @@ pub fn addCompileErrorTests(b: *build.Builder, test_filter: ?[]const u8) *build. |
| 90 | 87 | } |
| 91 | 88 | |
| 92 | 89 | pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 93 | const cases = b.allocator.create(BuildExamplesContext) catch unreachable; | |
| 94 | cases.* = BuildExamplesContext{ | |
| 90 | const cases = b.allocator.create(BuildExamplesContext{ | |
| 95 | 91 | .b = b, |
| 96 | 92 | .step = b.step("test-build-examples", "Build the examples"), |
| 97 | 93 | .test_index = 0, |
| 98 | 94 | .test_filter = test_filter, |
| 99 | }; | |
| 95 | }) catch unreachable; | |
| 100 | 96 | |
| 101 | 97 | build_examples.addCases(cases); |
| 102 | 98 | |
| ... | ... | @@ -104,13 +100,12 @@ pub fn addBuildExampleTests(b: *build.Builder, test_filter: ?[]const u8) *build. |
| 104 | 100 | } |
| 105 | 101 | |
| 106 | 102 | pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 107 | const cases = b.allocator.create(CompareOutputContext) catch unreachable; | |
| 108 | cases.* = CompareOutputContext{ | |
| 103 | const cases = b.allocator.create(CompareOutputContext{ | |
| 109 | 104 | .b = b, |
| 110 | 105 | .step = b.step("test-asm-link", "Run the assemble and link tests"), |
| 111 | 106 | .test_index = 0, |
| 112 | 107 | .test_filter = test_filter, |
| 113 | }; | |
| 108 | }) catch unreachable; | |
| 114 | 109 | |
| 115 | 110 | assemble_and_link.addCases(cases); |
| 116 | 111 | |
| ... | ... | @@ -118,13 +113,12 @@ pub fn addAssembleAndLinkTests(b: *build.Builder, test_filter: ?[]const u8) *bui |
| 118 | 113 | } |
| 119 | 114 | |
| 120 | 115 | pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 121 | const cases = b.allocator.create(TranslateCContext) catch unreachable; | |
| 122 | cases.* = TranslateCContext{ | |
| 116 | const cases = b.allocator.create(TranslateCContext{ | |
| 123 | 117 | .b = b, |
| 124 | 118 | .step = b.step("test-translate-c", "Run the C transation tests"), |
| 125 | 119 | .test_index = 0, |
| 126 | 120 | .test_filter = test_filter, |
| 127 | }; | |
| 121 | }) catch unreachable; | |
| 128 | 122 | |
| 129 | 123 | translate_c.addCases(cases); |
| 130 | 124 | |
| ... | ... | @@ -132,13 +126,12 @@ pub fn addTranslateCTests(b: *build.Builder, test_filter: ?[]const u8) *build.St |
| 132 | 126 | } |
| 133 | 127 | |
| 134 | 128 | pub fn addGenHTests(b: *build.Builder, test_filter: ?[]const u8) *build.Step { |
| 135 | const cases = b.allocator.create(GenHContext) catch unreachable; | |
| 136 | cases.* = GenHContext{ | |
| 129 | const cases = b.allocator.create(GenHContext{ | |
| 137 | 130 | .b = b, |
| 138 | 131 | .step = b.step("test-gen-h", "Run the C header file generation tests"), |
| 139 | 132 | .test_index = 0, |
| 140 | 133 | .test_filter = test_filter, |
| 141 | }; | |
| 134 | }) catch unreachable; | |
| 142 | 135 | |
| 143 | 136 | gen_h.addCases(cases); |
| 144 | 137 | |
| ... | ... | @@ -240,8 +233,7 @@ pub const CompareOutputContext = struct { |
| 240 | 233 | |
| 241 | 234 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8, expected_output: []const u8, cli_args: []const []const u8) *RunCompareOutputStep { |
| 242 | 235 | const allocator = context.b.allocator; |
| 243 | const ptr = allocator.create(RunCompareOutputStep) catch unreachable; | |
| 244 | ptr.* = RunCompareOutputStep{ | |
| 236 | const ptr = allocator.create(RunCompareOutputStep{ | |
| 245 | 237 | .context = context, |
| 246 | 238 | .exe_path = exe_path, |
| 247 | 239 | .name = name, |
| ... | ... | @@ -249,7 +241,7 @@ pub const CompareOutputContext = struct { |
| 249 | 241 | .test_index = context.test_index, |
| 250 | 242 | .step = build.Step.init("RunCompareOutput", allocator, make), |
| 251 | 243 | .cli_args = cli_args, |
| 252 | }; | |
| 244 | }) catch unreachable; | |
| 253 | 245 | context.test_index += 1; |
| 254 | 246 | return ptr; |
| 255 | 247 | } |
| ... | ... | @@ -328,14 +320,14 @@ pub const CompareOutputContext = struct { |
| 328 | 320 | |
| 329 | 321 | pub fn create(context: *CompareOutputContext, exe_path: []const u8, name: []const u8) *RuntimeSafetyRunStep { |
| 330 | 322 | const allocator = context.b.allocator; |
| 331 | const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable; | |
| 332 | ptr.* = RuntimeSafetyRunStep{ | |
| 323 | const ptr = allocator.create(RuntimeSafetyRunStep{ | |
| 333 | 324 | .context = context, |
| 334 | 325 | .exe_path = exe_path, |
| 335 | 326 | .name = name, |
| 336 | 327 | .test_index = context.test_index, |
| 337 | 328 | .step = build.Step.init("RuntimeSafetyRun", allocator, make), |
| 338 | }; | |
| 329 | }) catch unreachable; | |
| 330 | ||
| 339 | 331 | context.test_index += 1; |
| 340 | 332 | return ptr; |
| 341 | 333 | } |
| ... | ... | @@ -543,15 +535,15 @@ pub const CompileErrorContext = struct { |
| 543 | 535 | |
| 544 | 536 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { |
| 545 | 537 | const allocator = context.b.allocator; |
| 546 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | |
| 547 | ptr.* = CompileCmpOutputStep{ | |
| 538 | const ptr = allocator.create(CompileCmpOutputStep{ | |
| 548 | 539 | .step = build.Step.init("CompileCmpOutput", allocator, make), |
| 549 | 540 | .context = context, |
| 550 | 541 | .name = name, |
| 551 | 542 | .test_index = context.test_index, |
| 552 | 543 | .case = case, |
| 553 | 544 | .build_mode = build_mode, |
| 554 | }; | |
| 545 | }) catch unreachable; | |
| 546 | ||
| 555 | 547 | context.test_index += 1; |
| 556 | 548 | return ptr; |
| 557 | 549 | } |
| ... | ... | @@ -662,14 +654,14 @@ pub const CompileErrorContext = struct { |
| 662 | 654 | } |
| 663 | 655 | |
| 664 | 656 | pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 665 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 666 | tc.* = TestCase{ | |
| 657 | const tc = self.b.allocator.create(TestCase{ | |
| 667 | 658 | .name = name, |
| 668 | 659 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 669 | 660 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| 670 | 661 | .link_libc = false, |
| 671 | 662 | .is_exe = false, |
| 672 | }; | |
| 663 | }) catch unreachable; | |
| 664 | ||
| 673 | 665 | tc.addSourceFile(".tmp_source.zig", source); |
| 674 | 666 | comptime var arg_i = 0; |
| 675 | 667 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |
| ... | ... | @@ -829,14 +821,14 @@ pub const TranslateCContext = struct { |
| 829 | 821 | |
| 830 | 822 | pub fn create(context: *TranslateCContext, name: []const u8, case: *const TestCase) *TranslateCCmpOutputStep { |
| 831 | 823 | const allocator = context.b.allocator; |
| 832 | const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable; | |
| 833 | ptr.* = TranslateCCmpOutputStep{ | |
| 824 | const ptr = allocator.create(TranslateCCmpOutputStep{ | |
| 834 | 825 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 835 | 826 | .context = context, |
| 836 | 827 | .name = name, |
| 837 | 828 | .test_index = context.test_index, |
| 838 | 829 | .case = case, |
| 839 | }; | |
| 830 | }) catch unreachable; | |
| 831 | ||
| 840 | 832 | context.test_index += 1; |
| 841 | 833 | return ptr; |
| 842 | 834 | } |
| ... | ... | @@ -936,13 +928,13 @@ pub const TranslateCContext = struct { |
| 936 | 928 | } |
| 937 | 929 | |
| 938 | 930 | pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 939 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 940 | tc.* = TestCase{ | |
| 931 | const tc = self.b.allocator.create(TestCase{ | |
| 941 | 932 | .name = name, |
| 942 | 933 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 943 | 934 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 944 | 935 | .allow_warnings = allow_warnings, |
| 945 | }; | |
| 936 | }) catch unreachable; | |
| 937 | ||
| 946 | 938 | tc.addSourceFile(filename, source); |
| 947 | 939 | comptime var arg_i = 0; |
| 948 | 940 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |
| ... | ... | @@ -1023,15 +1015,15 @@ pub const GenHContext = struct { |
| 1023 | 1015 | |
| 1024 | 1016 | pub fn create(context: *GenHContext, h_path: []const u8, name: []const u8, case: *const TestCase) *GenHCmpOutputStep { |
| 1025 | 1017 | const allocator = context.b.allocator; |
| 1026 | const ptr = allocator.create(GenHCmpOutputStep) catch unreachable; | |
| 1027 | ptr.* = GenHCmpOutputStep{ | |
| 1018 | const ptr = allocator.create(GenHCmpOutputStep{ | |
| 1028 | 1019 | .step = build.Step.init("ParseCCmpOutput", allocator, make), |
| 1029 | 1020 | .context = context, |
| 1030 | 1021 | .h_path = h_path, |
| 1031 | 1022 | .name = name, |
| 1032 | 1023 | .test_index = context.test_index, |
| 1033 | 1024 | .case = case, |
| 1034 | }; | |
| 1025 | }) catch unreachable; | |
| 1026 | ||
| 1035 | 1027 | context.test_index += 1; |
| 1036 | 1028 | return ptr; |
| 1037 | 1029 | } |
| ... | ... | @@ -1070,12 +1062,12 @@ pub const GenHContext = struct { |
| 1070 | 1062 | } |
| 1071 | 1063 | |
| 1072 | 1064 | pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { |
| 1073 | const tc = self.b.allocator.create(TestCase) catch unreachable; | |
| 1074 | tc.* = TestCase{ | |
| 1065 | const tc = self.b.allocator.create(TestCase{ | |
| 1075 | 1066 | .name = name, |
| 1076 | 1067 | .sources = ArrayList(TestCase.SourceFile).init(self.b.allocator), |
| 1077 | 1068 | .expected_lines = ArrayList([]const u8).init(self.b.allocator), |
| 1078 | }; | |
| 1069 | }) catch unreachable; | |
| 1070 | ||
| 1079 | 1071 | tc.addSourceFile(filename, source); |
| 1080 | 1072 | comptime var arg_i = 0; |
| 1081 | 1073 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { |