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 :
- The declared methods are nothing but "bindings" so that native routines can be called directly from C code (Bison actually).
- The
Statements_add
function is called with aStatements
object and a subclassedStatement
object.
Now, the weirdness of it :
- The error doesn't happen all the time (actually it doesn't happen like 99% of the time), but when it does, the
s.add(st);
statement seems the culprit. - Never ever is one of the 2 parameters (
s
,st
)null
. - Now, if I comment the 2
if... writeln... typeid
statements, the error is there. - If I uncomment them (they don't do anything, huh?), it always works - fixed - bingo!
What's going on???
A few more details :
- Compiler : DMD64 D Compiler v2.065
- Debugger : lldb
- OS : OSX 10.9.2