Reputation: 22820
I won't go very deep into the issue (the codebase is already thousands of lines and quite complex), so I'll try to miniminise the... "window" to what I've spotted.
Here's the routine triggering the "Segmentation Fault" :
extern (C)
{
void* Statements_new() { return cast(void*)(new Statements()); }
void Statements_add(Statements s, Statement st)
{
//writeln("In here");
if (s is null) writeln("StatemenTS are null");
else writeln("not null : "~ typeid(s).name);
if (st is null) writeln("statement is null");
else writeln("not null : " ~ typeid(st).name);
s.add(st);
//writeln("Out of here");
}
}
A few notes :
Statements_add
function is called with a Statements
object and a subclassed Statement
object.Now, the weirdness of it :
s.add(st);
statement seems the culprit.s
,st
) null
.if... writeln... typeid
statements, the error is there.What's going on???
A few more details :
Upvotes: 2
Views: 163
Reputation: 25187
If you are passing the only reference of an object allocated in D code from the D heap to non-D code, then you must either register it as a GC root, or change your code to use malloc
instead of allocating from the managed D heap. Otherwise, the GC will think that the object is unused, and collect it to free memory.
Upvotes: 7