authorgravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-06-21 00:40:21+09:00
committergravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-06-21 00:40:21+09:00
log71db8df5480f4d849480267574cd5491066e3868
tree1842ce3024d7254022c66d5a00c5e53488fcbeb8
parent457c0f0a7e424177e7d8d00f4429da292b7c67d5

std: update stdlib to match updated allocator create signature; ref #733


11 files changed, 100 insertions(+), 122 deletions(-)

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