[Issue 21097] [REG2.083] Stack exhaustion upon large struct .destroy
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jul 31 09:54:19 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21097
--- Comment #2 from johanengelen at weka.io ---
Two potential solutions:
```
// Avoid stack allocation, at the cost of virtual call to get the init symbol.
{
auto arr = cast(ubyte[])typeid(T).initializer();
if (arr.ptr is null) {
(cast(ubyte*)val)[0 .. T.sizeof] = ubyte(0);
} else {
// Use fill to duplicate 'arr' to work around
https://issues.dlang.org/show_bug.cgi?id=16394
(cast(ubyte*)val)[0 .. T.sizeof].fillbytes(arr);
}
}
// Avoid stack allocation, at the cost of duplicating the init symbol (binary
size increase)
{
import core.stdc.string : memcpy;
shared static immutable T init = T.init;
memcpy(&chunk, &init, T.sizeof);
}
```
(one cannot access the init symbol directly)
--
More information about the Digitalmars-d-bugs
mailing list