Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 1617

Show
Ignore:
Timestamp:
02/06/07 14:40:42 (2 years ago)
Author:
sean
Message:

Merged in GDC 0.22 changes and cleaned up a comment here and there. This merge also includes the DMD 1.005 changes applied to GDC (there weren't many) so Frank's GC issues should not exist under GDC either (they were bugs in the compiler runtime code).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/compiler/dmd/aaA.d

    r1609 r1617  
    77 
    88/* 
    9  *  Copyright (C) 2000-2006 by Digital Mars, www.digitalmars.com 
     9 *  Copyright (C) 2000-2007 by Digital Mars, www.digitalmars.com 
    1010 *  Written by Walter Bright 
    1111 * 
  • trunk/lib/compiler/dmd/lifetime.d

    r1609 r1617  
    849849extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...) 
    850850{ 
    851     auto size = ti.next.tsize();                // array element size 
     851    auto size = ti.next.tsize(); // array element size 
    852852    void[] result; 
    853853 
     
    860860        if (!(ti.next.flags() & 1)) 
    861861            gc_setAttr(result.ptr, BlkAttr.NO_SCAN); 
    862         *cast(size_t *)&result = length;        // jam length 
     862        *cast(size_t *)&result = length; // jam length 
    863863 
    864864        va_list q; 
     
    919919    return *cast(long*)(&r); 
    920920} 
     921 
    921922 
    922923unittest 
  • trunk/lib/compiler/gdc/Makefile.in

    r1175 r1617  
    151151 
    152152OBJ_TI= \ 
    153     typeinfo/ti_Aa.o \ 
    154153    typeinfo/ti_AC.o \ 
    155154    typeinfo/ti_Acdouble.o \ 
    156155    typeinfo/ti_Acfloat.o \ 
    157156    typeinfo/ti_Acreal.o \ 
    158     typeinfo/ti_Adchar.o \ 
    159157    typeinfo/ti_Adouble.o \ 
    160158    typeinfo/ti_Afloat.o \ 
     
    187185    typeinfo/ti_real.o \ 
    188186    typeinfo/ti_short.o \ 
    189     typeinfo/ti_ubyte.o \ 
    190     typeinfo/ti_uint.o \ 
    191     typeinfo/ti_ulong.o \ 
    192     typeinfo/ti_ushort.o \ 
    193     typeinfo/ti_void.o \ 
    194     typeinfo/ti_wchar.o 
     187    typeinfo/ti_void.o 
    195188 
    196189ALL_OBJS= \ 
  • trunk/lib/compiler/gdc/aaA.d

    r1072 r1617  
    77 
    88/* 
    9  *  Copyright (C) 2000-2006 by Digital Mars, www.digitalmars.com 
     9 *  Copyright (C) 2000-2007 by Digital Mars, www.digitalmars.com 
    1010 *  Written by Walter Bright 
    1111 * 
     
    5757// Auto-rehash and pre-allocate - Dave Fladebo 
    5858 
    59 static uint[] prime_list = [ 
     59static size_t[] prime_list = [ 
    6060    97UL,         389UL, 
    6161    1543UL,       6151UL, 
     
    298298    size_t size = aaA.sizeof + keysize + valuesize; 
    299299    uint   bits = keysize   < (void*).sizeof && 
    300                   valuesize < (void*).sizeof ? BlkAttr.NO_SCAN : 0; 
     300                  keysize   > (void).sizeof  && 
     301                  valuesize < (void*).sizeof && 
     302                  valuesize > (void).sizeof  ? BlkAttr.NO_SCAN : 0; 
    301303    e = cast(aaA *) gc_calloc(size, bits); 
    302304    memcpy(e + 1, pkey, keysize); 
     
    497499    { 
    498500        a.length = _aaLen(aa); 
    499         a.ptr = cast(byte*) gc_malloc(a.length * valuesize, valuesize < (void*).sizeof ? BlkAttr.NO_SCAN : 0); 
     501        a.ptr = cast(byte*) gc_malloc(a.length * valuesize, 
     502                                      valuesize < (void*).sizeof && 
     503                                      valuesize > (void).sizeof  ? BlkAttr.NO_SCAN : 0); 
    500504        resi = 0; 
    501505        foreach (e; aa.a.b) 
     
    633637    if (!len) 
    634638        return a; 
    635     res = (cast(byte*) gc_malloc(len * keysize, keysize < (void*).sizeof ? BlkAttr.NO_SCAN : 0))[0 .. len * keysize]; 
     639    res = (cast(byte*) gc_malloc(len * keysize, 
     640                                 keysize < (void*).sizeof && 
     641                                 keysize > (void).sizeof  ? BlkAttr.NO_SCAN : 0))[0 .. len * keysize]; 
    636642    resi = 0; 
    637643    foreach (e; aa.a.b) 
  • trunk/lib/compiler/gdc/adi.d

    r1072 r1617  
    486486 */ 
    487487 
     488version (none) 
     489{ 
    488490extern (C) bit[] _adReverseBit(bit[] a) 
    489491    out (result) 
     
    526528    } 
    527529} 
    528  
     530
    529531 
    530532/********************************************** 
     
    627629 
    628630 
    629 /********************************** 
    630  * Support for array.dup property. 
    631  */ 
    632  
    633 extern (C) Array _adDup(Array a, int szelem) 
    634     out (result) 
    635     { 
    636         assert(memcmp(result.ptr, a.ptr, a.length * szelem) == 0); 
    637     } 
    638     body 
    639     { 
    640         Array r; 
    641  
    642         auto size = a.length * szelem; 
    643         r.ptr = gc_malloc(size, szelem < (void*).sizeof ? BlkAttr.NO_SCAN : 0); 
    644         r.length = a.length; 
    645         memcpy(r.ptr, a.ptr, size); 
    646         return r; 
    647     } 
    648  
    649 unittest 
    650 { 
    651     int[] a; 
    652     int[] b; 
    653     int i; 
    654  
    655     debug(adi) printf("array.dup.unittest\n"); 
    656  
    657     a = new int[3]; 
    658     a[0] = 1; a[1] = 2; a[2] = 3; 
    659     b = a.dup; 
    660     assert(b.length == 3); 
    661     for (i = 0; i < 3; i++) 
    662         assert(b[i] == i + 1); 
    663 } 
    664  
    665 /********************************** 
    666  * Support for array.dup property for bit[]. 
    667  */ 
    668  
    669 extern (C) Array _adDupBit(Array a) 
    670     out (result) 
    671     { 
    672         assert(memcmp(result.ptr, a.ptr, (a.length + 7) / 8) == 0); 
    673     } 
    674     body 
    675     { 
    676         Array r; 
    677  
    678         auto size = (a.length + 31) / 32; 
    679         r.ptr = cast(void *) new uint[size]; 
    680         r.length = a.length; 
    681         memcpy(r.ptr, a.ptr, size * uint.sizeof); 
    682         return r; 
    683     } 
    684  
    685 unittest 
    686 { 
    687     bit[] a; 
    688     bit[] b; 
    689     int i; 
    690  
    691     debug(adi) printf("array.dupBit[].unittest\n"); 
    692  
    693     a = new bit[3]; 
    694     a[0] = 1; a[1] = 0; a[2] = 1; 
    695     b = a.dup; 
    696     assert(b.length == 3); 
    697     for (i = 0; i < 3; i++) 
    698     {   debug(adi) printf("b[%d] = %d\n", i, b[i]); 
    699         assert(b[i] == (((i ^ 1) & 1) ? true : false)); 
    700     } 
    701 } 
    702  
    703  
    704631/*************************************** 
    705632 * Support for array equality test. 
     
    708635extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) 
    709636{ 
    710     //printf("a1.length = %d, a2.length = %d\n", a1.length, a2.length); 
     637    //printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
    711638    if (a1.length != a2.length) 
    712639        return 0;               // not equal 
    713640    auto sz = ti.tsize(); 
    714     //printf("sz = %d\n", sz); 
    715641    auto p1 = a1.ptr; 
    716642    auto p2 = a2.ptr; 
     
    752678 */ 
    753679 
     680version (none) 
     681{ 
    754682extern (C) int _adEqBit(Array a1, Array a2) 
    755683{   size_t i; 
     
    788716    assert(a != d); 
    789717    assert(a == e); 
     718} 
    790719} 
    791720 
     
    846775 */ 
    847776 
     777version (none) 
     778{ 
    848779extern (C) int _adCmpBit(Array a1, Array a2) 
    849780{ 
     
    893824    assert(a >= e); 
    894825} 
     826} 
     827 
  • trunk/lib/compiler/gdc/arraycast.d

    r925 r1617  
    11/* 
    2  *  Copyright (C) 2004 by Digital Mars, www.digitalmars.com 
     2 *  Copyright (C) 2004-2007 by Digital Mars, www.digitalmars.com 
    33 *  Written by Walter Bright 
    44 * 
     
    3535extern (C) 
    3636 
    37 void[] _d_arraycast(uint tsize, uint fsize, void[] a) 
     37void[] _d_arraycast(size_t tsize, size_t fsize, void[] a) 
    3838{ 
    39     uint length = a.length; 
    40     uint nbytes; 
     39    auto length = a.length; 
    4140 
    42     nbytes = length * fsize; 
     41    auto nbytes = length * fsize; 
    4342    if (nbytes % tsize != 0) 
    4443    { 
     
    4645    } 
    4746    length = nbytes / tsize; 
    48     *cast(uint *)&a = length;  // jam new length 
     47    *cast(size_t *)&a = length; // jam new length 
    4948    return a; 
    5049} 
     
    7372 */ 
    7473 
     74version (none) 
     75{ 
    7576extern (C) 
    7677 
     
    8485    } 
    8586    length /= 8 * tsize; 
    86     *cast(uint *)&a = length;  // jam new length 
     87    *cast(size_t *)&a = length; // jam new length 
    8788    return a; 
    8889} 
     
    103104    } 
    104105} 
     106 
     107} 
  • trunk/lib/compiler/gdc/arraycat.d

    r1072 r1617  
    44 
    55/* 
    6  *  Copyright (C) 2004-2006 by Digital Mars, www.digitalmars.com 
     6 *  Copyright (C) 2004-2007 by Digital Mars, www.digitalmars.com 
    77 *  Written by Walter Bright 
    88 * 
     
    2626 */ 
    2727 
    28 /* NOTE: This file has been patched from the original DMD distribution to 
    29    work with the GDC compiler. 
    30  
    31    Modified by David Friedman, November 2006 
    32 */ 
    33  
    3428/* 
    3529 *  Modified by Sean Kelly <sean@f4.ca> for use with Tango. 
     
    3933{ 
    4034    import tango.stdc.string; 
    41     import tango.stdc.stdbool; // TODO: remove this when the old bit code goes away 
    42     import tango.stdc.stdarg; 
    43  
    44     enum BlkAttr : uint 
    45     { 
    46         FINALIZE = 0b0000_0001, 
    47         NO_SCAN  = 0b0000_0010, 
    48         NO_MOVE  = 0b0000_0100, 
    49         ALL_BITS = 0b1111_1111 
    50     } 
    51  
    52     extern (C) void* gc_malloc( size_t sz, uint ba = 0 ); 
    53     extern (C) void* gc_calloc( size_t sz, uint ba = 0 ); 
    54     extern (C) void  gc_free( void* p ); 
     35    debug import tango.stdc.stdio; 
    5536} 
    5637 
    5738extern (C): 
    5839 
    59 byte[] _d_arraycatn(uint size, uint n, ...) 
    60 {   byte[] a; 
    61     uint length; 
    62     uint i; 
    63     byte[] b; 
    64     va_list va; 
    65  
    66     va_start!(typeof(n))(va, n); 
    67  
    68     for (i = 0; i < n; i++) 
    69     { 
    70         b = va_arg!(typeof(b))(va); 
    71         length += b.length; 
    72     } 
    73     if (!length) 
    74         return null; 
    75  
    76     a = (cast(byte*) gc_malloc(length * size, size < (void*).sizeof ? BlkAttr.NO_SCAN : 0))[0 .. length * size]; 
    77     va_start!(typeof(n))(va, n); 
    78  
    79     uint j = 0; 
    80     for (i = 0; i < n; i++) 
    81     { 
    82         b = va_arg!(typeof(b))(va); 
    83         if (b.length) 
    84         { 
    85             memcpy(&a[j], b.ptr, b.length * size); 
    86             j += b.length * size; 
    87         } 
    88     } 
    89  
    90     *cast(int *)&a = length;    // jam length 
    91     //a.length = length; 
    92     return a; 
    93 } 
    94  
    95 bit[] _d_arraycatb(bit[] x, bit[] y) 
    96 {   bit[] a; 
    97     uint a_length; 
    98     uint x_bytes; 
    99  
    100     if (!x.length) 
    101         return y; 
    102     if (!y.length) 
    103         return x; 
    104  
    105     a_length = x.length + y.length; 
    106     a = new bit[a_length]; 
    107     x_bytes = (x.length + 7) >> 3; 
    108     memcpy(a.ptr, x.ptr, x_bytes); 
    109     if ((x.length & 7) == 0) 
    110         memcpy(cast(void*)a.ptr + x_bytes, y.ptr, (y.length + 7) >> 3); 
    111     else 
    112     {   uint x_length = x.length; 
    113         uint y_length = y.length; 
    114         for (uint i = 0; i < y_length; i++) 
    115             a[x_length + i] = y[i]; 
    116     } 
    117     return a; 
    118 } 
    119  
    12040byte[] _d_arraycopy(uint size, byte[] from, byte[] to) 
    12141{ 
    122     //printf("f = %p,%d, t = %p,%d, size = %d\n", (void*)from, from.length, (void*)to, to.length, size); 
     42    debug printf("f = %p,%d, t = %p,%d, size = %d\n", 
     43                 cast(void*)from, from.length, cast(void*)to, to.length, size); 
    12344 
    12445    if (to.length != from.length) 
     
    13758    return to; 
    13859} 
    139  
    140 bit[] _d_arraycopybit(bit[] from, bit[] to) 
    141 { 
    142     //printf("f = %p,%d, t = %p,%d\n", (void*)from, from.length, (void*)to, to.length); 
    143     uint nbytes; 
    144  
    145     if (to.length != from.length) 
    146     { 
    147         throw new Exception("lengths don't match for array copy"); 
    148     } 
    149     else 
    150     { 
    151         nbytes = (to.length + 7) / 8; 
    152         if (cast(void *)to + nbytes <= cast(void *)from || 
    153             cast(void *)from + nbytes <= cast(void *)to) 
    154         { 
    155             nbytes = to.length / 8; 
    156             if (nbytes) 
    157                 memcpy(cast(void *)to, cast(void *)from, nbytes); 
    158  
    159             if (to.length & 7) 
    160             { 
    161                 /* Copy trailing bits. 
    162                  */ 
    163                 static ubyte[8] masks = [0,1,3,7,0x0F,0x1F,0x3F,0x7F]; 
    164                 ubyte mask = masks[to.length & 7]; 
    165                 (cast(ubyte*)to)[nbytes] &= ~mask; 
    166                 (cast(ubyte*)to)[nbytes] |= (cast(ubyte*)from)[nbytes] & mask; 
    167             } 
    168         } 
    169         else 
    170         { 
    171     throw new Exception("overlapping array copy"); 
    172         } 
    173     } 
    174     return to; 
    175 } 
    176  
    177 bit[] _d_arraysetbit(bit[] ba, uint lwr, uint upr, bit value) 
    178 in 
    179 { 
    180     //printf("_d_arraysetbit(ba.length = %d, lwr = %u, upr = %u, value = %d)\n", ba.length, lwr, upr, value); 
    181     assert(lwr <= upr); 
    182     assert(upr <= ba.length); 
    183 } 
    184 body 
    185 { 
    186     // Inefficient; lots of room for improvement here 
    187     for (uint i = lwr; i < upr; i++) 
    188         ba[i] = value; 
    189  
    190     return ba; 
    191 } 
    192  
    193 bit[] _d_arraysetbit2(bit[] ba, bit value) 
    194 { 
    195     //printf("_d_arraysetbit2(ba.ptr = %p, ba.length = %d, value = %d)\n", ba.ptr, ba.length, value); 
    196     size_t len = ba.length; 
    197     uint val = -cast(int)value; 
    198     memset(ba.ptr, val, len >> 3); 
    199     for (uint i = len & ~7; i < len; i++) 
    200         ba[i] = value; 
    201     return ba; 
    202 } 
    203  
    204  
    205  
    206 version (GNU) { /* _d_arrayliteral not used; can't always be compiled */ } 
    207 else 
    208 void* _d_arrayliteral(size_t size, size_t length, ...) 
    209 { 
    210     byte[] result; 
    211  
    212     //printf("_d_arrayliteral(size = %d, length = %d)\n", size, length); 
    213     if (length == 0 || size == 0) 
    214         result = null; 
    215     else 
    216     { 
    217         result = (cast(byte*) gc_malloc(length * size, size < (void*).sizeof ? BlkAttr.NO_SCAN : 0))[0 .. length * size]; 
    218         *cast(size_t *)&result = length;        // jam length 
    219  
    220         va_list q; 
    221         va_start!(size_t)(q, length); 
    222  
    223         size_t stacksize = (size + int.sizeof - 1) & ~(int.sizeof - 1); 
    224  
    225         if (stacksize == size) 
    226         { 
    227             memcpy(result.ptr, q, length * size); 
    228         } 
    229         else 
    230         { 
    231             for (size_t i = 0; i < length; i++) 
    232             { 
    233                 memcpy(result.ptr + i * size, q, size); 
    234                 q += stacksize; 
    235             } 
    236         } 
    237  
    238         va_end(q); 
    239     } 
    240     return result.ptr; 
    241 } 
  • trunk/lib/compiler/gdc/genobj.d

    r1122 r1617  
    244244    void *destructor; 
    245245    void (*classInvariant)(Object); 
    246     uint flags; 
     246    uint flags; 
    247247    //  1:                      // IUnknown 
     248    //  2:                      // has no possible pointers into GC memory 
     249    //  4:                      // has offTi[] member 
    248250    void *deallocator; 
     251    OffsetTypeInfo[] offTi; 
     252} 
     253 
     254 
     255/** 
     256 * Array of pairs giving the offset and type information for each 
     257 * member in an aggregate. 
     258 */ 
     259struct OffsetTypeInfo 
     260{ 
     261    size_t offset;      /// Offset of member from start of object 
     262    TypeInfo ti;        /// TypeInfo for this member 
    249263} 
    250264 
     
    260274    {   hash_t hash; 
    261275 
    262         foreach (char c; this.classinfo.name
     276        foreach (char c; this.toUtf8()
    263277            hash = hash * 9 + c; 
    264278        return hash; 
     
    267281    int opCmp(Object o) 
    268282    { 
    269         return stringCompare(this.classinfo.name, o.classinfo.name); 
     283        if (this is o) 
     284            return 0; 
     285        TypeInfo ti = cast(TypeInfo)o; 
     286        if (ti is null) 
     287            return 1; 
     288        return stringCompare(this.toUtf8(), ti.toUtf8()); 
    270289    } 
    271290 
     
    276295         * sufficient. 
    277296         */ 
    278         return this is o || this.classinfo.name == o.classinfo.name; 
     297        if (this is o) 
     298            return 1; 
     299        TypeInfo ti = cast(TypeInfo)o; 
     300        return ti && this.toUtf8() == ti.toUtf8(); 
    279301    } 
    280302 
     
    303325        } 
    304326    } 
    305 
    306  
     327 
     328    /// Get TypeInfo for 'next' type, as defined by what kind of type this is, 
     329    /// null if none. 
     330    TypeInfo next() { return null; } 
     331 
     332    /// Return default initializer, null if default initialize to 0 
     333    void[] init() { return null; } 
     334 
     335    /// Get flags for type: 1 means GC should scan for pointers 
     336    uint flags() { return 0; } 
     337 
     338    /// Get type information on the contents of the type; null if not available 
     339    OffsetTypeInfo[] offTi() { return null; } 
     340
    307341 
    308342class TypeInfo_Typedef : TypeInfo 
     
    325359    void swap(void *p1, void *p2) { return base.swap(p1, p2); } 
    326360 
     361    TypeInfo next() { return base.next(); } 
     362    uint flags() { return base.flags(); } 
     363    void[] init() { return m_init.length ? m_init : base.init(); } 
     364 
    327365    TypeInfo base; 
    328366    char[] name; 
     367    void[] m_init; 
    329368} 
    330369 
     
    335374class TypeInfo_Pointer : TypeInfo 
    336375{ 
    337     char[] toUtf8() { return next.toUtf8() ~ "*"; } 
     376    char[] toUtf8() { return m_next.toUtf8() ~ "*"; } 
    338377 
    339378    int opEquals(Object o) 
     
    342381        return this is o || 
    343382                ((c = cast(TypeInfo_Pointer)o) !is null && 
    344                  this.next == c.next); 
     383                 this.m_next == c.m_next); 
    345384    } 
    346385 
     
    372411    } 
    373412 
    374     TypeInfo next; 
     413    TypeInfo next() { return m_next; } 
     414    uint flags() { return 1; } 
     415 
     416    TypeInfo m_next; 
    375417} 
    376418 
    377419class TypeInfo_Array : TypeInfo 
    378420{ 
    379     char[] toUtf8() { return next.toUtf8() ~ "[]"; } 
     421    char[] toUtf8() { return value.toUtf8() ~ "[]"; } 
    380422 
    381423    int opEquals(Object o) 
     
    384426        return this is o || 
    385427                ((c = cast(TypeInfo_Array)o) !is null && 
    386                  this.next == c.next); 
     428                 this.value == c.value); 
    387429    } 
    388430 
    389431    hash_t getHash(void *p) 
    390     {   size_t sz = next.tsize(); 
     432    {   size_t sz = value.tsize(); 
    391433        hash_t hash = 0; 
    392434        void[] a = *cast(void[]*)p; 
    393435        for (size_t i = 0; i < a.length; i++) 
    394             hash += next.getHash(a.ptr + i * sz); 
     436            hash += value.getHash(a.ptr + i * sz); 
    395437        return hash; 
    396438    } 
     
    402444        if (a1.length != a2.length) 
    403445            return 0; 
    404         size_t sz = next.tsize(); 
     446        size_t sz = value.tsize(); 
    405447        for (size_t i = 0; i < a1.length; i++) 
    406448        { 
    407             if (!next.equals(a1.ptr + i * sz, a2.ptr + i * sz)) 
     449            if (!value.equals(a1.ptr + i * sz, a2.ptr + i * sz)) 
    408450                return 0; 
    409451        } 
     
    415457        void[] a1 = *cast(void[]*)p1; 
    416458        void[] a2 = *cast(void[]*)p2; 
    417         size_t sz = next.tsize(); 
     459        size_t sz = value.tsize(); 
    418460        size_t len = a1.length; 
    419461 
     
    422464        for (size_t u = 0; u < len; u++) 
    423465        { 
    424             int result = next.compare(a1.ptr + u * sz, a2.ptr + u * sz); 
     466            int result = value.compare(a1.ptr + u * sz, a2.ptr + u * sz); 
    425467            if (result) 
    426468                return result; 
     
    441483    } 
    442484 
    443     TypeInfo next; 
    444 
    445  
     485    TypeInfo value; 
     486 
     487    TypeInfo next() 
     488    { 
     489        return value; 
     490
     491 
     492    uint flags() { return 1; } 
     493
    446494 
    447495class TypeInfo_StaticArray : TypeInfo 
     
    450498    { 
    451499        char [10] tmp = void; 
    452         return next.toUtf8() ~ "[" ~ intToUtf8(tmp, len) ~ "]"; 
     500        return value.toUtf8() ~ "[" ~ intToUtf8(tmp, len) ~ "]"; 
    453501    } 
    454502 
     
    459507                ((c = cast(TypeInfo_StaticArray)o) !is null && 
    460508                 this.len == c.len && 
    461                  this.next == c.next); 
     509                 this.value == c.value); 
    462510    } 
    463511 
    464512    hash_t getHash(void *p) 
    465     {   size_t sz = next.tsize(); 
     513    {   size_t sz = value.tsize(); 
    466514        hash_t hash = 0; 
    467515        for (size_t i = 0; i < len; i++) 
    468             hash += next.getHash(p + i * sz); 
     516            hash += value.getHash(p + i * sz); 
    469517        return hash; 
    470518    } 
     
    472520    int equals(void *p1, void *p2) 
    473521    { 
    474         size_t sz = next.tsize(); 
     522        size_t sz = value.tsize(); 
    475523 
    476524        for (size_t u = 0; u < len; u++) 
    477525        { 
    478             if (!next.equals(p1 + u * sz, p2 + u * sz)) 
     526            if (!value.equals(p1 + u * sz, p2 + u * sz)) 
    479527                return 0; 
    480528        } 
     
    484532    int compare(void *p1, void *p2) 
    485533    { 
    486         size_t sz = next.tsize(); 
     534        size_t sz = value.tsize(); 
    487535 
    488536        for (size_t u = 0; u < len; u++) 
    489537        { 
    490             int result = next.compare(p1 + u * sz, p2 + u * sz); 
     538            int result = value.compare(p1 + u * sz, p2 + u * sz); 
    491539            if (result) 
    492540                return result; 
     
    497545    size_t tsize() 
    498546    { 
    499         return len * next.tsize(); 
     547        return len * value.tsize(); 
    500548    } 
    501549 
    502550    void swap(void *p1, void *p2) 
    503     {   ubyte* tmp; 
    504         size_t sz = next.tsize(); 
     551    {   void* tmp; 
     552        size_t sz = value.tsize(); 
    505553        ubyte[16] buffer; 
    506         ubyte* pbuffer; 
     554        void* pbuffer; 
    507555 
    508556        if (sz < buffer.sizeof) 
    509557            tmp = buffer.ptr; 
    510558        else 
    511             tmp = pbuffer = (new ubyte[sz]).ptr; 
     559            tmp = pbuffer = (new void[sz]).ptr; 
    512560 
    513561        for (size_t u = 0; u < len; u += sz) 
     
    521569    } 
    522570 
    523     TypeInfo next; 
     571    void[] init() { return value.init(); } 
     572    TypeInfo next() { return value; } 
     573    uint flags() { return value.flags(); } 
     574 
     575    TypeInfo value; 
    524576    size_t len; 
    525577} 
     
    538590                ((c = cast(TypeInfo_AssociativeArray)o) !is null && 
    539591                 this.key == c.key && 
    540                  this.next == c.next); 
     592                 this.value == c.value); 
    541593    } 
    542594 
     
    548600    } 
    549601 
    550     TypeInfo next; 
     602    TypeInfo next() { return value; } 
     603    uint flags() { return 1; } 
     604 
     605    TypeInfo value; 
    551606    TypeInfo key; 
    552607} 
     
    598653        return dg.sizeof; 
    599654    } 
     655 
     656    uint flags() { return 1; } 
    600657 
    601658    TypeInfo next; 
     
    655712    } 
    656713 
     714    uint flags() { return 1; } 
     715 
     716    OffsetTypeInfo[] offTi() 
     717    { 
     718        return (info.flags & 4) ? info.offTi : null; 
     719    } 
     720 
    657721    ClassInfo info; 
    658722} 
     
    716780    } 
    717781 
     782    uint flags() { return 1; } 
     783 
    718784    ClassInfo info; 
    719785} 
     
    762828            c = 0; 
    763829        else if (xopEquals) 
     830        { 
     831            version (GNU) 
     832                // GDC and DMD use different calling conventions 
     833                c = (*xopEquals)(p2, p1); 
     834            else 
    764835            c = (*xopEquals)(p1, p2); 
     836        } 
    765837        else 
    766838            // BUG: relies on the GC not moving objects 
     
    780852                    c = 1; 
    781853                else if (xopCmp) 
     854                { 
     855                    version (GNU) 
     856                        // GDC and DMD use different calling conventions 
     857                        c = (*xopCmp)(p2, p1); 
     858                    else 
    782859                    c = (*xopCmp)(p1, p2); 
     860                } 
    783861                else 
    784862                    // BUG: relies on the GC not moving objects 
     
    796874    } 
    797875 
     876    void[] init() { return m_init; } 
     877 
     878    uint flags() { return m_flags; } 
     879 
    798880    char[] name; 
    799     byte[] init; // initializer; init.ptr == null if 0 initialize 
     881    void[] m_init;      // initializer; init.ptr == null if 0 initialize 
    800882 
    801883    hash_t function(void*)    xtoHash; 
     
    803885    int function(void*,void*) xopCmp; 
    804886    char[] function(void*)    xtoString; 
     887 
     888    uint m_flags; 
    805889} 
    806890 
  • trunk/lib/compiler/gdc/lifetime.d

    r1173 r1617  
    33 * allocation, resizing, deallocation, and finalization. 
    44 * 
    5  * Copyright: Copyright (C) 2005-2006 Digital Mars, www.digitalmars.com. 
     5 * Copyright: Copyright (C) 2005-2007 Digital Mars, www.digitalmars.com. 
    66 *            All rights reserved. 
    77 * License: 
     
    7373    void* p; 
    7474 
    75     debug printf("_d_newclass(ci = %p)\n", ci); 
    76  
     75    debug printf("_d_newclass(ci = %p, %s)\n", ci, cast(char *)ci.name); 
    7776    if (ci.flags & 1) // if COM object 
    7877    { 
     
    8382    else 
    8483    { 
    85         p = gc_malloc(ci.init.length, BlkAttr.FINALIZE); 
     84        p = gc_malloc(ci.init.length, 
     85                      BlkAttr.FINALIZE | (ci.flags & 2 ? BlkAttr.NO_SCAN : 0)); 
    8686        debug printf(" p = %p\n", p); 
    8787    } 
     
    160160 
    161161/** 
    162  * 
    163  */ 
    164 extern (C) Array _d_new(size_t length, size_t size) 
    165 
    166     void *p; 
     162 * Allocate a new array of length elements. 
     163 * ti is the type of the resulting array, or pointer to element. 
     164 * (For when the array is initialized to 0) 
     165 */ 
     166extern (C) Array _d_newarrayT(TypeInfo ti, size_t length) 
     167
    167168    Array result; 
    168  
    169     debug printf("_d_new(length = %d, size = %d)\n", length, size); 
    170     /* 
     169    auto size = ti.next.tsize();                // array element size 
     170 
     171    debug printf("_d_newT(length = %d, size = %d)\n", length, size); 
     172    if (length && size) 
     173    { 
     174        result.length = length; 
     175        size *= length; 
     176        result.data = cast(byte*) gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0); 
     177        memset(result.data, 0, size); 
     178    } 
     179    return result; 
     180
     181 
     182 
     183/** 
     184 * For when the array has a non-zero initializer. 
     185 */ 
     186extern (C) Array _d_newarrayiT(TypeInfo ti, size_t length) 
     187
     188    Array result; 
     189    auto size = ti.next.tsize(); // array element size 
     190 
     191    debug printf("_d_newarrayiT(length = %d, size = %d, isize = %d)\n", length, size, isize); 
    171192    if (length == 0 || size == 0) 
    172     result = 0; 
     193        { } 
    173194    else 
    174     */ 
    175     if (length && size) 
    176     { 
    177         p = gc_malloc(length * size + 1, size < (void*).sizeof ? BlkAttr.NO_SCAN : 0); 
     195    { 
     196        auto initializer = ti.next.init(); 
     197        auto isize = initializer.length; 
     198        auto q = initializer.ptr; 
     199        size *= length; 
     200        auto p = gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0); 
    178201        debug printf(" p = %p\n", p); 
    179         memset(p, 0, length * size); 
     202        if (isize == 1) 
     203            memset(p, *cast(ubyte*)q, size); 
     204        else if (isize == int.sizeof) 
     205        { 
     206            int init = *cast(int*)q; 
     207            size /= int.sizeof;