Skip to content

Commit 225e060

Browse files
Pyrolisticalalexrp
authored andcommitted
std.DynLib: compile error if attempt to lookup a function pointer with an unspecified callconv
fixes #19841
1 parent b00cbec commit 225e060

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
@@ -43,6 +43,19 @@ pub const DynLib = struct {
4343
}
4444

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

0 commit comments

Comments
 (0)