www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Allow calling of original druntime functions within 'hooked' functions

According to http://wiki.dlang.org/Runtime_Hooks you can hook a 
bunch of functions of the druntime to provide different behavior.

I am using that to have (from my perspective) sane behavior on 
asserts, e.g.:


extern(C) void abort();

extern(C) void _d_assert_msg(string msg, string file, uint line)
{
     abort();
}

extern(C) void _d_assert(string file, uint line)
{
     abort();
}

extern(C)void _d_assertm(ModuleInfo* m, uint line)
{
     abort();
}



Now, with the concept of Errors which are more or less on the 
same level as asserts regarding severity, I'd like to have the 
same behavior.

In my specific case, a RangeError is thrown.
There is a function listed on the earlier link that sounds like 
it does what i want:

extern (C) void onRangeError(string file, size_t line)
{
     abort();
}

However, this has no effect.

One solution I saw was to override _d_throwc, check whether the 
object being thrown is a child of Error and if so, abort(); else 
call the original _d_throwc.

But the problem is, there is no way I can call the original 
_d_throwc now that I overrode it.

The overrideable assert functions are implemented like

     void _d_assert(string file, uint line)
     {
         onAssertError(file, line);
     }

so the actual implementation is one function call further.
Doing the same for _d_throwc would allow me to implement the 
desired behavior for me. E.g. have


extern (C) void onThrow(Object *h)
{
     // Original implementation
}

extern (C) void _d_throwc(Object *h)
{
     onThrow(h);
}

In the druntime.

Opinions?
Sep 25 2015