Merge pull request #897 from micklat/devel
dynlib: optionally pass RTLD_GLOBAL to dlopen
This commit is contained in:
commit
c41687237d
1 changed files with 7 additions and 3 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
type
|
type
|
||||||
TLibHandle* = pointer ## a handle to a dynamically loaded library
|
TLibHandle* = pointer ## a handle to a dynamically loaded library
|
||||||
|
|
||||||
proc loadLib*(path: string): TLibHandle
|
proc loadLib*(path: string, global_symbols=false): TLibHandle
|
||||||
## loads a library from `path`. Returns nil if the library could not
|
## loads a library from `path`. Returns nil if the library could not
|
||||||
## be loaded.
|
## be loaded.
|
||||||
|
|
||||||
|
|
@ -53,6 +53,7 @@ when defined(posix):
|
||||||
#
|
#
|
||||||
var
|
var
|
||||||
RTLD_NOW {.importc: "RTLD_NOW", header: "<dlfcn.h>".}: int
|
RTLD_NOW {.importc: "RTLD_NOW", header: "<dlfcn.h>".}: int
|
||||||
|
RTLD_GLOBAL {.importc: "RTLD_GLOBAL", header: "<dlfcn.h>".}: int
|
||||||
|
|
||||||
proc dlclose(lib: TLibHandle) {.importc, header: "<dlfcn.h>".}
|
proc dlclose(lib: TLibHandle) {.importc, header: "<dlfcn.h>".}
|
||||||
proc dlopen(path: CString, mode: int): TLibHandle {.
|
proc dlopen(path: CString, mode: int): TLibHandle {.
|
||||||
|
|
@ -60,7 +61,10 @@ when defined(posix):
|
||||||
proc dlsym(lib: TLibHandle, name: cstring): pointer {.
|
proc dlsym(lib: TLibHandle, name: cstring): pointer {.
|
||||||
importc, header: "<dlfcn.h>".}
|
importc, header: "<dlfcn.h>".}
|
||||||
|
|
||||||
proc loadLib(path: string): TLibHandle = return dlopen(path, RTLD_NOW)
|
proc loadLib(path: string, global_symbols=false): TLibHandle =
|
||||||
|
var flags = RTLD_NOW
|
||||||
|
if global_symbols: flags = flags or RTLD_GLOBAL
|
||||||
|
return dlopen(path, flags)
|
||||||
proc loadLib(): TLibHandle = return dlopen(nil, RTLD_NOW)
|
proc loadLib(): TLibHandle = return dlopen(nil, RTLD_NOW)
|
||||||
proc unloadLib(lib: TLibHandle) = dlclose(lib)
|
proc unloadLib(lib: TLibHandle) = dlclose(lib)
|
||||||
proc symAddr(lib: TLibHandle, name: cstring): pointer =
|
proc symAddr(lib: TLibHandle, name: cstring): pointer =
|
||||||
|
|
@ -81,7 +85,7 @@ elif defined(windows) or defined(dos):
|
||||||
proc getProcAddress(lib: THINSTANCE, name: cstring): pointer {.
|
proc getProcAddress(lib: THINSTANCE, name: cstring): pointer {.
|
||||||
importc: "GetProcAddress", header: "<windows.h>", stdcall.}
|
importc: "GetProcAddress", header: "<windows.h>", stdcall.}
|
||||||
|
|
||||||
proc loadLib(path: string): TLibHandle =
|
proc loadLib(path: string, global_symbols=false): TLibHandle =
|
||||||
result = cast[TLibHandle](winLoadLibrary(path))
|
result = cast[TLibHandle](winLoadLibrary(path))
|
||||||
proc loadLib(): TLibHandle =
|
proc loadLib(): TLibHandle =
|
||||||
result = cast[TLibHandle](winLoadLibrary(nil))
|
result = cast[TLibHandle](winLoadLibrary(nil))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue