core.runtime: loadLibrary and unloadLibrary?

Sean Kelly sean at invisibleduck.org
Fri Jan 11 13:17:22 PST 2013


On Jan 11, 2013, at 12:41 PM, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:

> On Fri, Jan 11, 2013 at 11:26:33AM -0800, Sean Kelly wrote:
>> On Jan 11, 2013, at 7:34 AM, Phil Lavoie <maidenphil at hotmail.com> wrote:
>> 
>>> Anyone else finds themself desiring a "loadSymbol( void *
>>> whateverReturnedByLoadLib, string name )" function?
>> 
>> Please submit an enhancement request :-)
> 
> Is it safe to use void* for representing _both_ variables and functions?
> 
> I know in C++ this was a problem in the standard, because a function
> pointer may not be the same size as a pointer to a variable, and
> therefore dlsym technically has undefined behaviour (though I doubt if
> any implementation actually doesn't work).
> 
> What's the situation in D? What if the library exports delegates? Would
> it be dangerous to cast it to void*? Do we need separate functions for
> loading function symbols vs. data symbols?

I don't think a library can directly export a delegate, because that implies a context pointer linked to instantiated data.  void* is safe provided that's what the underlying API uses.  It may be a better idea to change this to an opaque handle though.


More information about the Digitalmars-d mailing list