authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-05-27 10:12:07-05:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-05-28 10:34:35-05:00
logb8cd4b18b068d83bd4c2ae44777f60244d8d1853
treec91951a315a48a0babac5534645c44000b96e16d
parentd1b6f29d225bbedd0afb97fce64f5d042df4d9c6

remove unneed allocator from DynLib


1 files changed, 15 insertions(+), 9 deletions(-)

std/dynamic_library.zig+15-9
...@@ -104,9 +104,9 @@ pub const LinuxDynLib = struct {...@@ -104,9 +104,9 @@ pub const LinuxDynLib = struct {
104 memory: []align(mem.page_size) u8,104 memory: []align(mem.page_size) u8,
105105
106 /// Trusts the file106 /// Trusts the file
107 pub fn open(allocator: *mem.Allocator, path: []const u8) !DynLib {107 pub fn open(path: []const u8) !DynLib {
108 const fd = try os.open(path, 0, os.O_RDONLY | os.O_CLOEXEC);108 const fd = try std.os.posixOpen(path, 0, linux.O_RDONLY | linux.O_CLOEXEC);
109 errdefer os.close(fd);109 errdefer std.os.close(fd);
110110
111 const size = @intCast(usize, (try os.fstat(fd)).size);111 const size = @intCast(usize, (try os.fstat(fd)).size);
112112
...@@ -244,15 +244,21 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [...@@ -244,15 +244,21 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
244}244}
245245
246pub const WindowsDynLib = struct {246pub const WindowsDynLib = struct {
247 allocator: *mem.Allocator,
248 dll: windows.HMODULE,247 dll: windows.HMODULE,
249248
250 pub fn open(allocator: *mem.Allocator, path: []const u8) !WindowsDynLib {249 pub fn open(path: []const u8) !WindowsDynLib {
251 const wpath = try windows.sliceToPrefixedFileW(path);250 const wpath = try win_util.sliceToPrefixedFileW(path);
252251
253 return WindowsDynLib{252 return WindowsDynLib{
254 .allocator = allocator,253 .dll = windows.LoadLibraryW(&wpath) orelse {
255 .dll = try windows.LoadLibraryW(&wpath),254 const err = windows.GetLastError();
255 switch (err) {
256 windows.ERROR.FILE_NOT_FOUND => return error.FileNotFound,
257 windows.ERROR.PATH_NOT_FOUND => return error.FileNotFound,
258 windows.ERROR.MOD_NOT_FOUND => return error.FileNotFound,
259 else => return os.unexpectedErrorWindows(err),
260 }
261 },
256 };262 };
257 }263 }
258264
...@@ -273,7 +279,7 @@ test "dynamic_library" {...@@ -273,7 +279,7 @@ test "dynamic_library" {
273 else => return,279 else => return,
274 };280 };
275281
276 const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| {282 const dynlib = DynLib.open(libname) catch |err| {
277 testing.expect(err == error.FileNotFound);283 testing.expect(err == error.FileNotFound);
278 return;284 return;
279 };285 };