事先對長文章道歉 - 我有一個問題,我認爲可能與垃圾收集有關。垃圾收集,指針和範圍在D
我有一個類,包裝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捆綁包。
謝謝,
我使用DMD 1.056 /探戈0.99.9啓,是的。這就是說我的系統正在運行64位。你如何檢查你的32位或64位探戈? – Frederik
如果你在Windows/OS X上,那麼它是32位。如果你在Linux上,'libtango.a'會告訴你。或'dmd -v'。正如dsmicha提到的那樣,64位dmd在首次發佈時存在一個問題 - 你能否嘗試更新的dmd並查看是否修復了它? (我相信在探戈網站上有一些更新的預編譯二進制文件)。 – Robert
我正在使用[tango的最新捆綁包](http://downloads.dsource.org/projects/tango/0.99.9/tango-0.99.9-bin-win32.zip)。從我的理解,我不能只是切換到更新版本的DMD,因爲它會打破探戈(?) – Frederik