load dynamic library test: update API usage code

This commit is contained in:
Andrew Kelley 2019-12-10 12:48:10 -05:00
parent fd6b7b160d
commit 80882bda59
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 2 additions and 3 deletions

View File

@ -144,7 +144,7 @@ pub const LinuxDynLib = struct {
pub fn lookup(self: *LinuxDynLib, comptime T: type, name: []const u8) ?T {
if (self.elf_lib.lookup("", name)) |symbol| {
return @ptrCast(T, symbol);
return @intToPtr(T, symbol);
} else {
return null;
}

View File

@ -9,8 +9,7 @@ pub fn main() !void {
var lib = try std.DynLib.open(dynlib_name);
defer lib.close();
const addr = lib.lookup("add") orelse return error.SymbolNotFound;
const addFn = @intToPtr(extern fn (i32, i32) i32, addr);
const addFn = lib.lookup(extern fn (i32, i32) i32, "add") orelse return error.SymbolNotFound;
const result = addFn(12, 34);
std.debug.assert(result == 46);