mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 05:48:31 +00:00
Sema: Value.copy: we gotta copy the bytes
For Value.Tag.bytes, the value copy implementation did not copy the bytes array. No good. This operation must do a deep copy. If we want some other mechanism for not copying very large byte buffers then it has to work differently than this one.
This commit is contained in:
parent
7378ce67da
commit
74ccd0c40b
@ -526,7 +526,15 @@ pub const Value = extern union {
|
||||
};
|
||||
return Value{ .ptr_otherwise = &new_payload.base };
|
||||
},
|
||||
.bytes => return self.copyPayloadShallow(arena, Payload.Bytes),
|
||||
.bytes => {
|
||||
const bytes = self.castTag(.bytes).?.data;
|
||||
const new_payload = try arena.create(Payload.Bytes);
|
||||
new_payload.* = .{
|
||||
.base = .{ .tag = .bytes },
|
||||
.data = try arena.dupe(u8, bytes),
|
||||
};
|
||||
return Value{ .ptr_otherwise = &new_payload.base };
|
||||
},
|
||||
.repeated,
|
||||
.eu_payload,
|
||||
.opt_payload,
|
||||
|
||||
@ -462,7 +462,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
|
||||
}
|
||||
|
||||
test "implicit cast from *const [N]T to []const T" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
try testCastConstArrayRefToConstSlice();
|
||||
comptime try testCastConstArrayRefToConstSlice();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user