summaryrefslogtreecommitdiff
path: root/src/walk.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/walk.zig')
-rw-r--r--src/walk.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/walk.zig b/src/walk.zig
index d0d20e8a..3556ce88 100644
--- a/src/walk.zig
+++ b/src/walk.zig
@@ -1332,6 +1332,17 @@ pub fn Load(comptime roots: []const type) type {
out.* = if (comptime C == std.mem.Allocator) l.gpa else null;
return;
}
+ // A slice's or a pointer's null is its address: set to
+ // an undefined payload, the optional itself is undefined,
+ // and ReleaseSafe's optimizer read it as null (a pane's
+ // `?[]u8` command one byte long, every field after it out
+ // of step). Read through a local and set it from that.
+ if (comptime @typeInfo(C) == .pointer) {
+ var payload: C = undefined;
+ try l.value(C, s.child, &payload);
+ out.* = payload;
+ return;
+ }
out.* = @as(C, undefined);
try l.fresh(C, &out.*.?);
l.value(C, s.child, &out.*.?) catch |err| {
@@ -1626,6 +1637,18 @@ pub fn load(comptime T: type, gpa: std.mem.Allocator, bytes: []const u8, notes:
return v;
}
+test "an optional slice comes back, and the fields after it" {
+ const S = struct { before: u32 = 0, command: ?[]u8 = null, after: u32 = 0 };
+ var text = "sleep 30".*;
+ const bytes = try save(S, std.testing.allocator, &.{ .before = 1, .command = &text, .after = 2 });
+ defer std.testing.allocator.free(bytes);
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const back = try load(S, arena.allocator(), bytes, null);
+ try std.testing.expectEqualStrings("sleep 30", back.command.?);
+ try std.testing.expectEqual(2, back.after);
+}
+
test "a dump comes back whole: shared things shared, lists and runs as long as they were" {
const gpa = std.testing.allocator;
const Leaf = struct { n: u21, name: []const u8 };