aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-23 19:20:38 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-23 19:20:38 -0700
commit74ccd0c40b6871093f52769d342c1316e9ded0c0 (patch)
tree0344132802f5581c1687e7f72083577c0648eb3a /src/value.zig
parent7378ce67dabf996f2d0927138f826dfb3d6fa05f (diff)
downloadzig-74ccd0c40b6871093f52769d342c1316e9ded0c0.tar.gz
zig-74ccd0c40b6871093f52769d342c1316e9ded0c0.zip
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.
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/value.zig b/src/value.zig
index fb9a2f826a..24f6b1df75 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -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,