From 2b7577f918513f8bc8a3abc7199e37bb40e44723 Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 10 Oct 2008 21:49:12 +0000 Subject: [PATCH] Added _d_delarray_t and _d_allocmemory. git-svn-id: http://svn.dsource.org/projects/druntime/trunk@19 4a9d5153-6564-4b3f-b5e1-7e8e9dac548f --- src/compiler/dmd/lifetime.d | 40 ++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) 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; } -- 2.43.0