How to call 'shared static this()' code of a D shared library?

Ali Çehreli acehreli at yahoo.com
Mon Jan 20 06:58:21 UTC 2020


On 1/17/20 7:53 PM, Adam D. Ruppe wrote:
> Did you already try rt_init? That should trigger it....

I was under the impression that the extern (C) function rt_init() would 
magically be exposed from the library but 'nm' showed no such symbol. 
So, I ended up exposing a my_init() function, which called rt_init() 
internally.

I've realized that rt_init() is sneaky: it returns 1 for success. WAT!? 
:p Then I discovered the more readable Runtime.initialize(), which is 
also sneaky by returning 'true' for success. WAT!? WAT!? :p

This worked:

import core.runtime;

extern (C)
int my_init() {
   return tried({
     return Runtime.initialize ? 0 : 1;
   });
}

my_deinit() is similar...

Ali

P.S.'tried' is a function template that I wrote, which catches all 
throwables, logs the issue, and returns 1 as an error code.


More information about the Digitalmars-d-learn mailing list