Fix `@call` usage errors and duplicate test names

master
Aron Gabriel 2 years ago
parent 5045a4fa33
commit 13ea2be1c1

@ -59,7 +59,7 @@ pub fn Cache(comptime T: type) type {
pub fn remove(self: *@This(), id: u32) void { pub fn remove(self: *@This(), id: u32) void {
if (self.resources.fetchRemove(id)) |kv| { if (self.resources.fetchRemove(id)) |kv| {
if (@hasDecl(T, "deinit")) { if (@hasDecl(T, "deinit")) {
@call(.always_inline, @field(kv.value, "deinit"), .{}); @call(.always_inline, T.deinit, .{kv.value});
} }
} }
} }
@ -69,7 +69,7 @@ pub fn Cache(comptime T: type) type {
if (@hasDecl(T, "deinit")) { if (@hasDecl(T, "deinit")) {
var iter = self.resources.iterator(); var iter = self.resources.iterator();
while (iter.next()) |kv| { while (iter.next()) |kv| {
@call(.always_inline, @field(kv.value_ptr.*, "deinit"), .{}); @call(.always_inline, T.deinit, .{kv.value_ptr.*});
} }
} }
self.resources.clearAndFree(); self.resources.clearAndFree();

@ -17,12 +17,13 @@ pub fn Delegate(comptime Event: type) type {
std.debug.assert(@intFromPtr(ctx) != 0); std.debug.assert(@intFromPtr(ctx) != 0);
const T = @TypeOf(ctx); const T = @TypeOf(ctx);
const BaseT = @typeInfo(T).Pointer.child;
return Self{ return Self{
.ctx_ptr_address = @intFromPtr(ctx), .ctx_ptr_address = @intFromPtr(ctx),
.callback = .{ .callback = .{
.bound = struct { .bound = struct {
fn cb(self: usize, param: Event) void { fn cb(self: usize, param: Event) void {
@call(.always_inline, @field(@ptrFromInt(T, self), fn_name), .{param}); @call(.always_inline, @field(BaseT, fn_name), .{ @ptrFromInt(T, self), param });
} }
}.cb, }.cb,
}, },

@ -58,7 +58,7 @@ test "context not pointer" {
// reg.setContext(pos); // reg.setContext(pos);
} }
test "context get/set/unset" { test "context get/set/unset typed" {
const SomeType = struct { dummy: u1 }; const SomeType = struct { dummy: u1 };
var reg = Registry.init(std.testing.allocator); var reg = Registry.init(std.testing.allocator);

Loading…
Cancel
Save