www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Caller of dynamic library crashes with SIGSEV if D code allocates

reply "Gabor Mezo" <gabor.mezo outlook.com> writes:
Hello,

I've opened an other thread for this, because this is a different 
issue.

Previous issue is there: 
http://forum.dlang.org/thread/zzjeajhjpzhnvgxquluu forum.dlang.org#post-vuzttuewxyvuihubgtas:40forum.dlang.org

The current issue is if I build a dynamic library with DUB and 
call externals form another application, and my D code
allocates anything on heap, the calling process crashes with
SIGSEV.

I mean it works:

extern (C)
{
	int ping()
	{
		return 555;
	}
}

But it doesn't:

extern (C)
{
	int ping()
	{
                 try { throw new Exception("foo"); } catch
(Exception ex) { }
		return 555;
	}
}

or this one crashes too:

extern (C)
{
	int ping()
	{
                 auto foo = new Object();
		return 555;
	}
}
Dec 14 2014
next sibling parent "Gabor Mezo" <gabor.mezo outlook.com> writes:
I's solved by ketmar:

"did you called `rt_init()` for your dynamic library? you have to 
do
that in the calling process. and don't forget to call `rt_term()` 
on
exiting."

Yea, I missed that. It works. Thanks.
Dec 14 2014
prev sibling parent Martin Nowak <code+news.digitalmars dawg.eu> writes:
 The current issue is if I build a dynamic library with DUB and call
 externals form another application, and my D code
 allocates anything on heap, the calling process crashes with
 SIGSEV.
Don't forget to link against libphobos2.so using -defaultlib=libphobos2.so.
Dec 14 2014