Skip to content

Commit 1629292

Browse files
Make MbrPartitionTable compile
1 parent e52c6ed commit 1629292

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/components/part/MbrPartitionTable.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn parse(ctx: dim.Context) !dim.Content {
5050
}
5151
}
5252

53-
return .create_handle(pf, .create(@This(), .{
53+
return .create_handle(pf, .create(PartTable, .{
5454
.guess_size_fn = guess_size,
5555
.render_fn = render,
5656
}));
@@ -74,19 +74,20 @@ fn parse_partition(ctx: dim.Context) !Partition {
7474
parse_loop: while (true) {
7575
const kw = try ctx.parse_enum(enum {
7676
type,
77-
size,
7877
bootable,
78+
size,
79+
offset,
7980
contents,
8081
endpart,
8182
});
82-
switch (kw) {
83+
try switch (kw) {
8384
.type => updater.set(.type, try ctx.parse_enum(PartitionType)),
8485
.bootable => updater.set(.bootable, true),
8586
.size => updater.set(.size, try ctx.parse_mem_size()),
8687
.offset => updater.set(.offset, try ctx.parse_mem_size()),
87-
.contents => updater.set(.contents, try ctx.parse_content()),
88+
.contents => updater.set(.data, try ctx.parse_content()),
8889
.endpart => break :parse_loop,
89-
}
90+
};
9091
}
9192

9293
try updater.validate();

src/dim.zig

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn FieldUpdater(comptime Obj: type, comptime optional_fields: []const std.me
255255

256256
pub fn set(fup: *FUP, comptime field: FieldName, value: @FieldType(Obj, @tagName(field))) !void {
257257
if (fup.updated_fields.contains(field)) {
258-
fup.ctx.report_nonfatal_error("duplicate assignment of {s}.{s}", .{
258+
try fup.ctx.report_nonfatal_error("duplicate assignment of {s}.{s}", .{
259259
@typeName(Obj),
260260
@tagName(field),
261261
});
@@ -273,7 +273,7 @@ pub fn FieldUpdater(comptime Obj: type, comptime optional_fields: []const std.me
273273
missing_fields = missing_fields.complement();
274274
var iter = missing_fields.iterator();
275275
while (iter.next()) |fld| {
276-
fup.ctx.report_nonfatal_error("missing assignment of {s}.{s}", .{
276+
try fup.ctx.report_nonfatal_error("missing assignment of {s}.{s}", .{
277277
@typeName(Obj),
278278
@tagName(fld),
279279
});
@@ -290,6 +290,8 @@ const Environment = struct {
290290
UnknownContentType,
291291
FatalConfigError,
292292
InvalidEnumTag,
293+
Overflow,
294+
InvalidSize,
293295
};
294296

295297
arena: std.mem.Allocator,
@@ -341,6 +343,24 @@ pub const Content = struct {
341343
obj: *anyopaque,
342344
vtable: *const VTable,
343345

346+
pub const empty: Content = .{
347+
.obj = undefined,
348+
.vtable = &emptyVTable,
349+
};
350+
351+
const emptyVTable: VTable = blk: {
352+
const Wrap = struct {
353+
fn render(_: *anyopaque, _: *BinaryStream) RenderError!void {}
354+
fn guess_size_fn(_: *anyopaque) GuessError!SizeGuess {
355+
return .{ .exact = 0 };
356+
}
357+
};
358+
break :blk .{
359+
.render_fn = Wrap.render,
360+
.guess_size_fn = Wrap.guess_size_fn,
361+
};
362+
};
363+
344364
pub fn create_handle(obj: *anyopaque, vtable: *const VTable) Content {
345365
return .{ .obj = obj, .vtable = vtable };
346366
}
@@ -361,10 +381,13 @@ pub const Content = struct {
361381
render_fn: *const fn (*anyopaque, *BinaryStream) RenderError!void,
362382
guess_size_fn: *const fn (*anyopaque) GuessError!SizeGuess,
363383

364-
pub fn create(comptime Container: type, comptime funcs: struct {
365-
render_fn: *const fn (*Container, *BinaryStream) RenderError!void,
366-
guess_size_fn: *const fn (*Container) GuessError!SizeGuess,
367-
}) *const VTable {
384+
pub fn create(
385+
comptime Container: type,
386+
comptime funcs: struct {
387+
render_fn: *const fn (*Container, *BinaryStream) RenderError!void,
388+
guess_size_fn: *const fn (*Container) GuessError!SizeGuess,
389+
},
390+
) *const VTable {
368391
const Wrap = struct {
369392
fn render(self: *anyopaque, stream: *BinaryStream) RenderError!void {
370393
return funcs.render_fn(

0 commit comments

Comments
 (0)