Is it possible to dynamically load a @safe function from a shared library ?

Steven Schveighoffer schveiguy at gmail.com
Sun Mar 15 16:52:34 UTC 2020


On 3/13/20 5:06 PM, H. S. Teoh wrote:
> On Fri, Mar 13, 2020 at 04:31:16PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
> [...]
>> I would expect that something could be written to turn a signature
>> string into a mangling and also provide the correct type upon return.
>> Something like:
>>
>> auto f = getFunction!(@safe void function(int))("package.module.symbol");
>>
>> and have it properly mangle the expected function name and pull it
>> from the dynamic library.
> [...]
> 
> This would still have to be @trusted, of course, since there's no
> telling what's actually inside the object file.

Of course it has to be trusted. The underlying function uses void *.

But not because you can't trust the mangling.

> But this sort of facility totally should be in Phobos, or at least in
> some dub package somewhere.  It will make working with dynamically
> loaded libraries in D so much more convenient.

I'm not really motivated to make such a package, as I don't do any 
software with runtime loading of libraries. But I bet it would be either 
accepted into Phobos and/or wouldn't be that hard to add for a library.

-Steve


More information about the Digitalmars-d-learn mailing list