X-Git-Url: https://git.llucax.com/software/druntime.git/blobdiff_plain/5a07183e26b7ca151959629420a83f59af5339f3..ee7c028ebdd89ffc05410551c6e4812187049279:/src/compiler/dmd/lifetime.d?ds=sidebyside diff --git a/src/compiler/dmd/lifetime.d b/src/compiler/dmd/lifetime.d index 55861b0..2b77809 100644 --- a/src/compiler/dmd/lifetime.d +++ b/src/compiler/dmd/lifetime.d @@ -29,10 +29,10 @@ module rt.lifetime; private { - import stdc.stdlib; - import stdc.string; - import stdc.stdarg; - debug(PRINTF) import stdc.stdio; + import core.stdc.stdlib; + import core.stdc.string; + import core.stdc.stdarg; + debug(PRINTF) import core.stdc.stdio; } @@ -66,7 +66,7 @@ private extern (C) size_t gc_sizeOf( void* p ); extern (C) BlkInfo gc_query( void* p ); - extern (C) void onFinalizeError( ClassInfo c, Exception e ); + extern (C) void onFinalizeError( ClassInfo c, Throwable e ); extern (C) void onOutOfMemoryError(); extern (C) void _d_monitordelete(Object h, bool det = true); @@ -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; } @@ -499,7 +529,7 @@ extern (C) void rt_finalize(void* p, bool det = true) if ((cast(void**)p)[1]) // if monitor is not null _d_monitordelete(cast(Object)p, det); } - catch (Exception e) + catch (Throwable e) { onFinalizeError(**pc, e); }