authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-27 13:57:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-28 18:30:57-07:00
logea3471288ad934d37884d4f4b2d94623a30243f2
treeb7ee618c4bb2408e5c3c8965c3f7f3ec9e75d83a
parent888f00e856998841f5da7b75c6891fab8e31703c

update GenericWriter usage found by test-cases


4 files changed, 47 insertions(+), 38 deletions(-)

lib/compiler/aro/aro/Parser.zig+1-1
......@@ -719,7 +719,7 @@ fn diagnoseIncompleteDefinitions(p: *Parser) !void {
719719}
720720
721721/// root : (decl | assembly ';' | staticAssert)*
722pub fn parse(pp: *Preprocessor) Compilation.Error!Tree {
722pub fn parse(pp: *Preprocessor) Error!Tree {
723723 assert(pp.linemarkers == .none);
724724 pp.comp.pragmaEvent(.before_parse);
725725
lib/compiler/aro_translate_c.zig+10-8
......@@ -116,15 +116,17 @@ pub fn translate(
116116 var driver: aro.Driver = .{ .comp = comp };
117117 defer driver.deinit();
118118
119 var macro_buf = std.array_list.Managed(u8).init(gpa);
119 var macro_buf: std.Io.Writer.Allocating = .init(gpa);
120120 defer macro_buf.deinit();
121121
122 assert(!try driver.parseArgs(std.io.null_writer, macro_buf.writer(), args));
122 var trash: [64]u8 = undefined;
123 var discarding: std.Io.Writer.Discarding = .init(&trash);
124 assert(!try driver.parseArgs(&discarding.writer, &macro_buf.writer, args));
123125 assert(driver.inputs.items.len == 1);
124126 const source = driver.inputs.items[0];
125127
126128 const builtin_macros = try comp.generateBuiltinMacros(.include_system_defines);
127 const user_macros = try comp.addSourceFromBuffer("<command line>", macro_buf.items);
129 const user_macros = try comp.addSourceFromBuffer("<command line>", macro_buf.written());
128130
129131 var pp = try aro.Preprocessor.initDefault(comp);
130132 defer pp.deinit();
......@@ -698,11 +700,10 @@ fn transEnumDecl(c: *Context, scope: *Scope, enum_decl: *const Type.Enum, field_
698700}
699701
700702fn getTypeStr(c: *Context, ty: Type) ![]const u8 {
701 var buf: std.ArrayListUnmanaged(u8) = .empty;
702 defer buf.deinit(c.gpa);
703 const w = buf.writer(c.gpa);
704 try ty.print(c.mapper, c.comp.langopts, w);
705 return c.arena.dupe(u8, buf.items);
703 var allocating: std.Io.Writer.Allocating = .init(c.gpa);
704 defer allocating.deinit();
705 ty.print(c.mapper, c.comp.langopts, &allocating.writer) catch return error.OutOfMemory;
706 return c.arena.dupe(u8, allocating.written());
706707}
707708
708709fn transType(c: *Context, scope: *Scope, raw_ty: Type, qual_handling: Type.QualHandling, source_loc: TokenIndex) TypeError!ZigNode {
......@@ -1820,6 +1821,7 @@ pub fn main() !void {
18201821 var tree = translate(gpa, &aro_comp, args) catch |err| switch (err) {
18211822 error.ParsingFailed, error.FatalError => renderErrorsAndExit(&aro_comp),
18221823 error.OutOfMemory => return error.OutOfMemory,
1824 error.WriteFailed => return error.WriteFailed,
18231825 error.StreamTooLong => std.process.fatal("An input file was larger than 4GiB", .{}),
18241826 };
18251827 defer tree.deinit(gpa);
lib/std/debug/Pdb.zig+36-18
......@@ -65,9 +65,15 @@ pub fn deinit(self: *Pdb) void {
6565pub fn parseDbiStream(self: *Pdb) !void {
6666 var stream = self.getStream(pdb.StreamType.dbi) orelse
6767 return error.InvalidDebugInfo;
68 const reader = stream.reader();
6968
70 const header = try reader.readStruct(std.pdb.DbiStreamHeader);
69 const gpa = self.allocator;
70
71 const deprecated_reader = stream.reader();
72 var adapted_buffer: [1024]u8 = undefined;
73 var adapted_reader = deprecated_reader.adaptToNewApi(&adapted_buffer);
74 const reader = &adapted_reader.new_interface;
75
76 const header = try reader.takeStruct(std.pdb.DbiStreamHeader, .little);
7177 if (header.version_header != 19990903) // V70, only value observed by LLVM team
7278 return error.UnknownPDBVersion;
7379 // if (header.Age != age)
......@@ -76,22 +82,24 @@ pub fn parseDbiStream(self: *Pdb) !void {
7682 const mod_info_size = header.mod_info_size;
7783 const section_contrib_size = header.section_contribution_size;
7884
79 var modules = std.array_list.Managed(Module).init(self.allocator);
85 var modules = std.array_list.Managed(Module).init(gpa);
8086 errdefer modules.deinit();
8187
8288 // Module Info Substream
8389 var mod_info_offset: usize = 0;
8490 while (mod_info_offset != mod_info_size) {
85 const mod_info = try reader.readStruct(pdb.ModInfo);
91 const mod_info = try reader.takeStruct(pdb.ModInfo, .little);
8692 var this_record_len: usize = @sizeOf(pdb.ModInfo);
8793
88 const module_name = try reader.readUntilDelimiterAlloc(self.allocator, 0, 1024);
89 errdefer self.allocator.free(module_name);
90 this_record_len += module_name.len + 1;
94 var module_name: std.Io.Writer.Allocating = .init(gpa);
95 defer module_name.deinit();
96 this_record_len += try reader.streamDelimiterLimit(&module_name.writer, 0, .limited(1024));
97 this_record_len += 1;
9198
92 const obj_file_name = try reader.readUntilDelimiterAlloc(self.allocator, 0, 1024);
93 errdefer self.allocator.free(obj_file_name);
94 this_record_len += obj_file_name.len + 1;
99 var obj_file_name: std.Io.Writer.Allocating = .init(gpa);
100 defer obj_file_name.deinit();
101 this_record_len += try reader.streamDelimiterLimit(&obj_file_name.writer, 0, .limited(1024));
102 this_record_len += 1;
95103
96104 if (this_record_len % 4 != 0) {
97105 const round_to_next_4 = (this_record_len | 0x3) + 1;
......@@ -102,8 +110,8 @@ pub fn parseDbiStream(self: *Pdb) !void {
102110
103111 try modules.append(Module{
104112 .mod_info = mod_info,
105 .module_name = module_name,
106 .obj_file_name = obj_file_name,
113 .module_name = try module_name.toOwnedSlice(),
114 .obj_file_name = try obj_file_name.toOwnedSlice(),
107115
108116 .populated = false,
109117 .symbols = undefined,
......@@ -117,21 +125,21 @@ pub fn parseDbiStream(self: *Pdb) !void {
117125 }
118126
119127 // Section Contribution Substream
120 var sect_contribs = std.array_list.Managed(pdb.SectionContribEntry).init(self.allocator);
128 var sect_contribs = std.array_list.Managed(pdb.SectionContribEntry).init(gpa);
121129 errdefer sect_contribs.deinit();
122130
123131 var sect_cont_offset: usize = 0;
124132 if (section_contrib_size != 0) {
125 const version = reader.readEnum(std.pdb.SectionContrSubstreamVersion, .little) catch |err| switch (err) {
126 error.InvalidValue => return error.InvalidDebugInfo,
127 else => |e| return e,
133 const version = reader.takeEnum(std.pdb.SectionContrSubstreamVersion, .little) catch |err| switch (err) {
134 error.InvalidEnumTag, error.EndOfStream => return error.InvalidDebugInfo,
135 error.ReadFailed => return error.ReadFailed,
128136 };
129137 _ = version;
130138 sect_cont_offset += @sizeOf(u32);
131139 }
132140 while (sect_cont_offset != section_contrib_size) {
133141 const entry = try sect_contribs.addOne();
134 entry.* = try reader.readStruct(pdb.SectionContribEntry);
142 entry.* = try reader.takeStruct(pdb.SectionContribEntry, .little);
135143 sect_cont_offset += @sizeOf(pdb.SectionContribEntry);
136144
137145 if (sect_cont_offset > section_contrib_size)
......@@ -233,6 +241,7 @@ pub fn getSymbolName(self: *Pdb, module: *Module, address: u64) ?[]const u8 {
233241pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.SourceLocation {
234242 std.debug.assert(module.populated);
235243 const subsect_info = module.subsect_info;
244 const gpa = self.allocator;
236245
237246 var sect_offset: usize = 0;
238247 var skip_len: usize = undefined;
......@@ -287,7 +296,16 @@ pub fn getLineNumberInfo(self: *Pdb, module: *Module, address: u64) !std.debug.S
287296 const chksum_hdr: *align(1) pdb.FileChecksumEntryHeader = @ptrCast(&module.subsect_info[subsect_index]);
288297 const strtab_offset = @sizeOf(pdb.StringTableHeader) + chksum_hdr.file_name_offset;
289298 try self.string_table.?.seekTo(strtab_offset);
290 const source_file_name = try self.string_table.?.reader().readUntilDelimiterAlloc(self.allocator, 0, 1024);
299 const source_file_name = s: {
300 const deprecated_reader = self.string_table.?.reader();
301 var adapted_buffer: [1024]u8 = undefined;
302 var adapted_reader = deprecated_reader.adaptToNewApi(&adapted_buffer);
303 var source_file_name: std.Io.Writer.Allocating = .init(gpa);
304 defer source_file_name.deinit();
305 _ = try adapted_reader.new_interface.streamDelimiterLimit(&source_file_name.writer, 0, .limited(1024));
306 break :s try source_file_name.toOwnedSlice();
307 };
308 errdefer gpa.free(source_file_name);
291309
292310 const line_entry_idx = line_i - 1;
293311
test/behavior/packed-struct.zig-11
......@@ -1075,17 +1075,6 @@ test "assigning packed struct inside another packed struct" {
10751075 try expect(S.mem.padding == 0);
10761076}
10771077
1078test "packed struct used as part of anon decl name" {
1079 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1080 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1081 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
1082
1083 const S = packed struct { a: u0 = 0 };
1084 var a: u8 = 0;
1085 _ = &a;
1086 try std.io.null_writer.print("\n{} {}\n", .{ a, S{} });
1087}
1088
10891078test "packed struct acts as a namespace" {
10901079 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10911080