Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime.loadLibrary/unloadLibrary need .getSymbol() #17232

Open
dlangBugzillaToGithub opened this issue Mar 27, 2011 · 1 comment
Open

Runtime.loadLibrary/unloadLibrary need .getSymbol() #17232

dlangBugzillaToGithub opened this issue Mar 27, 2011 · 1 comment
Labels

Comments

@dlangBugzillaToGithub
Copy link

Alvaro reported this on 2011-03-27T14:46:07Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=5789

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

code (@MartinNowak) commented on 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

@thewilsonator thewilsonator added Severity:Enhancement Druntime Specific to druntime and removed enhancement labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants