【问题标题】:Garbage Collection, pointers and scope in DD中的垃圾收集,指针和范围
【发布时间】:2011-07-11 21:44:02
【问题描述】:

对于这篇长篇文章提前道歉 - 我遇到了一个我认为可能与垃圾收集有关的问题。

我有一个像这样包装 DMDScript 的类:

/**
*   Wrapper class for the DMDScript 
*/
class ScriptingHost
{
    protected static CallContext *cc ;  // Call Context for interaction with the script.
    protected static Program prg ;      // Reference to program object (this is where the script buffer gets parsed)

    static this()
    {
        // create our program instance
        prg = new Program();

        // create reference to call Context 
        cc = prg.callcontext;

        Stdout( "cc.global: " )( cc.global ).newline ;

        // add some built-in functions, like trace() and trigger()
        DnativeFunction dnfTrace = new DnativeFunction( &jsTrace, "trace", 0, Dfunction.getPrototype() ) ;
        DnativeFunction dnfTrigger = new DnativeFunction( &jsTrigger, "trigger", 0, Dfunction.getPrototype() ) ;

        // add it to the call context
        cc.global.Put("trace", dnfTrace , 0);
        cc.global.Put("trigger", dnfTrigger , 0);
    }

    /***********************************************************************
    *   Helper functions for D<-->JS interaction
    ************************************************************************/

    /**
    *   Trace (output)
    */
    protected static void* jsTrace( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) 
    {
        Stdout( "<<" )( arglist ).newline ;
        return null;
    }  

    /**
    *   Trigger
    */
    protected static void* jsTrigger( Dobject pthis, CallContext* cc, Dobject othis, Value* ret, Value[] arglist) 
    {
        Stdout( "<<" )( arglist ).newline ;
        return null;
    }  
}

到目前为止,一切都很好,我可以毫无错误地运行代码。 输出:

cc.global: dmdscript_tango.dglobal.Dglobal

我还向 ScriptingHost 添加了一个跟踪 cc.global 对象的方法:

public static void testGlobal()
{
    Stdout( "testGlobal: " )( cc.global ).newline.flush ; 
}

...这也可以正常工作 - 当我尝试从类 ala 之外访问它时出现问题:

int main()
{
    Stdout( "DMDScriptTest" ).newline ;
    ScriptingHost.testGlobal() ;
    Stdout( "global: " )( ScriptingHost.global() ).newline.flush ; 
    ScriptingHost.testGlobal() ;
}

然后我得到以下错误:

cc.global: dmdscript_tango.dglobal.Dglobal
DMDScriptTest
testGlobal: dmdscript_tango.dglobal.Dglobal
object.Exception: Illegal Instruction
----------------
[  5fd264]       0+0   ???                                                                                 @0+1975211 :0 
[  404e05]       0+0   tango.text.convert.Layout.Layout!(char).Layout.parse.process                     @0+29 c:\dmd\dmd\bin\..\import\tango\text\convert\Layout.d:595 
[  404875]       0+0   tango.text.convert.Layout.Layout!(char).Layout.parse                             @0+65 c:\dmd\dmd\bin\..\import\tango\text\convert\Layout.d:603 
[  40463b]       0+0   tango.text.convert.Layout.Layout!(char).Layout.convert                           @0+34 c:\dmd\dmd\bin\..\import\tango\text\convert\Layout.d:347 
[  40418e]       0+0   tango.io.stream.Format.FormatOutput!(char).FormatOutput.print                    @0+67 c:\dmd\dmd\bin\..\import\tango\io\stream\Format.d:172 
[  40206c]       0+0   __Dmain                                                                          @0+45 test2.d:87 
[  4380b5]       0+0   rt.compiler.dmd.rt.dmain2.main.runMain                                           @0+119292 :0 
[  43800b]       0+0   rt.compiler.dmd.rt.dmain2.main.tryExec                                           @0+119122 :0 
[  4380f3]       0+0   rt.compiler.dmd.rt.dmain2.main.runAll                                            @0+119354 :0 
[  43800b]       0+0   rt.compiler.dmd.rt.dmain2.main.tryExec                                           @0+119122 :0 
[  437fc3]       0+0   _main                                                                            @0+119050 :0 
[  44c980]       0+0   _mainCRTStartup                                                                  @0+203463 :0 
[75e133c8]       0+0   ???                                                                                 @0+1973388559 :0 
[76f49ed0]       0+0   ???                                                                                 @0+1991438359 :0 
[76f49ea0]       0+0   ???                                                                                 @0+1991438311 :0 
global: unittest start
unittest end

有没有人能解释一下这里的问题——也许是如何解决这个问题,拜托? :)

编辑:我使用的是 Windows D1-Tango 设置。我使用的版本是 0.99.9 Tango/DMD 1.056 Kai bundle。

谢谢,

【问题讨论】:

    标签: garbage-collection scope d tango dmd


    【解决方案1】:

    首先,您使用的是哪个操作系统?基于错误我猜windows?您使用的是哪个版本的 dmd/tango? 32位还是64位?尝试通过反汇编程序运行您的应用程序并查看 5fd264 中列出的指令(搜索输出)。我们应该能够通过上述一些信息提供更多帮助。

    【讨论】:

    • 我正在使用 DMD 1.056/Tango 0.99.9 Kai,是的。那就是说我的系统正在运行64位。如何检查您正在运行的探戈是 32 位还是 64 位?
    • 如果您使用的是 Windows/OS X,那么它是 32 位的。如果您使用的是 Linux,file libtango.a 会告诉您。或dmd -v。正如 dsmicha 所提到的,64 位 dmd 首次发布时存在问题 - 您可以尝试更新的 dmd 看看是否可以解决问题吗? (我相信 tango 网站上有一些较新的预编译二进制文件)。
    • 我正在使用latest bundle from tango。据我了解,我不能只切换到新版本的 DMD,因为它会破坏探戈(?)
    • 我尝试通过 ddbg 运行它,即使我不擅长使用它。这就是我所拥有的:paste2.org/p/1516916
    【解决方案2】:

    您使用的是哪个版本的 DMD?如果您仍在使用 1.067,在 64 位模式下编译并且使用足够古老的硬件,那么您可能会遇到问题。 1.067 是第一个支持 64 位的版本,有一个错误会使用 LAHF 和 SAHF 指令,这些指令在非常旧的 64 位 CPU 上不受支持。

    【讨论】:

    • 我在 Windows 上使用 DMD 1.056/Tango 0.99.9 Kai。我正在运行 64 位,但我 99% 确定我的 D+Tango 安装是 32 位
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2012-10-03
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 2011-10-22
    • 2019-01-28
    相关资源
    最近更新 更多