Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 476

Show
Ignore:
Timestamp:
01/06/11 07:04:31 (14 years ago)
Author:
braddr
Message:

Fix AA's on 64bit.
The key aligntsize stuff was pretty messed up.
Move the aligntsize pieces to the aaA.d side of the logic rather than being duplicated in both object.d's AA logic also.
Fix the signature of _aaKeys to match. object.d's version had an extra parameter for the value size that was unused.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/import/object.di

    r473 r476  
    330330extern (C) 
    331331{ 
    332332    // from druntime/src/compiler/dmd/aaA.d 
    333333 
    334334    size_t _aaLen(void* p); 
    335335    void*  _aaGet(void** pp, TypeInfo keyti, size_t valuesize, ...); 
    336336    void*  _aaGetRvalue(void* p, TypeInfo keyti, size_t valuesize, ...); 
    337337    void*  _aaIn(void* p, TypeInfo keyti); 
    338338    void   _aaDel(void* p, TypeInfo keyti, ...); 
    339339    void[] _aaValues(void* p, size_t keysize, size_t valuesize); 
    340     void[] _aaKeys(void* p, size_t keysize, size_t valuesize); 
     340    void[] _aaKeys(void* p, size_t keysize); 
    341341    void*  _aaRehash(void** pp, TypeInfo keyti); 
    342342 
    343343    extern (D) typedef scope int delegate(void *) _dg_t; 
    344344    int _aaApply(void* aa, size_t keysize, _dg_t dg); 
    345345 
    346346    extern (D) typedef scope int delegate(void *, void *) _dg2_t; 
    347347    int _aaApply2(void* aa, size_t keysize, _dg2_t dg); 
    348348 
    349349    void* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...); 
    350350} 
    351351 
    352352struct AssociativeArray(Key, Value) 
    353353{ 
    354354    void* p; 
    355355 
    356     size_t aligntsize(size_t tsize) 
    357     { 
    358         version (X86_64) 
    359             // Size of key needed to align value on 16 bytes 
    360             return (tsize + 15) & ~(15); 
    361         else 
    362             return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
    363     } 
    364  
    365356    size_t length() @property { return _aaLen(p); } 
    366357 
    367358    Value[Key] rehash() @property 
    368359    { 
    369360        auto p = _aaRehash(&p, typeid(Value[Key])); 
    370361        return *cast(Value[Key]*)(&p); 
    371362    } 
    372363 
    373364    Value[] values() @property 
    374365    { 
    375         auto a = _aaValues(p, aligntsize(Key.sizeof), Value.sizeof); 
     366        auto a = _aaValues(p, Key.sizeof, Value.sizeof); 
    376367        return *cast(Value[]*) &a; 
    377368    } 
    378369 
    379370    Key[] keys() @property 
    380371    { 
    381         auto a = _aaKeys(p, aligntsize(Key.sizeof), Value.sizeof); 
     372        auto a = _aaKeys(p, Key.sizeof); 
    382373        return *cast(Key[]*) &a; 
    383374    } 
    384375 
    385376    int opApply(scope int delegate(ref Key, ref Value) dg) 
    386377    { 
    387         return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)dg); 
     378        return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg); 
    388379    } 
    389380 
    390381    int opApply(scope int delegate(ref Value) dg) 
    391382    { 
    392         return _aaApply(p, aligntsize(Key.sizeof), cast(_dg_t)dg); 
     383        return _aaApply(p, Key.sizeof, cast(_dg_t)dg); 
    393384    } 
    394385 
    395386    int delegate(int delegate(ref Key) dg) byKey() 
    396387    { 
    397388    int foo(int delegate(ref Key) dg) 
    398389    { 
    399390        int byKeydg(ref Key key, ref Value value) 
    400391        { 
    401392        return dg(key); 
    402393        } 
    403394 
    404         return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)&byKeydg); 
     395        return _aaApply2(p, Key.sizeof, cast(_dg2_t)&byKeydg); 
    405396    } 
    406397 
    407398    return &foo; 
    408399    } 
    409400 
    410401    int delegate(int delegate(ref Value) dg) byValue() 
    411402    { 
    412403    return &opApply; 
    413404    } 
    414405 
  • trunk/posix.mak

    r469 r476  
    391391$(DRUNTIME): $(OBJS) $(SRCS) win32.mak 
    392392    $(DMD) -lib -of$(DRUNTIME) -Xfdruntime.json $(DFLAGS) $(SRCS) $(OBJS) 
    393393 
    394394unittest : $(addprefix $(OBJDIR)/,$(SRC_D_MODULES)) $(DRUNTIME) $(OBJDIR)/emptymain.d 
    395395    @echo done 
    396396 
    397397ifeq ($(MODEL),64) 
    398398DISABLED_TESTS = \ 
    399399    core/sync/barrier \ 
    400400    core/sync/condition \ 
    401     core/sync/mutex \ 
    402401    core/sync/rwmutex \ 
    403402    core/sync/semaphore \ 
    404403    rt/adi \ 
    405404    rt/dmain2 
    406405else 
    407406DISABLED_TESTS = \ 
    408407    rt/dmain2 
    409408endif 
    410409 
    411410$(addprefix $(OBJDIR)/,$(DISABLED_TESTS)) : 
  • trunk/src/object_.d

    r473 r476  
    23752375extern (C) 
    23762376{ 
    23772377    // from druntime/src/compiler/dmd/aaA.d 
    23782378 
    23792379    size_t _aaLen(void* p); 
    23802380    void* _aaGet(void** pp, TypeInfo keyti, size_t valuesize, ...); 
    23812381    void* _aaGetRvalue(void* p, TypeInfo keyti, size_t valuesize, ...); 
    23822382    void* _aaIn(void* p, TypeInfo keyti); 
    23832383    void _aaDel(void* p, TypeInfo keyti, ...); 
    23842384    void[] _aaValues(void* p, size_t keysize, size_t valuesize); 
    2385     void[] _aaKeys(void* p, size_t keysize, size_t valuesize); 
     2385    void[] _aaKeys(void* p, size_t keysize); 
    23862386    void* _aaRehash(void** pp, TypeInfo keyti); 
    23872387 
    23882388    extern (D) typedef scope int delegate(void *) _dg_t; 
    23892389    int _aaApply(void* aa, size_t keysize, _dg_t dg); 
    23902390 
    23912391    extern (D) typedef scope int delegate(void *, void *) _dg2_t; 
    23922392    int _aaApply2(void* aa, size_t keysize, _dg2_t dg); 
    23932393 
    23942394    void* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...); 
    23952395} 
    23962396 
    23972397struct AssociativeArray(Key, Value) 
    23982398{ 
    23992399    void* p; 
    24002400 
    2401     size_t aligntsize(size_t tsize) 
    2402     { 
    2403         version (X86_64) 
    2404             // Size of key needed to align value on 16 bytes 
    2405             return (tsize + 15) & ~(15); 
    2406         else 
    2407             return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
    2408     } 
    2409  
    24102401    size_t length() @property { return _aaLen(p); } 
    24112402 
    24122403    Value[Key] rehash() @property 
    24132404    { 
    24142405        auto p = _aaRehash(&p, typeid(Value[Key])); 
    24152406        return *cast(Value[Key]*)(&p); 
    24162407    } 
    24172408 
    24182409    Value[] values() @property 
    24192410    { 
    2420         auto a = _aaValues(p, aligntsize(Key.sizeof), Value.sizeof); 
     2411        auto a = _aaValues(p, Key.sizeof, Value.sizeof); 
    24212412        return *cast(Value[]*) &a; 
    24222413    } 
    24232414 
    24242415    Key[] keys() @property 
    24252416    { 
    2426         auto a = _aaKeys(p, aligntsize(Key.sizeof), Value.sizeof); 
     2417        auto a = _aaKeys(p, Key.sizeof); 
    24272418        return *cast(Key[]*) &a; 
    24282419    } 
    24292420 
    24302421    int opApply(scope int delegate(ref Key, ref Value) dg) 
    24312422    { 
    2432         return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)dg); 
     2423        return _aaApply2(p, Key.sizeof, cast(_dg2_t)dg); 
    24332424    } 
    24342425 
    24352426    int opApply(scope int delegate(ref Value) dg) 
    24362427    { 
    2437         return _aaApply(p, aligntsize(Key.sizeof), cast(_dg_t)dg); 
     2428        return _aaApply(p, Key.sizeof, cast(_dg_t)dg); 
    24382429    } 
    24392430 
    24402431    int delegate(int delegate(ref Key) dg) byKey() 
    24412432    { 
    24422433    // Discard the Value part and just do the Key 
    24432434    int foo(int delegate(ref Key) dg) 
    24442435    { 
    24452436        int byKeydg(ref Key key, ref Value value) 
    24462437        { 
    24472438        return dg(key); 
    24482439        } 
    24492440 
    2450         return _aaApply2(p, aligntsize(Key.sizeof), cast(_dg2_t)&byKeydg); 
     2441        return _aaApply2(p, Key.sizeof, cast(_dg2_t)&byKeydg); 
    24512442    } 
    24522443 
    24532444    return &foo; 
    24542445    } 
    24552446 
    24562447    int delegate(int delegate(ref Value) dg) byValue() 
    24572448    { 
    24582449    return &opApply; 
    24592450    } 
    24602451 
  • trunk/src/rt/aaA.d

    r474 r476  
    255255            if (c == 0) 
    256256                goto Lret; 
    257257        } 
    258258        pe = &e.next; 
    259259    } 
    260260 
    261261    // Not found, create new elem 
    262262    //printf("create new one\n"); 
    263263    size_t size = aaA.sizeof + keysize + valuesize; 
    264264    e = cast(aaA *) gc_calloc(size); 
    265     memcpy(e + 1, pkey, keysize); 
     265    memcpy(e + 1, pkey, keyti.tsize); 
     266    memset(cast(byte*)(e + 1) + keyti.tsize, 0, keysize - keyti.tsize); 
    266267    e.hash = key_hash; 
    267268    *pe = e; 
    268269 
    269270    auto nodes = ++aa.a.nodes; 
    270271    //printf("length = %d, nodes = %d\n", aa.a.b.length, nodes); 
    271272    if (nodes > aa.a.b.length * 4) 
    272273    { 
    273274        //printf("rehash\n"); 
    274275        _aaRehash(aa,keyti); 
    275276    } 
     
    406407        } 
    407408    } 
    408409} 
    409410 
    410411 
    411412/******************************************** 
    412413 * Produce array of values from aa. 
    413414 */ 
    414415 
    415416ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) 
    416 in 
    417 { 
    418     assert(keysize == aligntsize(keysize)); 
    419 } 
    420 body 
    421417{ 
    422418    size_t resi; 
    423419    Array a; 
     420    
     421    auto alignsize = aligntsize(keysize);  
    424422 
    425423    if (aa.a) 
    426424    { 
    427425        a.length = _aaLen(aa); 
    428426        a.ptr = cast(byte*) gc_malloc(a.length * valuesize, 
    429427                                      valuesize < (void*).sizeof ? BlkAttr.NO_SCAN : 0); 
    430428        resi = 0; 
    431429        foreach (e; aa.a.b) 
    432430        { 
    433431            while (e) 
    434432            { 
    435433                memcpy(a.ptr + resi * valuesize, 
    436                        cast(byte*)e + aaA.sizeof + keysize, 
     434                       cast(byte*)e + aaA.sizeof + alignsize, 
    437435                       valuesize); 
    438436                resi++; 
    439437                e = e.next; 
    440438            } 
    441439        } 
    442440        assert(resi == a.length); 
    443441    } 
    444442    return *cast(ArrayRet_t*)(&a); 
    445443} 
    446444 
     
    556554 
    557555 
    558556/********************************************** 
    559557 * 'apply' for associative arrays - to support foreach 
    560558 */ 
    561559 
    562560// dg is D, but _aaApply() is C 
    563561extern (D) typedef int delegate(void *) dg_t; 
    564562 
    565563int _aaApply(AA aa, size_t keysize, dg_t dg) 
    566 in 
    567 { 
    568     assert(aligntsize(keysize) == keysize); 
    569 } 
    570 body 
    571564{   int result; 
    572565 
    573566    //printf("_aaApply(aa = x%llx, keysize = %d, dg = x%llx)\n", aa.a, keysize, dg); 
     567 
     568    auto alignsize = aligntsize(keysize); 
    574569 
    575570    if (aa.a) 
    576571    { 
    577572    Loop: 
    578573        foreach (e; aa.a.b) 
    579574        { 
    580575            while (e) 
    581576            { 
    582                 result = dg(cast(void *)(e + 1) + keysize); 
     577                result = dg(cast(void *)(e + 1) + alignsize); 
    583578                if (result) 
    584579                    break Loop; 
    585580                e = e.next; 
    586581            } 
    587582        } 
    588583    } 
    589584    return result; 
    590585} 
    591586 
    592587// dg is D, but _aaApply2() is C 
    593588extern (D) typedef int delegate(void *, void *) dg2_t; 
    594589 
    595590int _aaApply2(AA aa, size_t keysize, dg2_t dg) 
    596 in 
    597 { 
    598     assert(aligntsize(keysize) == keysize); 
    599 } 
    600 body 
    601591{   int result; 
    602592 
    603593    //printf("_aaApply(aa = x%llx, keysize = %d, dg = x%llx)\n", aa.a, keysize, dg); 
     594 
     595    auto alignsize = aligntsize(keysize); 
    604596 
    605597    if (aa.a) 
    606598    { 
    607599    Loop: 
    608600        foreach (e; aa.a.b) 
    609601        { 
    610602            while (e) 
    611603            { 
    612                 result = dg(cast(void *)(e + 1), cast(void *)(e + 1) + keysize); 
     604                result = dg(cast(void *)(e + 1), cast(void *)(e + 1) + alignsize); 
    613605                if (result) 
    614606                    break Loop; 
    615607                e = e.next; 
    616608            } 
    617609        } 
    618610    } 
    619611    return result; 
    620612} 
    621613 
    622614