blockblaz / blockblaz/ssz.zig

Allocate pointers in deserialize

Open
#17 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Zig
Stars
34
Forks
17
PR merge metrics
No merged PRs in 30d

Description

This is a tracking issue for a potential API change: should `deserialize` be passed an allocator?

While this library is designed not to have any allocations beyond the `ArrayList`, some issue arises with pointers. For instance, consider the following structure:

```zig
const data = .{
// The cast is necessary, otherwise the type is interpreted as `const [0..5]u8`.
.name = @as([]const u8, "James"),
.age = @as(u8, 32),
.company = @as([]const u8, "DEV Inc."),
};
```

When serializing it, then deserializing it, one can not pass the following object:\

```zig
var out: @TypeOf(data) = undefined;
```

This is because the compiler will complain that `runtime value contains reference to comptime var` and `note: comptime var pointers are not available at runtime`. The `undefined` will stuff some `0xaaaaaaa` values in the pointers, and this will be considered comptime, and no reference can be taken to this fudge value.

So the current approach is to somehow pre-allocate the pointers, which creates a whole host of other issues (e.g. what size should be allocated?).

The only way around this issue that I see for now, is to add a new `allocator` agument, so that it can be used in this specific instance. Since this is useless most of the time, this could be an optional argument.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.