Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Destructors of structs in arrays are now called as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Orvid committed Jan 13, 2015
1 parent f54084f commit 4166460
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 65 deletions.
43 changes: 33 additions & 10 deletions src/gc/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private
// make these functions available from rt.lifetime
void rt_finalize_struct(void* p, StructInfo inf, bool resetMemory) nothrow;
int rt_hasStructFinalizerInSegment(void* p, StructInfo inf, in void[] segment) nothrow;
void rt_finalize_array(void* p, bool resetMemory = true) nothrow;
int rt_hasArrayFinalizerInSegment(void* p, in void[] segment) nothrow;
void rt_finalize2(void* p, bool det, bool resetMemory) nothrow;
int rt_hasFinalizerInSegment(void* p, in void[] segment) nothrow;

Expand Down Expand Up @@ -1554,10 +1556,15 @@ struct Gcx

if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
if (pool.appendable.nbits && pool.appendable.test(biti) && rt_hasArrayFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_array(sentinel_add(p));
else
{
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
}
}
else if (!pool.finals.nbits || !pool.finals.test(biti) || !rt_hasFinalizerInSegment(sentinel_add(p), segment))
continue;
Expand Down Expand Up @@ -1612,10 +1619,15 @@ struct Gcx

if (pool.structFinals.nbits && pool.structFinals.test(biti))
{
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
if (pool.appendable.nbits && pool.appendable.test(biti) && rt_hasArrayFinalizerInSegment(sentinel_add(p), segment))
rt_finalize_array(sentinel_add(p));
else
{
auto si = *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof);
if (!rt_hasStructFinalizerInSegment(sentinel_add(p), si, segment))
continue;
rt_finalize_struct(sentinel_add(p), si, false);
}
}
else if (!pool.finals.nbits || !pool.finals.test(biti) || !rt_hasFinalizerInSegment(sentinel_add(p), segment))
continue;
Expand Down Expand Up @@ -2660,7 +2672,12 @@ struct Gcx
sentinel_Invariant(sentinel_add(p));

if (pool.structFinals.nbits && pool.structFinals.testClear(biti))
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
{
if (pool.appendable.nbits && pool.appendable.test(biti))
rt_finalize_array(sentinel_add(p));
else
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
}
else if (pool.finals.nbits && pool.finals.testClear(biti))
rt_finalize2(sentinel_add(p), false, false);

Expand Down Expand Up @@ -2734,7 +2751,12 @@ struct Gcx
pool.freebits.set(biti);

if (pool.structFinals.nbits && pool.structFinals.test(biti))
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
{
if (pool.appendable.nbits && pool.appendable.test(biti))
rt_finalize_array(sentinel_add(p));
else
rt_finalize_struct(sentinel_add(p), *cast(StructInfo*)(sentinel_add(p) + pool.getSize(p) - size_t.sizeof), false);
}
else if (pool.finals.nbits && pool.finals.test(biti))
rt_finalize2(sentinel_add(p), false, false);

Expand Down Expand Up @@ -2920,6 +2942,7 @@ struct Gcx
if (!pool.structFinals.nbits)
pool.structFinals.alloc(pool.mark.nbits);
pool.structFinals.data[dataIndex] |= orWith;

mask &= ~BlkAttr.FINALIZE; // prevent from setting normal finalize attribute.
}

Expand Down
Loading

0 comments on commit 4166460

Please sign in to comment.