I hate class destructors with a burning passion

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 9 14:01:39 UTC 2021


On 6/9/21 7:02 AM, Steven Schveighoffer wrote:
> Come to think of it, an InvalidMemoryOperationError should use malloc 
> instead of GC, then maybe we can get stack traces?

I delved into this a bit, trying to see where the GC allocations are 
happening. There are some functions that are not marked nogc that can be.

I got hung up on core.demangle.demangle.

It's used here: 
https://github.com/dlang/druntime/blob/751f5665a31ea0f150d71b22a9852abacc2f61ec/src/core/runtime.d#L830-L865

Ironically, it demangles the string into a buffer, and then truncates 
that allocated buffer if it was allocated on the heap into the static 
buffer (and essentially throws away all the work if truncated).

We can possibly fix this by telling the demangler to use malloc (maybe 
in a nogc version), or tell the demangler to truncate for us if it runs 
out of room in the buffer (preferred).

The demangler is quite complex, I tried something cute by making a type 
that is a fake unlimited size array (but doesn't write to anything past 
the buffer), but it was more trouble than it's worth.

I'm 99% sure we could have a nogc stack trace for 
InvalidMemoryOperationError if we had a nogc demangler. Everything else 
seems already nogc, just not fully marked.

-Steve


More information about the Digitalmars-d mailing list