www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 915] New: dmd generate bad form return(retn 4) for invariant func

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=915

           Summary: dmd generate bad form return(retn 4) for invariant func
           Product: D
           Version: 1.004
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P1
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: davidl 126.com


import std.stdio;
interface IUnknown{
        extern(Windows):
        void func();
}
class ComObject :IUnknown
{
extern (Windows):
        void func()
        {writefln(`comobject`);
        }
}
interface IDataObject: IUnknown
{
        extern(Windows):
        void method();
}
package class invarianttest:ComObject, IDataObject
{
        invariant
        {
                writefln(`hello invariant`);
        }

extern (Windows):
        override void func()
        {
        int esp;
        asm{
                mov esp,ESP;
        }
        printf("\n%d",esp);
        printf(`func`);
        }
        void method()
        {
                writefln(`method`);
        }
}
void main()
{
        auto inst= new invarianttest;
        int esp;
        asm{
                mov esp,ESP;
        }
        inst.func();
        inst.method();
        writefln("\n%d",esp);
        asm{
                mov esp,ESP;
        }
        writefln("\n%d",esp);
}

we get runtime AV when the we return from our own invariant to _d_invariant
the problem is dmd generate the retn 4 for the return of our own invariant func


-- 
Feb 01 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=915






a simpler case, but we don't see any exception get caught. 
de-comment the ret , we can see the code work correctly.
though i find in some situation , the case actually in a ctor
before calling my invariant , dmd first push some thing on the stack
and the windows directive makes it seems right( that's quite weird)
 and the next time calling my invariant in my case, it's 
from _d_invariant, the situation is different , _d_invariant need 
the invariant func retn directly instead of "retn 4".

import std.stdio;
package class invarianttest
{
        extern(D):
        this(Object test,int i)
        {
                myobject = test;
                writefln(`class tester`,i);
        }
        extern(Windows):
        invariant
        {
                writefln(`hello invariant`);
                asm
                {
//                      ret;
                }
        }

extern (Windows):
        void func()
        {
                printf(`func`);
        }
        void method()
        {
                writefln(`method`);
        }
        extern(D):
        private:
        Object myobject;
}
void main()
{
        Object t=new Object;
        auto inst= new invarianttest(t,1);
        inst.func();
        inst.method();
}


-- 
Feb 01 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=915


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 1.005


-- 
Feb 12 2007