Skip to content

Commit

Permalink
adapt to wasmtime API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dermetfan committed May 8, 2024
1 parent 3293779 commit ebef517
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/Runtime.zig
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ pub const Allocator = struct {
wasmtime.val(.{ .i32 = std.math.cast(i32, len) orelse return null }),
wasmtime.val(.{ .i32 = ptr_align }), // XXX is ptr_align valid inside WASM runtime?
};
defer for (&inputs) |*input| c.wasmtime_val_delete(input);
defer for (&inputs) |*input| c.wasmtime_val_delete(self.memory.wasm_context, input);

var output: c.wasmtime_val = undefined;
defer c.wasmtime_val_delete(&output);
defer c.wasmtime_val_delete(self.memory.wasm_context, &output);

{
var trap: ?*c.wasm_trap_t = null;
Expand All @@ -678,10 +678,10 @@ pub const Allocator = struct {
wasmtime.val(.{ .i32 = buf_align }), // XXX is buf_align valid inside WASM runtime?
wasmtime.val(.{ .i32 = @intCast(new_len) }),
};
defer for (&inputs) |*input| c.wasmtime_val_delete(input);
defer for (&inputs) |*input| c.wasmtime_val_delete(self.memory.wasm_context, input);

var output: c.wasmtime_val = undefined;
defer c.wasmtime_val_delete(&output);
defer c.wasmtime_val_delete(self.memory.wasm_context, &output);

{
var trap: ?*c.wasm_trap_t = null;
Expand All @@ -703,7 +703,7 @@ pub const Allocator = struct {
wasmtime.val(.{ .i32 = @intCast(buf.len) }),
wasmtime.val(.{ .i32 = buf_align }), // XXX is buf_align valid inside WASM runtime?
};
defer for (&inputs) |*input| c.wasmtime_val_delete(input);
defer for (&inputs) |*input| c.wasmtime_val_delete(self.memory.wasm_context, input);

{
var trap: ?*c.wasm_trap_t = null;
Expand Down Expand Up @@ -785,13 +785,13 @@ pub fn call(self: @This(), func_name: [:0]const u8, inputs: []const wasm.Value,
const c_inputs = try self.allocator.alloc(c.wasmtime_val, inputs.len);
for (c_inputs, inputs) |*c_input, input| c_input.* = wasmtime.val(input);
defer {
for (c_inputs) |*c_input| c.wasmtime_val_delete(c_input);
for (c_inputs) |*c_input| c.wasmtime_val_delete(self.wasm_context, c_input);
self.allocator.free(c_inputs);
}

const c_outputs = try self.allocator.alloc(c.wasmtime_val, outputs.len);
defer {
for (c_outputs) |*c_output| c.wasmtime_val_delete(c_output);
for (c_outputs) |*c_output| c.wasmtime_val_delete(self.wasm_context, c_output);
self.allocator.free(c_outputs);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wasm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub const Value = union(enums.Merged(&.{
f64: f64,
v128: @Vector(128 / 8, u8),
funcref: *const anyopaque,
externref: ?*const anyopaque,
externref: *const anyopaque,

pub const Type = std.meta.Tag(@This());
};
Expand Down
5 changes: 3 additions & 2 deletions src/wasmtime.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub fn fromVal(v: *const c.wasmtime_val) !wasm.Value {
c.WASMTIME_F64 => .{ .f64 = v.of.f64 },
c.WASMTIME_V128 => .{ .v128 = v.of.v128 },
c.WASMTIME_FUNCREF => .{ .funcref = @ptrCast(&v.of.funcref) },
c.WASMTIME_EXTERNREF => .{ .externref = @ptrCast(&v.of.externref) },
c.WASMTIME_EXTERNREF => .{ .externref = @ptrCast(v.of.externref) },
c.WASMTIME_ANYREF => error.UnknownWasmtimeVal,
else => error.UnknownWasmtimeVal,
};
}
Expand All @@ -28,7 +29,7 @@ pub fn val(value: wasm.Value) c.wasmtime_val {
.f64 => |v| .{ .f64 = v },
.v128 => |v| .{ .v128 = v },
.funcref => |v| .{ .funcref = @as(*const c.wasmtime_func_t, @alignCast(@ptrCast(v))).* },
.externref => |v| .{ .externref = c.wasmtime_externref_new(@constCast(v), null) },
.externref => |v| .{ .externref = @constCast(@ptrCast(v)) },
},
};
}
Expand Down

0 comments on commit ebef517

Please sign in to comment.