Skip to content

Commit a044b49

Browse files
committed
std.DynLib: compile error if attempt to lookup a function pointer with an unspecified callconv
fixes #19841
1 parent ae44e19 commit a044b49

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/std/dynamic_library.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ pub const DynLib = struct {
4040
}
4141

4242
pub fn lookup(self: *DynLib, comptime T: type, name: [:0]const u8) ?T {
43+
switch (@typeInfo(T)) {
44+
.Pointer => |pointer| {
45+
switch (@typeInfo(pointer.child)) {
46+
.Fn => |function| {
47+
if (function.calling_convention == .Unspecified) {
48+
@compileError("callconv cannot be .Unspecified for: " ++ @typeName(T));
49+
}
50+
},
51+
else => {},
52+
}
53+
},
54+
else => @compileError("expected a pointer type"),
55+
}
4356
return self.inner.lookup(T, name);
4457
}
4558
};

0 commit comments

Comments
 (0)