mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
stage2: fix toAllocatedBytes on slices
This commit is contained in:
parent
ee149aaa03
commit
bff7714a7c
3 changed files with 20 additions and 15 deletions
|
|
@ -791,19 +791,24 @@ pub const Value = extern union {
|
|||
return decl_val.toAllocatedBytes(decl.ty, allocator);
|
||||
},
|
||||
.the_only_possible_value => return &[_]u8{},
|
||||
.slice => return toAllocatedBytes(val.castTag(.slice).?.data.ptr, ty, allocator),
|
||||
else => {
|
||||
const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
|
||||
var elem_value_buf: ElemValueBuffer = undefined;
|
||||
for (result) |*elem, i| {
|
||||
const elem_val = val.elemValueBuffer(i, &elem_value_buf);
|
||||
elem.* = @intCast(u8, elem_val.toUnsignedInt());
|
||||
}
|
||||
return result;
|
||||
.slice => {
|
||||
const slice = val.castTag(.slice).?.data;
|
||||
return arrayToAllocatedBytes(slice.ptr, slice.len.toUnsignedInt(), allocator);
|
||||
},
|
||||
else => return arrayToAllocatedBytes(val, ty.arrayLen(), allocator),
|
||||
}
|
||||
}
|
||||
|
||||
fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator) ![]u8 {
|
||||
const result = try allocator.alloc(u8, @intCast(usize, len));
|
||||
var elem_value_buf: ElemValueBuffer = undefined;
|
||||
for (result) |*elem, i| {
|
||||
const elem_val = val.elemValueBuffer(i, &elem_value_buf);
|
||||
elem.* = @intCast(u8, elem_val.toUnsignedInt());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
pub const ToTypeBuffer = Type.Payload.Bits;
|
||||
|
||||
/// Asserts that the value is representable as a type.
|
||||
|
|
|
|||
|
|
@ -127,8 +127,11 @@ test {
|
|||
_ = @import("behavior/bugs/726.zig");
|
||||
_ = @import("behavior/bugs/1421.zig");
|
||||
_ = @import("behavior/bugs/1442.zig");
|
||||
_ = @import("behavior/bugs/1607.zig");
|
||||
_ = @import("behavior/bugs/2114.zig");
|
||||
_ = @import("behavior/bugs/3384.zig");
|
||||
_ = @import("behavior/bugs/3742.zig");
|
||||
_ = @import("behavior/bugs/5398.zig");
|
||||
_ = @import("behavior/struct_contains_null_ptr_itself.zig");
|
||||
_ = @import("behavior/switch_prong_err_enum.zig");
|
||||
_ = @import("behavior/switch_prong_implicit_cast.zig");
|
||||
|
|
@ -147,11 +150,8 @@ test {
|
|||
_ = @import("behavior/bugs/828.zig");
|
||||
_ = @import("behavior/bugs/920.zig");
|
||||
_ = @import("behavior/bugs/1120.zig");
|
||||
_ = @import("behavior/bugs/1607.zig");
|
||||
_ = @import("behavior/bugs/1851.zig");
|
||||
_ = @import("behavior/bugs/3384.zig");
|
||||
_ = @import("behavior/bugs/3779.zig");
|
||||
_ = @import("behavior/bugs/5398.zig");
|
||||
_ = @import("behavior/bugs/5413.zig");
|
||||
_ = @import("behavior/bugs/5487.zig");
|
||||
_ = @import("behavior/bugs/6456.zig");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ test "assignment of field with padding" {
|
|||
.emits_shadows = false,
|
||||
},
|
||||
};
|
||||
try testing.expectEqual(false, renderable.material.transparent);
|
||||
try testing.expectEqual(false, renderable.material.emits_shadows);
|
||||
try testing.expectEqual(true, renderable.material.render_color);
|
||||
try testing.expect(false == renderable.material.transparent);
|
||||
try testing.expect(false == renderable.material.emits_shadows);
|
||||
try testing.expect(true == renderable.material.render_color);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue