Commit 3090f83800
std/event/io.zig
@@ -53,10 +53,12 @@ pub fn InStream(comptime ReadError: type) type {
return mem.readInt(bytes, T, endian);
}
- pub async fn readStruct(self: *Self, comptime T: type, ptr: *T) !void {
+ pub async fn readStruct(self: *Self, comptime T: type) !T {
// Only extern and packed structs have defined in-memory layout.
comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
- return await (async self.readNoEof(@sliceToBytes((*[1]T)(ptr)[0..])) catch unreachable);
+ var res: [1]T = undefined;
+ try await (async self.readNoEof(@sliceToBytes(res[0..])) catch unreachable);
+ return res[0];
}
};
}
std/pdb.zig
@@ -485,8 +485,7 @@ const Msf = struct {
var file_stream = file.inStream();
const in = &file_stream.stream;
- var superblock: SuperBlock = undefined;
- try in.readStruct(SuperBlock, &superblock);
+ const superblock = try in.readStruct(SuperBlock);
if (!mem.eql(u8, superblock.FileMagic, SuperBlock.file_magic))
return error.InvalidDebugInfo;