Bug 5789 – Runtime.loadLibrary/unloadLibrary need .getSymbol()

Status
NEW
Severity
enhancement
Priority
P4
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-27T14:46:07Z
Last change time
2024-12-14T19:58:11Z
Keywords
dll
Assigned to
Martin Nowak
Creator
Alvaro
Moved to GitHub: dmd#17232 →

Comments

Comment #0 by alvaro.segura — 2011-03-27T14:46:07Z
Runtime.loadLibrary()/unloadLibrary() are very handy to load DLLs in a platform independent way, without using directly the platform's LoadLibrary()/UnloadLibrary() or dlopen()/dlclose(). But these two are missing a third very important function: a function to load the address of a given symbol in the shared library. E.g. the equivalent GetProcAddress() in Windows or dlsym() in Linux. To keep the current simplicity in Phobos, where the library is just referenced by a void*, the new functions could be: void* Runtime.getLibrarySymbol(void* libhandle, string symbol); Libraries such as gtkD are currently doing a lot of dynamic loading and use platform specific functions with version(Windows){...}else{...} conditions. That could be avoided and simplified with the above. -- Anyway I'd favor a little DynLibrary class allowing: auto lib = new DynLibrary("mylib"); // ".dll" or ".so" autoappended Function f = lib["main_function"]; BTW, autoappending the extension in Runtime.loadLibrary() would be great to ease program portability. Not sure if it's already like that. -- Also (this could be a different request report) it would be great to have an additional function in dynamic libraries: a "factory" function to create objects from classes defined inside the DLL (great for plugins for example). There is already Object.factory("module.Class"); which works great but only locally. Can't that be supported for loaded libraries? either with a new call: Runtime.libraryFactory(void* libhandle, string classname); or lib.factory("class"); or just making the library, in its init code, add its classes to the calling runtime so that Object.factory("mydll.Classname") does it.
Comment #1 by code — 2014-06-15T19:40:38Z
There is a pull request for this issue this which needs some more work to get accepted. https://github.com/D-Programming-Language/druntime/pull/617
Comment #2 by robert.schadek — 2024-12-07T13:31:24Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17232 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB