From e0453eefd0f128fd4d930d21011d373589b65548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=28xq=29=20Quei=C3=9Fner?= Date: Wed, 28 Jul 2021 10:01:27 +0200 Subject: [PATCH 1/2] Update to latest master. --- examples.zig | 23 ++++++++++++----------- interface.zig | 14 ++++++++++---- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/examples.zig b/examples.zig index 94340c9..a6c8f47 100644 --- a/examples.zig +++ b/examples.zig @@ -30,8 +30,8 @@ test "Simple NonOwning interface" { var fooer = try Fooer.init(&f); defer fooer.deinit(); - expectEqual(@as(usize, 42), fooer.call("foo", .{})); - expectEqual(@as(usize, 43), fooer.call("foo", .{})); + try expectEqual(@as(usize, 42), fooer.call("foo", .{})); + try expectEqual(@as(usize, 43), fooer.call("foo", .{})); } }; @@ -56,7 +56,7 @@ test "Comptime only interface" { }; comptime var iface = try TestIFace.init(TestType{ .state = 0 }); - expectEqual(@as(u8, 42), iface.call("foo", .{42})); + try expectEqual(@as(u8, 42), iface.call("foo", .{42})); } test "Owning interface with optional function and a non-method function" { @@ -65,7 +65,7 @@ test "Owning interface with optional function and a non-method function" { const TestOwningIface = Interface(struct { someFn: ?fn (*const SelfType, usize, usize) usize, otherFn: fn (*SelfType, usize) anyerror!void, - thirdFn: fn(usize) usize, + thirdFn: fn (usize) usize, }, interface.Storage.Owning); const TestStruct = struct { @@ -92,8 +92,8 @@ test "Owning interface with optional function and a non-method function" { defer iface_instance.deinit(); try iface_instance.call("otherFn", .{100}); - expectEqual(@as(usize, 42), iface_instance.call("someFn", .{ 0, 42 }).?); - expectEqual(@as(usize, 101), iface_instance.call("thirdFn", .{ 100 })); + try expectEqual(@as(usize, 42), iface_instance.call("someFn", .{ 0, 42 }).?); + try expectEqual(@as(usize, 101), iface_instance.call("thirdFn", .{100})); } }; @@ -118,7 +118,7 @@ test "Interface with virtual async function implemented by an async function" { self.frame = @frame(); } self.state += 1; - suspend; + suspend {} self.state += 1; } }; @@ -127,11 +127,11 @@ test "Interface with virtual async function implemented by an async function" { var instance = try AsyncIFace.init(&i); _ = async instance.call("foo", .{}); - expectEqual(@as(usize, 0), i.state); + try expectEqual(@as(usize, 0), i.state); resume i.frame; - expectEqual(@as(usize, 1), i.state); + try expectEqual(@as(usize, 1), i.state); resume i.frame; - expectEqual(@as(usize, 2), i.state); + try expectEqual(@as(usize, 2), i.state); } test "Interface with virtual async function implemented by a blocking function" { @@ -143,6 +143,7 @@ test "Interface with virtual async function implemented by a blocking function" const Self = @This(); pub fn readBytes(self: Self, outBuf: []u8) void { + _ = self; for (outBuf) |*c| { c.* = 3; } @@ -154,5 +155,5 @@ test "Interface with virtual async function implemented by a blocking function" var buf: [256]u8 = undefined; try await async instance.call("readBytes", .{buf[0..]}); - expectEqual([_]u8{3} ** 256, buf); + try expectEqual([_]u8{3} ** 256, buf); } diff --git a/interface.zig b/interface.zig index cf6616e..52b0cf7 100644 --- a/interface.zig +++ b/interface.zig @@ -6,7 +6,7 @@ const assert = std.debug.assert; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -pub const SelfType = opaque{}; +pub const SelfType = opaque {}; fn makeSelfPtr(ptr: anytype) *SelfType { if (comptime !trait.isSingleItemPtr(@TypeOf(ptr))) { @@ -65,7 +65,9 @@ pub const Storage = struct { return self.erased_ptr; } - pub fn deinit(comptime self: Comptime) void {} + pub fn deinit(comptime self: Comptime) void { + _ = self; + } }; pub const NonOwning = struct { @@ -88,7 +90,9 @@ pub const Storage = struct { return self.erased_ptr; } - pub fn deinit(self: NonOwning) void {} + pub fn deinit(self: NonOwning) void { + _ = self; + } }; pub const Owning = struct { @@ -158,7 +162,9 @@ pub const Storage = struct { return makeSelfPtr(&self.mem[0]); } - pub fn deinit(self: Self) void {} + pub fn deinit(self: Self) void { + _ = self; + } }; } From 666627e58990e508f600c34c3009a44c9d12fc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=22xq=22=20Quei=C3=9Fner?= Date: Tue, 14 Sep 2021 18:32:35 +0200 Subject: [PATCH 2/2] Update to latest master. --- interface.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface.zig b/interface.zig index 52b0cf7..1d1dd12 100644 --- a/interface.zig +++ b/interface.zig @@ -147,7 +147,7 @@ pub const Storage = struct { .mem = undefined, }; if (ImplSize > 0) { - std.mem.copy(u8, self.mem[0..], @ptrCast([*]const u8, &args[0])[0..ImplSize]); + std.mem.copy(u8, self.mem[0..], @ptrCast([*]const u8, &value)[0..ImplSize]); } return TInterface{