From ba361f31c610bb97958201391f929696afd7f5aa Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 15 Nov 2018 16:16:08 -0500 Subject: [PATCH] more fixes related to readStruct API --- std/debug/index.zig | 11 ++++------- std/io.zig | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/std/debug/index.zig b/std/debug/index.zig index c256932b24..b077bdb3b0 100644 --- a/std/debug/index.zig +++ b/std/debug/index.zig @@ -755,8 +755,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { return cap * 2 / 3 + 1; } }; - var hash_tbl_hdr: HashTableHeader = undefined; - try pdb_stream.stream.readStruct(HashTableHeader, &hash_tbl_hdr); + const hash_tbl_hdr = try pdb_stream.stream.readStruct(HashTableHeader); if (hash_tbl_hdr.Capacity == 0) return error.InvalidDebugInfo; @@ -790,8 +789,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { const dbi = di.pdb.dbi; // Dbi Header - var dbi_stream_header: pdb.DbiStreamHeader = undefined; - try dbi.stream.readStruct(pdb.DbiStreamHeader, &dbi_stream_header); + const dbi_stream_header = try dbi.stream.readStruct(pdb.DbiStreamHeader); const mod_info_size = dbi_stream_header.ModInfoSize; const section_contrib_size = dbi_stream_header.SectionContributionSize; @@ -800,8 +798,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { // Module Info Substream var mod_info_offset: usize = 0; while (mod_info_offset != mod_info_size) { - var mod_info: pdb.ModInfo = undefined; - try dbi.stream.readStruct(pdb.ModInfo, &mod_info); + const mod_info = try dbi.stream.readStruct(pdb.ModInfo); var this_record_len: usize = @sizeOf(pdb.ModInfo); const module_name = try dbi.readNullTermString(allocator); @@ -845,7 +842,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { } while (sect_cont_offset != section_contrib_size) { const entry = try sect_contribs.addOne(); - try dbi.stream.readStruct(pdb.SectionContribEntry, entry); + entry.* = try dbi.stream.readStruct(pdb.SectionContribEntry); sect_cont_offset += @sizeOf(pdb.SectionContribEntry); if (sect_cont_offset > section_contrib_size) diff --git a/std/io.zig b/std/io.zig index 7459bbcdf5..6473d993c4 100644 --- a/std/io.zig +++ b/std/io.zig @@ -192,7 +192,7 @@ pub fn InStream(comptime ReadError: type) type { // Only extern and packed structs have defined in-memory layout. comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto); var res: [1]T = undefined; - return self.readNoEof(@sliceToBytes(res[0..])); + try self.readNoEof(@sliceToBytes(res[0..])); return res[0]; } };