I hate class destructors with a burning passion

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 9 11:02:42 UTC 2021


On 6/8/21 10:37 PM, Walter Bright wrote:
> On 6/6/2021 4:54 AM, Mathias LANG wrote:
>  > https://github.com/dlang/druntime/pull/3476/files
> 
> Frankly, the whole jazz with assert() went way off the rails. Assert 
> should go directly to Jail, it should not pass Go or collect $200. All 
> these layers it goes through is just madness.
> 
> Allocating via the GC is in assert is just ridiculous, as the program is 
> going to exit shortly anyway. There won't ever be a need to run a 
> collection on it. Just malloc away and fuggeddabootet.

Come to think of it, an InvalidMemoryOperationError should use malloc 
instead of GC, then maybe we can get stack traces?

Note that fixing asserts so they don't GC-allocate is just masking what 
the true problem here is -- any InvalidMemoryOperationError reports zero 
context for why it was thrown. In *this case* it happened to be an 
assert inside a destructor. But there are other times where an 
inadvertent destructor allocation causes an error, and it's impossible 
to find the spot where it was triggered without using a debugger.

-Steve


More information about the Digitalmars-d mailing list