shared lib

Jacob Carlborg doob at me.com
Tue Nov 15 23:29:23 PST 2011


On 2011-11-16 01:27, Ellery Newcomer wrote:
> On 11/15/2011 01:19 AM, Jacob Carlborg wrote:
>> On 2011-11-14 19:05, Ellery Newcomer wrote:
>>
>> core.runtime.Runtime.initialize
>
> cool
>
>>
>> Not sure if that will initialize everything properly. Have a look in
>> rt.dmain2.main and make sure you do that same initialize the runtime.
>
> yep, found that file yesterday a little after I posted
>
>>
>> It would be better if rt.dmain2.main would call rt.dmain2.rt_init
>> instead of do all the initialize directly in main.
>>
>
> I just call rt_init and rt_term. The one thing I'm wondering about is
> what happens when I need to load multiple d shared libs (the shallow
> answer is rt_term crashes, but rt_init doesn't). I assume it would
> create two instances of the d runtime, which is just lovely from a
> memory leakage perspective.

Make sure rt_init and rt_term are only called once. You can take a look 
how it's done in Tango, I've implemented the support for dynamic 
libraries for Mac OS X.

http://www.dsource.org/projects/tango/browser/trunk/tango/core/rt/compiler/ldc/rt/dmain2.d

If you don't want to look at Tango code you can have a look at: 
http://d.puremagic.com/issues/attachment.cgi?id=607

Look at the diff for src/rt/dylib_fixes.c and src/rt/dmain2.d.

The GCC attribute __attribute__((constructor)) and 
__attribute__((destructor)) can be used to initialize and terminate the 
runtime, look at the diff for src/rt/dylib_fixes.c

> Now if only I could remember why I wanted to use pyd in the first place..

Haha.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list