fix command ptr alignment

This commit is contained in:
Luna 2024-06-01 16:53:01 -03:00
parent c0da5e68b7
commit 3af4dc575a
2 changed files with 17 additions and 6 deletions

View File

@ -143,7 +143,18 @@ pub const Command = struct {
if (base.tag != T.base_tag)
return null;
const ptr: *const T = @alignCast(@fieldParentPtr("base", base));
//const baseInt = @intFromPtr(base);
//log.debug("casting from {d}", .{baseInt});
//log.debug("aligns from 8? {d}", .{baseInt % 8});
//log.debug("align T: {d} {s}", .{ @alignOf(*T), @typeName(T) });
//log.debug("align base: {d} {s}", .{ @alignOf(*const @This()), @typeName(@This()) });
const base_aligned: *const @This() = @alignCast(base);
const parented = @as(*const T, @alignCast(@fieldParentPtr("base", base_aligned)));
const ptr: *const T = @alignCast(parented);
//log.debug("align: {d}\n", .{@alignOf(@TypeOf(ptr))});
return ptr;
}

View File

@ -194,7 +194,7 @@ pub const Runner = struct {
try image.saveTo(out_path);
}
fn runQSCmd(self: *Runner, cmd: lang.Command) !void {
fn runQSCmd(self: *Runner, cmd: *lang.Command) !void {
const runqs = cmd.cast(lang.Command.RunQS).?;
var image = try self.getImage();
const out_path = try self.makeGlitchedPath();
@ -211,7 +211,7 @@ pub const Runner = struct {
_ = try proc.spawnAndWait();
}
fn rotateCmd(self: *Runner, cmd: lang.Command) !void {
fn rotateCmd(self: *Runner, cmd: *lang.Command) !void {
const rotate_cmd = cmd.cast(lang.Command.Rotate).?;
const image = try self.getImage();
@ -255,7 +255,7 @@ pub const Runner = struct {
fn runSingleCommand(
self: *@This(),
cmd: lang.Command,
cmd: *lang.Command,
comptime tag: lang.Command.Tag,
) !void {
const typ = lang.Command.tagToType(tag);
@ -267,7 +267,7 @@ pub const Runner = struct {
}
}
fn runCommand(self: *@This(), cmd: lang.Command) !void {
fn runCommand(self: *@This(), cmd: *lang.Command) !void {
switch (cmd.tag) {
.noop => {},
.load => {
@ -322,7 +322,7 @@ pub const Runner = struct {
_ = debug_flag;
for (cmds.list.items) |cmd| {
cmd.print();
try self.runCommand(cmd.*);
try self.runCommand(cmd);
}
}
};