| Thread overview |
|---|
September 03, 2015 Object.destroy() broken? | ||||
|---|---|---|---|---|
| ||||
It seems that Object.destory() doesn't handle static arrays properly. It doesn't destroy the contained elements.
Example:
struct S
{
int x;
this(int x) { writeln("ctor"); }
this(this) { writeln("ctor(postblit)"); }
~this() { writeln("dtor"); }
}
void main(string[] args)
{
S[2]* arr = cast(S[2]*)calloc(1, S.sizeof);
emplace(arr, S(1));
destroy(*arr);
free(arr);
}
output has 5 ctors, and 3 dtors:
ctor
ctor(postblit)
ctor(postblit)
dtor
ctor(postblit)
dtor
ctor(postblit)
dtor
if I modify this overload of destroy() like this, then it's fine:
void destroy(T : U[n], U, size_t n)(ref T obj) if (!is(T == struct))
{
foreach(i; 0..n) // +
destroy(obj[i]); // +
obj[] = U.init;
}
output has 5 ctors, and 5 dtors, as expected:
ctor
ctor(postblit)
ctor(postblit)
dtor
dtor
dtor
ctor(postblit)
dtor
ctor(postblit)
dtor
| ||||
September 03, 2015 Re: Object.destroy() broken? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Thursday, 3 September 2015 at 06:57:12 UTC, bitwise wrote: > [...] Nevermind... fixed. https://github.com/D-Programming-Language/druntime/pull/362 | |||
September 03, 2015 Re: Object.destroy() broken? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Thursday, 3 September 2015 at 07:25:09 UTC, bitwise wrote: > On Thursday, 3 September 2015 at 06:57:12 UTC, bitwise wrote: >> [...] > > Nevermind... fixed. > > https://github.com/D-Programming-Language/druntime/pull/362 Derp.. No it's not. https://github.com/D-Programming-Language/druntime/blob/master/src/object.d#L2728 Bed time. | |||
September 03, 2015 Re: Object.destroy() broken? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Thursday, 3 September 2015 at 06:57:12 UTC, bitwise wrote: > It seems that Object.destory() doesn't handle static arrays properly. It doesn't destroy the contained elements. > > [...] https://issues.dlang.org/show_bug.cgi?id=15009 https://github.com/D-Programming-Language/druntime/pull/1375 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply