[Issue 5789] New: Runtime.loadLibrary/unloadLibrary need .getSymbol()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 27 14:49:32 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5789
Summary: Runtime.loadLibrary/unloadLibrary need .getSymbol()
Product: D
Version: D2
Platform: Other
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: alvaro.segura at gmail.com
--- Comment #0 from Alvaro <alvaro.segura at gmail.com> 2011-03-27 14:46:07 PDT ---
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list