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

Changeset 3742

Show
Ignore:
Timestamp:
07/10/08 06:23:22 (5 months ago)
Author:
larsivi
Message:

Merged more fixes from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/next/0.99.7/lib/compiler/dmd/adi.d

    r3697 r3742  
    374374/*************************************** 
    375375 * Support for array equality test. 
     376 * Returns: 
     377 *      1       equal 
     378 *      0       not equal 
    376379 */ 
    377380 
    378381extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) 
    379382{ 
    380     /+ 
    381      + TODO: Re-enable once the correct TypeInfo is passed: 
    382      +       http://d.puremagic.com/issues/show_bug.cgi?id=2161 
    383      + 
    384     debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
    385  
    386     if (a1.length != a2.length) 
    387         return 0; // not equal 
    388     if (a1.ptr == a2.ptr) 
    389         return 1; // equal 
    390  
    391     // We should really have a ti.isPOD() check for this 
    392     if (ti.tsize() != 1) 
    393         return ti.equals(&a1, &a2); 
    394     return memcmp(a1.ptr, a2.ptr, a1.length) == 0; 
    395     +/ 
    396383    debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
    397384    if (a1.length != a2.length) 
     
    413400} 
    414401 
     402extern (C) int _adEq2(Array a1, Array a2, TypeInfo ti) 
     403{ 
     404    debug(adi) printf("_adEq2(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
     405    if (a1.length != a2.length) 
     406        return 0;               // not equal 
     407    if (!ti.equals(&a1, &a2)) 
     408        return 0; 
     409    return 1; 
     410} 
    415411unittest 
    416412{ 
     
    432428extern (C) int _adCmp(Array a1, Array a2, TypeInfo ti) 
    433429{ 
    434     /+ 
    435      + TODO: Re-enable once the correct TypeInfo is passed: 
    436      +       http://d.puremagic.com/issues/show_bug.cgi?id=2161 
    437      + 
    438     debug(adi) printf("adCmp()\n"); 
    439  
    440     if (a1.ptr == a2.ptr && 
    441         a1.length == a2.length) 
    442         return 0; 
    443  
    444     auto len = a1.length; 
    445     if (a2.length < len) 
    446         len = a2.length; 
    447  
    448     // We should really have a ti.isPOD() check for this 
    449     if (ti.tsize() != 1) 
    450         return ti.compare(&a1, &a2); 
    451     auto c = memcmp(a1.ptr, a2.ptr, len); 
    452     if (c) 
    453         return c; 
    454     if (a1.length == a2.length) 
    455         return 0; 
    456     return a1.length > a2.length ? 1 : -1; 
    457     +/ 
    458430    debug(adi) printf("adCmp()\n"); 
    459431    auto len = a1.length; 
     
    484456} 
    485457 
     458extern (C) int _adCmp2(Array a1, Array a2, TypeInfo ti) 
     459{ 
     460    debug(adi) printf("_adCmp2(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
     461    return ti.compare(&a1, &a2); 
     462} 
    486463unittest 
    487464{ 
  • branches/next/0.99.7/lib/compiler/dmd/win32.mak

    r3031 r3742  
    6666    arraycast.obj \ 
    6767    arraycat.obj \ 
     68    arraydouble.obj \ 
     69    arrayfloat.obj \ 
     70    arrayreal.obj \ 
    6871    cast.obj \ 
    6972    complex.obj \ 
     
    8992OBJ_UTIL= \ 
    9093    util\console.obj \ 
     94    util\cpuid.obj \ 
    9195    util\ctype.obj \ 
    9296    util\string.obj \ 
  • branches/next/0.99.7/tango/core/Array.d

    r3233 r3742  
    16841684     * 
    16851685     * Returns: 
    1686      *  The number of unique elements in buf. 
    1687      */ 
    1688     size_t unique( Elem[] buf, Pred2E pred = Pred2E.init ); 
     1686     *  The number of distinct sub-sequences in buf. 
     1687     */ 
     1688    size_t distinct( Elem[] buf, Pred2E pred = Pred2E.init ); 
    16891689} 
    16901690else 
    16911691{ 
    1692     template unique_( Elem, Pred = IsEqual!(Elem) ) 
     1692    template distinct_( Elem, Pred = IsEqual!(Elem) ) 
    16931693    { 
    16941694        static assert( isCallableType!(Pred) ); 
     
    17271727 
    17281728 
    1729     template unique( Buf ) 
    1730     { 
    1731         size_t unique( Buf buf ) 
    1732         { 
    1733             return unique_!(ElemTypeOf!(Buf)).fn( buf ); 
    1734         } 
    1735     } 
    1736  
    1737  
    1738     template unique( Buf, Pred ) 
    1739     { 
    1740         size_t unique( Buf buf, Pred pred ) 
    1741         { 
    1742             return unique_!(ElemTypeOf!(Buf), Pred).fn( buf, pred ); 
     1729    template distinct( Buf ) 
     1730    { 
     1731        size_t distinct( Buf buf ) 
     1732        { 
     1733            return distinct_!(ElemTypeOf!(Buf)).fn( buf ); 
     1734        } 
     1735    } 
     1736 
     1737 
     1738    template distinct( Buf, Pred ) 
     1739    { 
     1740        size_t distinct( Buf buf, Pred pred ) 
     1741        { 
     1742            return distinct_!(ElemTypeOf!(Buf), Pred).fn( buf, pred ); 
    17431743        } 
    17441744    } 
     
    17511751        void test( char[] buf, char[] pat ) 
    17521752        { 
    1753             assert( unique( buf ) == pat.length ); 
     1753            assert( distinct( buf ) == pat.length ); 
    17541754            foreach( pos, cur; pat ) 
    17551755            { 
  • branches/next/0.99.7/tango/core/Traits.d

    r3734 r3742  
    118118} 
    119119 
    120 debug(UnitTest) { 
    121  
    122     unittest { 
    123  
    124         assert(isPointerType!(void*)); 
    125         assert(!isPointerType!(char[])); 
    126         assert(isPointerType!(char[]*)); 
    127         assert(!isPointerType!(char*[])); 
    128         assert(isPointerType!(real*)); 
    129         assert(!isPointerType!(uint)); 
    130          
     120debug( UnitTest ) 
     121
     122    unittest 
     123    { 
     124        assert( isPointerType!(void*) ); 
     125        assert( !isPointerType!(char[]) ); 
     126        assert( isPointerType!(char[]*) ); 
     127        assert( !isPointerType!(char*[]) ); 
     128        assert( isPointerType!(real*) ); 
     129        assert( !isPointerType!(uint) ); 
     130 
    131131        class Ham 
    132132        { 
    133133            void* a; 
    134134        } 
    135          
    136         assert(!isPointerType!(Ham)); 
    137          
     135 
     136        assert( !isPointerType!(Ham) ); 
     137 
    138138        union Eggs 
    139139        { 
    140140            void* a; 
    141             uint b; 
     141            uint b; 
    142142        }; 
    143          
    144         assert(!isPointerType!(Eggs)); 
    145         assert(isPointerType!(Eggs*)); 
    146          
     143 
     144        assert( !isPointerType!(Eggs) ); 
     145        assert( isPointerType!(Eggs*) ); 
     146 
    147147        struct Bacon {}; 
    148          
    149         assert(!isPointerType!(Bacon)); 
     148 
     149        assert( !isPointerType!(Bacon) ); 
    150150 
    151151    } 
     
    176176 * Evaluates to true if T is a static array type. 
    177177 */ 
    178 template isStaticArrayType(T : T[U], size_t U) 
    179 
    180     const bool isStaticArrayType = true; 
    181 
    182  
    183 template isStaticArrayType(T) 
    184 
    185     const bool isStaticArrayType = false; 
    186 
    187  
    188 debug (UnitTest) { 
    189  
    190     unittest { 
    191         assert(isStaticArrayType!(char[15])); 
    192         assert(!isStaticArrayType!(char[])); 
    193  
    194         assert(isDynamicArrayType!(char[])); 
    195         assert(!isDynamicArrayType!(char[15]));     
     178version( GNU ) 
     179
     180    // GDC should also be able to use the other version, but it probably 
     181    // relies on a frontend fix in one of the latest DMD versions - will 
     182    // remove this when GDC is ready. For now, this code pass the unittests. 
     183    private template isStaticArrayTypeInst( T ) 
     184    { 
     185        const T isStaticArrayTypeInst = void; 
     186    } 
     187 
     188    template isStaticArrayType( T ) 
     189    { 
     190        static if( is( typeof(T.length) ) && !is( typeof(T) == typeof(T.init) ) ) 
     191        { 
     192            const bool isStaticArrayType = is( T == typeof(T[0])[isStaticArrayTypeInst!(T).length] ); 
     193        } 
     194        else 
     195        { 
     196            const bool isStaticArrayType = false; 
     197        } 
     198    } 
     199
     200else 
     201
     202    template isStaticArrayType( T : T[U], size_t U ) 
     203    { 
     204        const bool isStaticArrayType = true; 
     205    } 
     206 
     207    template isStaticArrayType( T ) 
     208    { 
     209        const bool isStaticArrayType = false; 
     210    } 
     211
     212 
     213debug( UnitTest ) 
     214
     215    unittest 
     216    { 
     217        assert( isStaticArrayType!(char[5][2]) ); 
     218        assert( !isDynamicArrayType!(char[5][2]) ); 
     219 
     220        assert( isStaticArrayType!(char[15]) ); 
     221        assert( !isStaticArrayType!(char[]) ); 
     222 
     223        assert( isDynamicArrayType!(char[]) ); 
     224        assert( !isDynamicArrayType!(char[15]) ); 
    196225    } 
    197226} 
  • branches/next/0.99.7/tango/io/encode/Base64.d

    r3713 r3742  
    126126{ 
    127127    assert(data); 
     128    assert(buff.length >= allocateEncodeSize(data)); 
    128129} 
    129130body 
     
    160161 
    161162    return rtn; 
     163} 
     164 
     165/******************************************************************************* 
     166 
     167    encodes data and returns as an ASCII base64 string. 
     168 
     169    Params: 
     170    data = what is to be encoded 
     171 
     172    Example: 
     173    --- 
     174    char[] myEncodedString = encode(cast(ubyte[])"Hello, how are you today?"); 
     175    Stdout(myEncodedString).newline; // SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw== 
     176    --- 
     177 
     178 
     179*******************************************************************************/ 
     180 
     181 
     182char[] encode(ubyte[] data) 
     183in 
     184{ 
     185    assert(data); 
     186} 
     187body 
     188{ 
     189    auto rtn = new char[allocateEncodeSize(data)]; 
     190    return encode(data, rtn); 
    162191} 
    163192 
     
    300329            char[] result = encode(cast(ubyte[])"Hello, how are you today?", encoded); 
    301330            if (result == "SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==") 
    302                 return Test.Status.Success; 
     331            { 
     332                char[] result2 = encode(cast(ubyte[])"Hello, how are you today?"); 
     333                if (result == "SGVsbG8sIGhvdyBhcmUgeW91IHRvZGF5Pw==") 
     334                    return Test.Status.Success; 
     335            } 
     336 
    303337            return Test.Status.Failure; 
    304338        } 
  • branches/next/0.99.7/tango/math/random/Kiss.d

    r3723 r3742  
    1616*******************************************************************************/ 
    1717 
    18 module tango.math.Kiss; 
     18module tango.math.random.Kiss; 
    1919 
    2020