Mercurial > projects > ldc
diff tango/lib/compiler/llvmdc/lifetime.d @ 203:e881c9b1c738 trunk
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
Changed: removed the crappy realloc based dynamic memory runtime and started moving over to DMD style runtime support, part of moving to real GC.
Fixed: dynamic arrays now use GC runtime for allocating memory.
Fixed: new expression now use GC for allocating memory.
Changed: revamped the dynamic array support routines related to dynamic memory.
Fixed: assertions no longer create exsessive allocas.
Changed: misc. minor cleanups.
author | lindquist |
---|---|
date | Tue, 13 May 2008 14:42:09 +0200 |
parents | ce7b81fb957f |
children | c4c9b4ac021b |
line wrap: on
line diff
--- a/tango/lib/compiler/llvmdc/lifetime.d Mon May 12 23:49:07 2008 +0200 +++ b/tango/lib/compiler/llvmdc/lifetime.d Tue May 13 14:42:09 2008 +0200 @@ -189,31 +189,30 @@ } } - /** * */ struct Array { size_t length; - byte* data; + void* data; } ++/ /** * Allocate a new array of length elements. * ti is the type of the resulting array, or pointer to element. * (For when the array is initialized to 0) */ -extern (C) Array _d_newarrayT(TypeInfo ti, size_t length) +extern (C) void* _d_newarrayT(TypeInfo ti, size_t length) { void* p; - Array result; auto size = ti.next.tsize(); // array element size debug(PRINTF) printf("_d_newarrayT(length = x%x, size = %d)\n", length, size); if (length == 0 || size == 0) - return Array(); + return null; version (D_InlineAsm_X86) { @@ -230,24 +229,25 @@ p = gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0); debug(PRINTF) printf(" p = %p\n", p); memset(p, 0, size); - return Array(length, p); + return p; Loverflow: onOutOfMemoryError(); + return null; } /** * For when the array has a non-zero initializer. */ -extern (C) Array _d_newarrayiT(TypeInfo ti, size_t length) +extern (C) void* _d_newarrayiT(TypeInfo ti, size_t length) { - Array result; + void* result; auto size = ti.next.tsize(); // array element size debug(PRINTF) printf("_d_newarrayiT(length = %d, size = %d)\n", length, size); if (length == 0 || size == 0) - result = Array(); + result = null; else { auto initializer = ti.next.init(); @@ -285,15 +285,17 @@ memcpy(p + u, q, isize); } } - va_end(q); - result = Array(length, p); + result = p; } return result; Loverflow: onOutOfMemoryError(); + return null; } +/+ + /** * */ @@ -400,8 +402,6 @@ return result; } -+/ - /** * */ @@ -410,6 +410,16 @@ return gc_malloc(nbytes); } ++/ + +/** + * for allocating a single POD value + */ +extern (C) void* _d_allocmemoryT(TypeInfo ti) +{ + return gc_malloc(ti.tsize(), (ti.flags() & 1) ? BlkAttr.NO_SCAN : 0); +} + /+ /** @@ -496,16 +506,14 @@ } } -/+ - /** * Resize dynamic arrays with 0 initializers. */ -extern (C) byte[] _d_arraysetlengthT(TypeInfo ti, size_t newlength, Array *p) +extern (C) byte* _d_arraysetlengthT(TypeInfo ti, size_t newlength, size_t plength, byte* pdata) in { assert(ti); - assert(!p.length || p.data); + assert(!plength || pdata); } body { @@ -516,7 +524,7 @@ { printf("_d_arraysetlengthT(p = %p, sizeelem = %d, newlength = %d)\n", p, sizeelem, newlength); if (p) - printf("\tp.data = %p, p.length = %d\n", p.data, p.length); + printf("\tp.data = %p, p.length = %d\n", pdata, plength); } if (newlength) @@ -543,26 +551,26 @@ debug(PRINTF) printf("newsize = %x, newlength = %x\n", newsize, newlength); - if (p.data) + if (pdata) { - newdata = p.data; - if (newlength > p.length) + newdata = pdata; + if (newlength > plength) { - size_t size = p.length * sizeelem; - auto info = gc_query(p.data); + size_t size = plength * sizeelem; + auto info = gc_query(pdata); - if (info.size <= newsize || info.base != p.data) + if (info.size <= newsize || info.base != pdata) { - if (info.size >= PAGESIZE && info.base == p.data) + if (info.size >= PAGESIZE && info.base == pdata) { // Try to extend in-place - auto u = gc_extend(p.data, (newsize + 1) - info.size, (newsize + 1) - info.size); + auto u = gc_extend(pdata, (newsize + 1) - info.size, (newsize + 1) - info.size); if (u) { goto L1; } } newdata = cast(byte *)gc_malloc(newsize + 1, info.attr); - newdata[0 .. size] = p.data[0 .. size]; + newdata[0 .. size] = pdata[0 .. size]; } L1: newdata[size .. newsize] = 0; @@ -575,15 +583,14 @@ } else { - newdata = p.data; + newdata = pdata; } - p.data = newdata; - p.length = newlength; - return newdata[0 .. newlength]; + return newdata; Loverflow: onOutOfMemoryError(); + return null; } @@ -595,10 +602,10 @@ * initsize size of initializer * ... initializer */ -extern (C) byte[] _d_arraysetlengthiT(TypeInfo ti, size_t newlength, Array *p) +extern (C) byte* _d_arraysetlengthiT(TypeInfo ti, size_t newlength, size_t plength, byte* pdata) in { - assert(!p.length || p.data); + assert(!plength || pdata); } body { @@ -616,7 +623,7 @@ { printf("_d_arraysetlengthiT(p = %p, sizeelem = %d, newlength = %d, initsize = %d)\n", p, sizeelem, newlength, initsize); if (p) - printf("\tp.data = %p, p.length = %d\n", p.data, p.length); + printf("\tp.data = %p, p.length = %d\n", pdata, plength); } if (newlength) @@ -642,27 +649,27 @@ } debug(PRINTF) printf("newsize = %x, newlength = %x\n", newsize, newlength); - size_t size = p.length * sizeelem; + size_t size = plength * sizeelem; - if (p.data) + if (pdata) { - newdata = p.data; - if (newlength > p.length) + newdata = pdata; + if (newlength > plength) { - auto info = gc_query(p.data); + auto info = gc_query(pdata); - if (info.size <= newsize || info.base != p.data) + if (info.size <= newsize || info.base != pdata) { - if (info.size >= PAGESIZE && info.base == p.data) + if (info.size >= PAGESIZE && info.base == pdata) { // Try to extend in-place - auto u = gc_extend(p.data, (newsize + 1) - info.size, (newsize + 1) - info.size); + auto u = gc_extend(pdata, (newsize + 1) - info.size, (newsize + 1) - info.size); if (u) { goto L1; } } newdata = cast(byte *)gc_malloc(newsize + 1, info.attr); - newdata[0 .. size] = p.data[0 .. size]; + newdata[0 .. size] = pdata[0 .. size]; L1: ; } } @@ -692,17 +699,17 @@ } else { - newdata = p.data; + newdata = pdata; } - p.data = newdata; - p.length = newlength; - return newdata[0 .. newlength]; + return newdata; Loverflow: onOutOfMemoryError(); + return null; } +/+ /** * Append y[] to array x[].