<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 17 Aug 2024 at 22:46, kinke via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Saturday, 17 August 2024 at 09:31:53 UTC, Manu wrote:<br>
> I mean, there's also the `assertHandler()` stuff, but I don't <br>
> really see the point; I'd rather just replace the assert <br>
> handler symbol directly. Using `assertHandler` is awkward <br>
> because you need a static constructor to register it at <br>
> runtime, and then anything you do in your assert handler almost <br>
> inevitably leads to bootup issues with cyclic module <br>
> dependencies because everything leads back to assert.<br>
<br>
You can set the handler in a CRT constructor, which avoids any <br>
cycles and makes sure it is installed before initializing <br>
druntime (`rt_init()`), so should really cover all asserts:<br>
```<br>
pragma(crt_constructor)<br>
void setupAssertHandler()<br>
{<br>
import core.exception : assertHandler;<br>
assertHandler = &myAssertHandler;<br>
}<br>
<br>
void myAssertHandler(string file, size_t line, string msg) nothrow<br>
{<br>
// print...<br>
import core.stdc.stdlib;<br>
abort(); // or something like that<br>
}<br>
```<br>
<br>
`@core.attribute.weak` isn't implemented by DMD, plus needs <br>
emulation on Windows (done by LDC) with according limitations. <br>
The extra indirection via that custom assert handler in druntime <br>
works e.g. for a pre-linked druntime DLL too.<br></blockquote><div><br></div><div>That's a reasonable solution. Thanks for the tip!</div><div>I'd still prefer to just replace a weak library call though, so that calls to assert are direct and don't add a bunch of extra layers to the callstack.</div><div><br></div><div>I'd also really like it if the condition were stringified and handed to the assert handler... that seems like a weird oversight?<br></div></div></div>