www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5789] New: Runtime.loadLibrary/unloadLibrary need .getSymbol()

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 puremagic.com
        ReportedBy: alvaro.segura gmail.com



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: -------
Mar 27 2011