【发布时间】:2014-04-23 14:53:22
【问题描述】:
我不会深入探讨这个问题(代码库已经有数千行并且相当复杂),所以我将尝试将...“窗口”最小化到我发现的内容。
这是触发“分段错误”的例程:
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");
}
}
几点说明:
- 声明的方法只不过是“绑定”,因此可以直接从 C 代码(实际上是 Bison)调用本机例程。
-
Statements_add函数使用Statements对象和子类Statement对象调用。
现在,它的怪异之处:
- 错误不会一直发生(实际上它不会像 99% 那样发生),但当它发生时,
s.add(st);语句似乎是罪魁祸首。 - 永远不会是 2 个参数之一 (
s,st)null。 - 现在,如果我评论 2 个
if... writeln... typeid语句,就会出现错误。 - 如果我取消注释它们(它们什么都不做,是吗?),它总是有效 - 已修复 - 宾果游戏!
怎么了???
更多细节:
- 编译器: DMD64 D 编译器 v2.065
- 调试器: lldb
- 操作系统: OSX 10.9.2
【问题讨论】: