setAssertHandler (druntime) segfaults

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Jul 24 14:34:33 PDT 2009


On Fri, Jul 24, 2009 at 4:37 PM, Lutger<lutger.blijdestijn at gmail.com> wrote:
> There is a function setAssertHandler in druntime, but when I try to use it
> it segfaults. I'm not sure how it should be used, this is a complete example
> of what I try to do:
>
> import std.stdio;
> import core.exception;
>
> void handleAssertion(string file, size_t line, string msg = null)
> {
>    writefln("assert in %s at line %s", file, line);
> };
>
> static this()
> {
>    setAssertHandler( &handleAssertion  );
> }
>
> unittest { assert(false); }
>
> void main() {}
>
>
> output:
> assert in test at line 16
> Segmentation fault
>
> This is with dmd 2.031 on linux. Is this a bug, am I doing something wrong?

Hm, it might - and I'm just taking a wild guess here - be that
std.stdio hasn't yet been initialized when you do the writefln in your
assertion handler.  But you really should try using a debugger to get
a stacktrace.


More information about the Digitalmars-d-learn mailing list