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
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(); }
Fixed DMD 1.005
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル