Override assert handler
Manu
turkeyman at gmail.com
Sat Aug 17 09:31:53 UTC 2024
On Sat, 17 Aug 2024 at 18:42, ryuukk_ via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:
> ```
> import core.stdc.stdio;
>
> void main()
> {
> assert(false, "no");
> }
>
> extern(C) void _d_assert_msg (string msg, string file, uint line)
> {
> printf("assert failed: %.*s:%u %.*s\n", cast(int)file.length,
> file.ptr, line, cast(int)msg.length, msg.ptr);
> }
> ```
>
> ```
> assert failed: onlineapp.d:4 no
> ```
>
>
> This works
>
> That's funny, because i was thinking about that just right now,
> and how the default message of druntime sucks ass
>
> ```
> core.exception.AssertError at onlineapp.d(5): no
> ----------------
> ??:? _d_assert_msg [0x5625e324e580]
> ./onlineapp.d:5 _Dmain [0x5625e324e4e4]
>
> ```
>
>
> assert message is obfuscated and surrounded with unpleasant
> characters to read, it should be clear by default, i want to send
> a PR but i can't be bothered to read druntime codebase, a waste
> of time
>
Orly? My project is rather more complex than this... I'll give it some more
time to find where it goes sideways.
What was your build cmdline? Did you link druntime?
I mean, there's also the `assertHandler()` stuff, but I don't really see
the point; I'd rather just replace the assert handler symbol directly.
Using `assertHandler` is awkward because you need a static constructor to
register it at runtime, and then anything you do in your assert handler
almost inevitably leads to bootup issues with cyclic module dependencies
because everything leads back to assert.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20240817/364adeca/attachment.htm>
More information about the Digitalmars-d
mailing list