mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.Io.Reader: work around llvm backend bug
tracked by #25067 and I already have a fix cooking in another branch
This commit is contained in:
parent
46b60dc069
commit
530cc2c111
@ -1163,7 +1163,11 @@ pub inline fn takeStruct(r: *Reader, comptime T: type, endian: std.builtin.Endia
|
||||
.@"struct" => |info| switch (info.layout) {
|
||||
.auto => @compileError("ill-defined memory layout"),
|
||||
.@"extern" => {
|
||||
var res = (try r.takeStructPointer(T)).*;
|
||||
// This code works around https://github.com/ziglang/zig/issues/25067
|
||||
// by avoiding a call to `peekStructPointer`.
|
||||
const struct_bytes = try r.takeArray(@sizeOf(T));
|
||||
var res: T = undefined;
|
||||
@memcpy(@as([]u8, @ptrCast(&res)), struct_bytes);
|
||||
if (native_endian != endian) std.mem.byteSwapAllFields(T, &res);
|
||||
return res;
|
||||
},
|
||||
@ -1188,7 +1192,11 @@ pub inline fn peekStruct(r: *Reader, comptime T: type, endian: std.builtin.Endia
|
||||
.@"struct" => |info| switch (info.layout) {
|
||||
.auto => @compileError("ill-defined memory layout"),
|
||||
.@"extern" => {
|
||||
var res = (try r.peekStructPointer(T)).*;
|
||||
// This code works around https://github.com/ziglang/zig/issues/25067
|
||||
// by avoiding a call to `peekStructPointer`.
|
||||
const struct_bytes = try r.peekArray(@sizeOf(T));
|
||||
var res: T = undefined;
|
||||
@memcpy(@as([]u8, @ptrCast(&res)), struct_bytes);
|
||||
if (native_endian != endian) std.mem.byteSwapAllFields(T, &res);
|
||||
return res;
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user