X-Git-Url: https://git.llucax.com/software/druntime.git/blobdiff_plain/5a07183e26b7ca151959629420a83f59af5339f3..471a1a23753606871f4d85eb951f615e5310792e:/src/compiler/dmd/lifetime.d?ds=inline diff --git a/src/compiler/dmd/lifetime.d b/src/compiler/dmd/lifetime.d index 55861b0..e5ef60f 100644 --- a/src/compiler/dmd/lifetime.d +++ b/src/compiler/dmd/lifetime.d @@ -81,6 +81,15 @@ private } +/** + * + */ +extern (C) void* _d_allocmemory(size_t sz) +{ + return gc_malloc(sz); +} + + /** * */ @@ -397,25 +406,46 @@ struct Array /** - * + * This function has been replaced by _d_delarray_t */ -void* _d_allocmemory(size_t nbytes) +extern (C) void _d_delarray(Array *p) { - return gc_malloc(nbytes); + if (p) + { + assert(!p.length || p.data); + + if (p.data) + gc_free(p.data); + p.data = null; + p.length = 0; + } } /** * */ -extern (C) void _d_delarray(Array *p) +extern (C) void _d_delarray_t(Array *p, TypeInfo ti) { if (p) { assert(!p.length || p.data); - if (p.data) + { + if (ti) + { + // Call destructors on all the sub-objects + auto sz = ti.tsize(); + auto pe = p.data; + auto pend = pe + p.length * sz; + while (pe != pend) + { + pend -= sz; + ti.destroy(pend); + } + } gc_free(p.data); + } p.data = null; p.length = 0; }