3

Apologies in advance about the long post - I'm having a problem I think might be related to garbage collection.

I have a class that wraps DMDScript like this:

/**
*   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;
    }  
}

So far, everything is fine and I can run the code with no errors. Output:

cc.global: dmdscript_tango.dglobal.Dglobal

I also added a method to ScriptingHost that traced the cc.global object:

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

...which also works fine - The problem arises when I try accessing it from outside the class ala:

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

Then I get the following error:

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

Is anyone able to shed some light on the issue here - and perhaps how to work around it, please? :)

edit: I am using a windows D1-Tango setup. The version I'm using is the 0.99.9 Tango/DMD 1.056 Kai bundle .

thanks,

Frederik
  • 594
  • 3
  • 9
  • 24

2 Answers2

1

First of all, which operating system are you using? Based on the error I'm guessing windows? Which version of dmd/tango are you using? 32 bit or 64 bit? Try running your application through a disassembler and looking what instruction is listed at 5fd264 (search through the output). We should be able to help more with some of the information above.

Robert
  • 436
  • 2
  • 3
  • I'm using DMD 1.056/Tango 0.99.9 Kai, yes. That said my system is running 64bit. How do you check if your running 32bit or 64 bit tango? – Frederik Jul 12 '11 at 05:55
  • If you're on Windows/OS X then it's 32 bit. If you're on Linux, `file libtango.a` will tell you. Or `dmd -v`. As dsmicha mentioned, there was an issue with 64bit dmd when it was first released - could you try a more recent dmd and see if that fixes it? (I believe there are some newer precompiled binaries on the tango site). – Robert Jul 12 '11 at 17:21
  • I'm using the [latest bundle from tango](http://downloads.dsource.org/projects/tango/0.99.9/tango-0.99.9-bin-win32.zip). From what I understand, I can't just switch to a newer version of DMD, since it'll break tango(?) – Frederik Jul 12 '11 at 18:40
  • I've tried to run it through ddbg even though i'm not that good at using it. This is what I've got: http://paste2.org/p/1516916 – Frederik Jul 12 '11 at 22:16
0

What version of DMD are you using? If you're still using 1.067, are compiling in 64-bit mode and are using sufficiently ancient hardware, you may have a problem. 1.067 was the first version with 64-bit support and had a bug that would use the LAHF and SAHF instructions, which weren't supported on very old 64-bit CPUs.

dsimcha
  • 67,514
  • 53
  • 213
  • 334
  • I'm using DMD 1.056/Tango 0.99.9 Kai on windows. I'm running 64 bit, but i'm 99% sure that my D+Tango installation is 32 bit – Frederik Jul 12 '11 at 05:59