我不会深入研究这个问题(代码库已经有数千行而且非常复杂),所以我会尝试将..."窗口"缩小到我发现的位置.
这是触发"分段错误"的例程:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
几点说明:
Statements_add使用Statements对象和子类Statement对象调用该函数.现在,它的奇怪之处:
s.add(st);声明似乎是罪魁祸首.s,st)null.if... writeln... typeid语句,那么错误就在那里.这是怎么回事???
更多细节: