| author | |
| committer | |
| log | 74ccd0c40b6871093f52769d342c1316e9ded0c0 |
| tree | 0344132802f5581c1687e7f72083577c0648eb3a |
| parent | 7378ce67dabf996f2d0927138f826dfb3d6fa05f |
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.2 files changed, 10 insertions(+), 2 deletions(-)
src/value.zig+9-1| ... | @@ -526,7 +526,15 @@ pub const Value = extern union { | ... | @@ -526,7 +526,15 @@ pub const Value = extern union { |
| 526 | }; | 526 | }; |
| 527 | return Value{ .ptr_otherwise = &new_payload.base }; | 527 | return Value{ .ptr_otherwise = &new_payload.base }; |
| 528 | }, | 528 | }, |
| 529 | .bytes => return self.copyPayloadShallow(arena, Payload.Bytes), | 529 | .bytes => { |
| 530 | const bytes = self.castTag(.bytes).?.data; | ||
| 531 | const new_payload = try arena.create(Payload.Bytes); | ||
| 532 | new_payload.* = .{ | ||
| 533 | .base = .{ .tag = .bytes }, | ||
| 534 | .data = try arena.dupe(u8, bytes), | ||
| 535 | }; | ||
| 536 | return Value{ .ptr_otherwise = &new_payload.base }; | ||
| 537 | }, | ||
| 530 | .repeated, | 538 | .repeated, |
| 531 | .eu_payload, | 539 | .eu_payload, |
| 532 | .opt_payload, | 540 | .opt_payload, |
test/behavior/cast.zig+1-1| ... | @@ -462,7 +462,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { | ... | @@ -462,7 +462,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { |
| 462 | } | 462 | } |
| 463 | 463 | ||
| 464 | test "implicit cast from *const [N]T to []const T" { | 464 | test "implicit cast from *const [N]T to []const T" { |
| 465 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | 465 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 466 | 466 | ||
| 467 | try testCastConstArrayRefToConstSlice(); | 467 | try testCastConstArrayRefToConstSlice(); |
| 468 | comptime try testCastConstArrayRefToConstSlice(); | 468 | comptime try testCastConstArrayRefToConstSlice(); |