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

Changeset 5652

Show
Ignore:
Timestamp:
05/09/11 11:08:40 (1 year ago)
Author:
Marenz
Message:

Merged branch dmd-1.067 into trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/script/unittest.sh

    r5561 r5652  
    88 
    99EXE=runUnittests_$DC 
    10 DL="-L-ldl" 
     10DL="-L-ldl "  
    1111UNAME=`uname` 
    12 OPTIONS="-debug -debug=UnitTest
     12OPTIONS="-debug -gc -debug=utf -debug=UnitTest" #  :w -debug=PRINTF
    1313 
    1414error () { 
     
    3131if [ $DC == "ldc" ] 
    3232then 
    33     OPTIONS="-oq -d-debug -d-debug=UnitTest" 
     33    OPTIONS="-oq -d-debug -d-debug=UnitTest -gc" 
     34    DL="-L-ldl " 
    3435fi 
    3536 
    36 build/bin/$PLATFORM$ARCH/bob -v -r=$DC -c=$DC -p=$PLATFORM -l=libtango-$DC-tst -o="-g -unittest $OPTIONS" .  
     37if [ $DC == "gdc" ] 
     38then 
     39    OPTIONS="-fdebug -fdebug=UnitTest -funittest -g -nophoboslib" 
     40    DL="-ldl -L.  -ltango-$DC-tst -lz -lbz2 -o $EXE" 
     41fi 
     42 
     43echo build/bin/${PLATFORM}32/bob -r=$DC -m=$ARCH -c=$DC -p=$PLATFORM -l=libtango-$DC-tst -o=\"-m$ARCH -unittest $OPTIONS\" .  
     44build/bin/${PLATFORM}32/bob -r=$DC -m=$ARCH -c=$DC -p=$PLATFORM -l=libtango-$DC-tst -o="-m$ARCH -unittest $OPTIONS" .  
     45 
     46 
     47echo "Compiled Library" 
    3748 
    3849if ! which $DC >& /dev/null 
     
    6071import tango.core.tools.TraceExceptions; 
    6172 
     73import tango.stdc.stdio : printf; 
     74 
    6275bool tangoUnitTester() 
    6376{ 
    6477    uint countFailed = 0; 
    6578    uint countTotal = 1; 
     79     
    6680    Stdout ("NOTE: This is still fairly rudimentary, and will only report the").newline; 
    6781    Stdout ("    first error per module.").newline; 
     
    92106} 
    93107 
    94 void main() {
     108void main() { } // assert ( 0 == 1, "Main .. ");
    95109EOF 
    96110 
     
    100114fi 
    101115 
    102 echo "$DC $EXE.d $DFILES -g $OPTIONS -unittest -L-L. -L-ltango-$DC-tst  $DL -L-lz -L-lbz2" 
    103 $DC $EXE.d $DFILES -g $OPTIONS -unittest -L-L. -L-ltango-$DC-tst  $DL -L-lz -L-lbz2  && rm $EXE.d && rm libtango-$DC-tst.a 
     116echo "$DC $EXE.d $DFILES $OPTIONS -m$ARCH -unittest -L-L. -L-ltango-$DC-tst  $DL -L-lz -L-lbz2" 
     117$DC $EXE.d $DFILES $OPTIONS -m$ARCH -Itango/core/vendor -unittest -L-L. -L-ltango-$DC-tst  $DL -L-lz -L-lbz2  #&& rm $EXE.d && rm libtango-$DC-tst.a 
    104118 
    105119./runUnittests_$DC 
  • trunk/build/src/bob.d

    r5622 r5652  
    3939           new Solaris (args); 
    4040           new Windows (args); 
    41            stdout.formatln ("{} files", FileFilter.builder(args.os, args.compiler)()); 
     41           Stdout.formatln ("{} files", FileFilter.builder(args.os, args.compiler)()); 
    4242           } 
    4343} 
     
    158158        private auto gcc = "gcc -c -o"; 
    159159        private auto gcc32 = "gcc -c -m32 -o"; 
     160        private auto gcc64 = "gcc -c -m64 -o"; 
    160161 
    161162        int dmd () 
    162163        { 
    163                 auto dmd = "dmd -c -I"~args.root~"/tango/core -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
     164                char[] gcc, march; 
     165 
     166                if (args.march.length) 
     167                { 
     168                    march = " -m" ~ args.march; 
     169                    gcc = args.march == "64" ? gcc64 : gcc32; 
     170                } 
     171 
     172                auto dmd = "dmd -c -I"~args.root~"/tango/core -I"~args.root ~ 
     173                    march~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
    164174                exclude ("tango/core/rt/compiler/dmd/windows"); 
    165175                exclude ("tango/core/rt/compiler/dmd/darwin"); 
     
    171181                if (args.core) { 
    172182                    foreach (file; scan(".c")) { 
    173                              auto obj = compile (file, gcc32); 
    174                              addToLib(obj); 
    175                     } 
    176  
    177                     foreach (file; scan(".S")) { 
    178                             auto obj = compile (file, gcc32); 
    179                             addToLib(obj); 
    180                     } 
    181                 } 
    182  
    183                 makeLib(true); 
     183                             auto obj = compile (file, gcc); 
     184                             addToLib(obj); 
     185                    } 
     186 
     187                    foreach (file; scan(".S")) { 
     188                            auto obj = compile (file, gcc); 
     189                            addToLib(obj); 
     190                    } 
     191                } 
     192 
     193                makeLib(args.march == " -m32"); 
    184194                return count; 
    185195        } 
     
    187197        int ldc () 
    188198        { 
    189                 auto ldc = "ldc -c -I"~args.root~"/tango/core -I"~args.root~"/tango/core/rt/compiler/ldc -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
     199                char[] gcc, march; 
     200 
     201                if (args.march.length) 
     202                { 
     203                    march = " -m" ~ args.march; 
     204                    gcc = args.march == "64" ? gcc64 : gcc32; 
     205                } 
     206 
     207                auto ldc = "ldc -c -I"~args.root~"/tango/core " ~ march ~ " -I"~args.root~"/tango/core/rt/compiler/ldc -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
    190208                foreach (file; scan(".d")) { 
    191209                         auto obj = compile (file, ldc); 
     
    205223                } 
    206224 
    207                 makeLib
     225                makeLib(args.march == "32")
    208226                return count; 
    209227        } 
     
    211229        int gdc () 
    212230        { 
    213                 auto gdc = "gdc -c -I"~args.root~"/tango/core -I"~args.root~" "~args.flags~" -o"; 
     231                char[] gcc, march; 
     232 
     233                if (args.march.length) 
     234                { 
     235                    march = " -m" ~ args.march; 
     236                    gcc = args.march == "64" ? gcc64 : gcc32; 
     237                } 
     238 
     239                auto gdc = "gdc -c -I"~args.root~"/tango/core -I"~args.root ~ 
     240                    march ~ " "~args.flags~" -o"; 
    214241                foreach (file; scan(".d")) { 
    215242                         auto obj = compile (file, gdc); 
     
    228255                    } 
    229256                } 
    230  
    231                 makeLib; 
     257                makeLib(args.march == "32"); 
    232258                return count; 
    233259        } 
     
    781807                   { 
    782808                   foreach (str; cmd) 
    783                             stdout (str)(' '); 
    784                    stdout.newline; 
     809                            Stdout (str)(' '); 
     810                   Stdout.newline; 
    785811                   }   
    786812                          
     
    795821 
    796822                   proc.execute(); 
    797                    stdout.stream.copy (proc.stderr); 
    798                    stdout.stream.copy (proc.stdout); 
     823                   Stdout.stream.copy (proc.stderr); 
     824                   Stdout.stream.copy (proc.stdout); 
    799825                   auto result = proc.wait; 
    800826                   if (result.status != 0 || result.reason != Process.Result.Exit) 
     
    824850                flags, 
    825851                target, 
    826                 compiler; 
     852                compiler, 
     853                march; 
     854                 
    827855 
    828856        char[]  usage = "Bob is a build tool for the sole purpose to compile the Tango library.\n" 
     
    834862                        "\t[-u]\t\t\tinclude user modules\n" 
    835863                        "\t[-d]\t\t\tbuild Tango as a dynamic/shared library\n" 
     864                        "\t[-m=64|32]\tCompile for 32/64 bit\n" 
    836865                        "\t[-r=dmd|gdc|ldc]\tinclude a runtime target\n" 
    837866                        "\t[-c=dmd|gdc|ldc]\tspecify a compiler to use\n"                         
     
    858887                auto h = args("help").aliased('h').aliased('?').halt; 
    859888                auto d = args('d'); 
     889                auto m = args('m').params(1).restrict("64", "32"); 
    860890 
    861891                version (Windows) 
     
    902932                   gc = g.assigned[0]; 
    903933                   lib = l.assigned[0]; 
     934                   march = m.assigned.length > 0 ? m.assigned[0] : ""; 
    904935                        
    905936                    if(compiler == "gdc" && flags == "-release") 
  • trunk/object.di

    r5609 r5652  
    120120    /// compares the types of this TypeInfo stored at p1 and p2 
    121121    int      compare(void *p1, void *p2); 
     122     /// Return alignment of type 
     123    size_t   talign() { return tsize(); } 
    122124    /// returns the size of a type with the current TypeInfo 
    123125    size_t   tsize(); 
     
    132134    /// offsets of the various elements 
    133135    OffsetTypeInfo[] offTi(); 
     136 
     137    /** Return internal info on arguments fitting into 8byte. 
     138       * See X86-64 ABI 3.2.3 
     139     */ 
     140    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2); 
    134141} 
    135142 
  • trunk/tango/core/Thread.d

    r5607 r5652  
    349349                __builtin_unwind_init(); 
    350350            } 
     351            else version ( D_InlineAsm_X86_64 ) 
     352            { 
     353                asm 
     354                { 
     355                    // Not sure what goes here, pushad is invalid in 64 bit code 
     356                    push RAX ; 
     357                    push RBX ; 
     358                    push RCX ; 
     359                    push RDX ; 
     360                    push RSI ; 
     361                    push RDI ; 
     362                    push RBP ; 
     363                    push R8  ; 
     364                    push R9  ; 
     365                    push R10 ; 
     366                    push R11 ; 
     367                    push R12 ; 
     368                    push R13 ; 
     369                    push R14 ; 
     370                    push R15 ; 
     371                    push EAX ;   // 16 byte align the stack 
     372                } 
     373            } 
    351374            else 
    352375            { 
     
    411434            { 
    412435                // registers will be popped automatically 
     436            } 
     437            else version ( D_InlineAsm_X86_64 ) 
     438            { 
     439                asm 
     440                { 
     441                    // Not sure what goes here, popad is invalid in 64 bit code 
     442                    pop EAX ;   // 16 byte align the stack 
     443                    pop R15 ; 
     444                    pop R14 ; 
     445                    pop R13 ; 
     446                    pop R12 ; 
     447                    pop R11 ; 
     448                    pop R10 ; 
     449                    pop R9  ; 
     450                    pop R8  ; 
     451                    pop RBP ; 
     452                    pop RDI ; 
     453                    pop RSI ; 
     454                    pop RDX ; 
     455                    pop RCX ; 
     456                    pop RBX ; 
     457                    pop RAX ; 
     458                } 
    413459            } 
    414460            else 
     
    26712717        else version( AsmX86_64_Posix ) 
    26722718        { 
    2673             asm 
     2719            version( DigitalMars ) const dmdgdc = true; 
     2720            else version (GNU) const dmdgdc = true; 
     2721            else const dmdgdc = false; 
     2722             
     2723            static if (dmdgdc == true) asm 
     2724            { 
     2725                naked; 
     2726 
     2727                // save current stack state 
     2728                push RBP; 
     2729                mov RBP, RSP; 
     2730                push RBX; 
     2731                push R12; 
     2732                push R13; 
     2733                push R14; 
     2734                push R15; 
     2735                sub RSP, 4; 
     2736                stmxcsr [RSP]; 
     2737                sub RSP, 4; 
     2738                //version(SynchroFloatExcept){ 
     2739                    fstcw [RSP]; 
     2740                    fwait; 
     2741                //} else { 
     2742                //    fnstcw [RSP]; 
     2743                //    fnclex; 
     2744                //} 
     2745 
     2746                // store oldp again with more accurate address 
     2747                mov [RDI], RSP; 
     2748                // load newp to begin context switch 
     2749                mov RSP, RSI; 
     2750 
     2751                // load saved state from new stack 
     2752                fldcw [RSP]; 
     2753                add RSP, 4; 
     2754                ldmxcsr [RSP]; 
     2755                add RSP, 4; 
     2756                pop R15; 
     2757                pop R14; 
     2758                pop R13; 
     2759                pop R12; 
     2760 
     2761                pop RBX; 
     2762                pop RBP; 
     2763 
     2764                // 'return' to complete switch 
     2765                ret; 
     2766 
     2767            } 
     2768            else asm 
    26742769            { 
    26752770                naked; 
  • trunk/tango/core/Vararg.d

    r5248 r5652  
    1111module tango.core.Vararg; 
    1212 
     13/** 
     14 
     15  Gdc  
     16 
     17 
     18**/ 
     19 
    1320 
    1421version( GNU ) 
    1522{ 
     23    // GDC doesn't need va_start/va_end 
     24    // If the va_arg template version is used,   
     25 
    1626    public import std.stdarg; 
     27 
     28    version( X86_64 ) 
     29    { 
     30        alias va_list __va_argsave_t; 
     31         //__va_argsave_t __va_argsave; 
     32    } 
     33 
     34    // va_start and va_end is not needed for gdc, stubs only exist for eased 
     35    // cross-compiler programming 
     36    void va_start(T)( va_list ap, T parmn)   {   } 
     37    void va_end(va_list ap)    {    } 
    1738} 
    1839else version( LDC ) 
     
    2243else 
    2344{ 
    24     /** 
    25     * The base vararg list type. 
    26     */ 
    27     alias void* va_list; 
     45    version (DigitalMars) version (X86_64) version = DigitalMarsX64; 
     46    version (X86) 
     47    { 
     48        alias void* va_list; 
    2849 
    29  
    30     /** 
    31      * This function initializes the supplied argument pointer for subsequent 
    32      * use by va_arg and va_end. 
    33      * 
    34      * Params: 
    35      *  ap      = The argument pointer to initialize. 
    36      *  paramn  = The identifier of the rightmost parameter in the function 
    37      *            parameter list. 
    38     */ 
    39     void va_start(T) ( out va_list ap, ref T parmn ) 
     50        template va_arg(T) 
     51        { 
     52            T va_arg(ref va_list _argptr) 
     53            { 
     54                T arg = *cast(T*)_argptr; 
     55                _argptr = _argptr + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1)); 
     56                return arg; 
     57            } 
     58        } 
     59    } 
     60    else 
    4061    { 
    41         ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); 
    42     } 
    43  
    44     /** 
    45      * This function returns the next argument in the sequence referenced by 
    46      * the supplied argument pointer.  The argument pointer will be adjusted 
    47      * to point to the next arggument in the sequence. 
    48      * 
    49      * Params: 
    50      *  ap  = The argument pointer. 
    51      * 
    52      * Returns: 
    53      *  The next argument in the sequence.  The result is undefined if ap 
    54      *  does not point to a valid argument. 
    55      */ 
    56     T va_arg(T) ( ref va_list ap ) 
    57     { 
    58         T arg = *cast(T*) ap; 
    59         ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); 
    60         return arg; 
    61     } 
    62  
    63     /** 
    64      * This function cleans up any resources allocated by va_start.  It is 
    65      * currently a no-op and exists mostly for syntax compatibility with 
    66      * the variadric argument functions for C. 
    67      * 
    68      * Params: 
    69      *  ap  = The argument pointer. 
    70      */ 
    71     void va_end( va_list ap ) 
    72     { 
    73  
    74     } 
    75  
    76  
    77     /** 
    78      * This function copied the argument pointer src to dst. 
    79      * 
    80      * Params: 
    81      *  src = The source pointer. 
    82      *  dst = The destination pointer. 
    83      */ 
    84     void va_copy( out va_list dst, va_list src ) 
    85     { 
    86         dst = src; 
     62        public import tango.stdc.stdarg; 
    8763    } 
    8864} 
  • trunk/tango/core/Variant.d

    r5231 r5652  
    99 
    1010private import tango.core.Memory : GC; 
    11 private import tango.core.Vararg : va_list
     11private import tango.core.Vararg
    1212private import tango.core.Traits; 
    1313private import tango.core.Tuple; 
     
    3838        } 
    3939    } 
     40    version( X86_64 ) 
     41    { 
     42        version( Windows ) 
     43        { 
     44            version=EnableVararg; 
     45        } 
     46        else version( Posix ) 
     47        { 
     48            version=EnableVararg; 
     49        } 
     50 
     51        version = DigitalMarsX64; 
     52 
     53        import tango.math.Math : max; 
     54 
     55    } 
    4056} 
    4157else version( LDC ) 
     
    5470            version=EnableVararg; // thanks mwarning 
    5571        } 
     72 
     73        import tango.math.Math : max; 
    5674    } 
    5775} 
     
    338356     * Returns: 
    339357     *  The new Variant. 
    340      *  
     358     * 
    341359     * Example: 
    342360     * ----- 
     
    367385     * Returns: 
    368386     *  The new Variant. 
    369      *  
     387     * 
    370388     * Example: 
    371389     * ----- 
     
    390408     * Returns: 
    391409     *  The new value of the assigned-to variant. 
    392      *  
     410     * 
    393411     * Example: 
    394412     * ----- 
     
    447465     * Returns: 
    448466     *  true if the Variant contains a value of type T, false otherwise. 
    449      *  
     467     * 
    450468     * Example: 
    451469     * ----- 
     
    469487     *  contains a value that can be implicitly cast to type T; false 
    470488     *  otherwise. 
    471      *  
     489     * 
    472490     * Example: 
    473491     * ----- 
     
    740758            return value.heap.ptr; 
    741759    } 
    742      
     760 
    743761    version( EnableVararg ) 
    744762    { 
     
    751769 
    752770            foreach( i, ref v ; vs ) 
    753                 args = Variant.fromPtr(types[i], args, v); 
    754              
     771            { 
     772                version(DigitalMars) version(X86_64) 
     773                { 
     774                    scope void[] buffer; 
     775                    uint len = 0; 
     776 
     777                    foreach(argType; types) 
     778                        len =  max(len,(argType.tsize + size_t.sizeof - 1) & ~ (size_t.sizeof - 1)); 
     779 
     780                    buffer.length = len; 
     781 
     782                    va_arg(args, types[i], buffer.ptr); 
     783 
     784                    Variant.fromPtr(types[i], buffer.ptr, v); 
     785                } 
     786                else 
     787                    args = Variant.fromPtr(types[i], args, v); 
     788            } 
     789 
    755790            return vs; 
    756791        } 
    757          
     792 
    758793        /// ditto 
    759794        static Variant[] fromVararg(...) 
    760795        { 
    761             return Variant.fromVararg(_arguments, _argptr); 
    762         } 
    763          
     796            version(DigitalMarsX64) 
     797            { 
     798                va_list ap; 
     799                va_start(ap, __va_argsave); 
     800 
     801                scope (exit) va_end(ap); 
     802 
     803                return Variant.fromVararg(_arguments, ap); 
     804            } 
     805            else 
     806                return Variant.fromVararg(_arguments, _argptr); 
     807        } 
     808 
    764809        /** 
    765810         * Converts an array of Variants into a vararg function argument list. 
     
    768813         * this memory when you are done with it if you feel so inclined. 
    769814         */ 
    770         static void toVararg(Variant[] vars, out TypeInfo[] types, out va_list args) 
     815        deprecated static void toVararg(Variant[] vars, out TypeInfo[] types, out va_list args) 
    771816        { 
    772817            // First up, compute the total amount of space we'll need.  While 
     
    781826                noptr = noptr && (ti.flags & 2); 
    782827            } 
    783              
     828 
    784829            // Create the storage, and tell the GC whether it needs to be scanned 
    785830            // or not. 
     
    811856        return (_type = v); 
    812857    } 
    813      
     858 
    814859    /* 
    815860     * Creates a Variant using a given TypeInfo and a void*.  Returns the 
     
    862907                { 
    863908                    // Copy into storage 
    864                     r.value.data[0 .. type.tsize] =  
     909                    r.value.data[0 .. type.tsize] = 
    865910                        (cast(ubyte*)ptr)[0 .. type.tsize]; 
    866911                } 
     
    12401285            Variant[] scoop(...) 
    12411286            { 
     1287                version(DigitalMarsX64) 
     1288                { 
     1289                    va_list ap; 
     1290                    va_start(ap, __va_argsave); 
     1291 
     1292                    scope (exit) va_end(ap); 
     1293 
     1294                    return Variant.fromVararg(_arguments, ap); 
     1295                } 
     1296 
    12421297                return Variant.fromVararg(_arguments, _argptr); 
    12431298            } 
     
    12561311            C    va_b = new D; 
    12571312            D    va_c = new D; 
    1258              
     1313 
    12591314            auto vs = scoop(va_0, va_1, va_2, va_3, 
    12601315                            va_4, va_5, va_6, va_7, 
     
    12781333            assert( vs[0xa].get!(typeof(va_a)).msg == "B" ); 
    12791334            assert( vs[0xc].get!(typeof(va_c)).msg == "D" ); 
    1280              
     1335 
    12811336            assert( vs[0xb].get!(typeof(va_b)).name == "phil" ); 
    12821337            assert( vs[0xc].get!(typeof(va_c)).name == "phil" ); 
    12831338 
     1339            version (none) version(X86) // TODO toVararg won't work in x86_64 as it is now 
    12841340            { 
    12851341                TypeInfo[] types; 
  • trunk/tango/core/rt/compiler/dmd/object_.d

    r5609 r5652  
    4949    debug(PRINTF) import tango.stdc.stdio: printf; 
    5050    extern (C) Object _d_newclass(ClassInfo ci); 
    51      
     51 
    5252    version (darwin) 
    5353        import rt.compiler.dmd.darwin.Image; 
     
    7474alias int equals_t; 
    7575 
    76 version (PhobosCompatibility)  
    77 {  
     76version (PhobosCompatibility) 
     77{ 
    7878        alias char[]  string; 
    7979        alias wchar[] wstring; 
     
    8787{ 
    8888    /** 
    89      * Override this to capture an explicit delete or an implicit  
     89     * Override this to capture an explicit delete or an implicit 
    9090     * delete via a scoped-instance. Unlike a dtor(), GC references 
    9191     * are still intact when this method is invoked 
     
    332332        foreach (m; ModuleInfo) 
    333333        { 
     334            if (!m) 
     335                continue; 
     336 
    334337            //writefln("module %s, %d", m.name, m.localClasses.length); 
    335338            foreach (c; m.localClasses) 
     
    417420    /// Compares two instances for <, ==, or >. 
    418421    int compare(in void* p1, in void* p2) { return 0; } // throw new Exception("non comparable",__FILE__,__LINE__); 
    419  
     422    /// Return alignment of type 
     423    size_t talign() { return tsize(); } 
    420424    /// Returns size of the type. 
    421425    size_t tsize() { return 0; } 
     
    474478    /// Get type information on the contents of the type; null if not available 
    475479    OffsetTypeInfo[] offTi() { return null; } 
     480 
     481 
     482     /** Return internal info on arguments fitting into 8byte. 
     483       * See X86-64 ABI 3.2.3 
     484     */ 
     485    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     486    { 
     487        arg1 = this; 
     488        return 0; 
     489    } 
    476490} 
    477491 
     
    499513    override PointerMap pointermap() { return base.pointermap(); } 
    500514    override void[] init() { return m_init.length ? m_init : base.init(); } 
     515 
     516    size_t talign() { return base.talign(); } 
     517 
     518    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     519    {    
     520        return base.argTypes(arg1, arg2); 
     521    } 
    501522 
    502523    TypeInfo base; 
     
    636657 
    637658    override uint flags() { return 1; } 
     659 
     660    size_t talign() 
     661    { 
     662        return (void[]).alignof; 
     663    } 
     664 
     665    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     666    {   //arg1 = typeid(size_t); 
     667        //arg2 = typeid(void*); 
     668        return 0; 
     669    } 
    638670 
    639671    override PointerMap pointermap() 
     
    751783    TypeInfo value; 
    752784    size_t   len; 
     785 
     786    size_t talign() 
     787    { 
     788        return value.talign(); 
     789    } 
     790 
     791    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     792    { 
     793        arg1 = typeid(void*); 
     794        return 0; 
     795    } 
     796 
    753797} 
    754798 
     
    819863    TypeInfo value; 
    820864    TypeInfo key; 
     865 
     866    size_t talign() 
     867    { 
     868        return (char[int]).alignof; 
     869    } 
     870 
     871    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     872    { 
     873        arg1 = typeid(void*); 
     874        return 0; 
     875    } 
    821876} 
    822877 
     
    903958 
    904959    TypeInfo next; 
     960 
     961    size_t talign() 
     962    { 
     963        alias int delegate() dg; 
     964        return dg.alignof; 
     965    } 
     966 
     967    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     968    {   //arg1 = typeid(void*); 
     969        //arg2 = typeid(void*); 
     970        return 0; 
     971    } 
     972 
    905973} 
    906974 
     
    11151183    override uint flags() { return m_flags; } 
    11161184 
     1185    size_t talign() { return m_align; } 
     1186 
     1187 
    11171188    char[] name; 
    11181189    void[] m_init;      // initializer; init.ptr == null if 0 initialize 
     
    11251196 
    11261197    uint m_flags; 
     1198    uint m_align; 
    11271199 
    11281200    version (D_HavePointerMap) { 
     
    11301202 
    11311203        override PointerMap pointermap() { return m_pointermap; } 
     1204    } 
     1205 
     1206    version (X86_64) 
     1207    { 
     1208        int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     1209        { 
     1210            arg1 = m_arg1; 
     1211            arg2 = m_arg2; 
     1212            return 0; 
     1213        } 
     1214        TypeInfo m_arg1; 
     1215        TypeInfo m_arg2; 
    11321216    } 
    11331217} 
     
    11951279 
    11961280    override PointerMap pointermap() 
     1281    { 
     1282        assert(0); 
     1283    } 
     1284 
     1285    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
    11971286    { 
    11981287        assert(0); 
     
    12531342            } 
    12541343        } 
    1255          
     1344 
    12561345        void clear(){ 
    12571346            line=0; 
     
    14411530version( freebsd ) 
    14421531{ 
    1443     // This linked list is created by a compiler generated function inserted  
    1444     // into the .ctor list by the compiler.  
     1532    // This linked list is created by a compiler generated function inserted 
     1533    // into the .ctor list by the compiler. 
    14451534    struct ModuleReference 
    1446     {  
    1447         ModuleReference* next;  
    1448         ModuleInfo mod;  
     1535    { 
     1536        ModuleReference* next; 
     1537        ModuleInfo mod; 
    14491538     } 
    1450     extern (C) ModuleReference *_Dmodule_ref;   // start of linked list  
     1539    extern (C) ModuleReference *_Dmodule_ref;   // start of linked list 
    14511540} 
    14521541 
     
    14771566            len++; 
    14781567        } 
     1568 
     1569        debug(PRINTF) foreach (m; _moduleinfo_array) 
     1570        { 
     1571            //printf("\t%p\n", m); 
     1572            printf("\t%.*s\n", m.name.length,m.name.ptr); 
     1573        } 
     1574 
    14791575    } 
    14801576 
     
    15021598     * are of zero size and are in the two bracketing segments, 
    15031599     * respectively. 
    1504      *  
     1600     * 
    15051601     * The __minfo_beg and __minfo_end sections are not put into 
    15061602     * dynamic libraries therefore we cannot use them or the 
     
    15091605     * collect all the ModuleInfo references. 
    15101606     */ 
    1511         _moduleinfo_array = getSectionData!(ModuleInfo, "__DATA", "__minfodata");         
     1607        _moduleinfo_array = getSectionData!(ModuleInfo, "__DATA", "__minfodata"); 
    15121608        debug(PRINTF) printf("moduleinfo: ptr = %p, length = %d\n", _moduleinfo_array.ptr, _moduleinfo_array.length); 
    15131609 
     
    15181614        } 
    15191615    } 
    1520      
     1616 
    15211617    version (Win32) 
    15221618    { 
     
    15431639} 
    15441640 
    1545 void _moduleCtor2(ModuleInfo from,ModuleInfo[] mi, int skip) 
     1641void _moduleCtor2(ModuleInfo from, ModuleInfo[] mi, int skip) 
    15461642{ 
    15471643    debug(PRINTF) printf("_moduleCtor2(): %d modules\n", mi.length); 
     
    15531649        if (!m) 
    15541650            continue; 
    1555         debug(PRINTF) printf("\tmodule[%d] = '%.*s'\n", i, m.name); 
     1651        debug(PRINTF) printf("\tmodule[%d].name = '%s'\n", i, m.name); 
    15561652        if (m.flags & MIctordone) 
    15571653            continue; 
     
    15631659            {   if (skip || m.flags & MIstandalone) 
    15641660                    continue; 
    1565                 throw new Exception( "Cyclic dependency in module " ~ (from is null ? "*null*" : from.name) ~ " for import " ~ m.name);  
     1661                throw new Exception( "Cyclic dependency in module " ~ (from is null ? "*null*" : from.name) ~ " for import " ~ m.name); 
    15661662            } 
    15671663 
  • trunk/tango/core/rt/compiler/dmd/posix/deh.d

    r5589 r5652  
    3636{ 
    3737    version (darwin) {} 
    38      
     38 
    3939    else 
    4040    { 
     
    6565    uint espoffset;             // offset of ESP from EBP 
    6666    uint retoffset;             // offset from start of function to return code 
    67     uint nhandlers;             // dimension of handler_info[] 
     67    size_t nhandlers;             // dimension of handler_info[] 
    6868    DHandlerInfo handler_info[1]; 
    6969} 
     
    7272{ 
    7373    ClassInfo type;             // catch type 
    74     uint bpoffset;              // EBP offset of catch var 
     74    size_t bpoffset;              // EBP offset of catch var 
    7575    void *code;                 // catch handler code 
    7676} 
     
    7979struct DCatchInfo 
    8080{ 
    81     uint ncatches;                      // number of catch blocks 
     81    size_t ncatches;                      // number of catch blocks 
    8282    DCatchBlock catch_block[1];         // data for each catch block 
    8383} 
     
    112112        static FuncTable[] functionTables; 
    113113        static bool hasFunctionTables; 
    114          
     114 
    115115        if (!hasFunctionTables) 
    116116        { 
     
    118118            hasFunctionTables = true; 
    119119        } 
    120          
     120 
    121121        foreach (ft ; functionTables) 
    122122        { 
     
    124124                return ft.handlertable; 
    125125        } 
    126                  
     126 
    127127        return null; 
    128128    } 
    129      
    130129    else 
    131130    { 
     
    165164 */ 
    166165 
    167 uint __eh_find_caller(uint regbp, uint *pretaddr) 
    168 { 
    169     uint bp = *cast(uint *)regbp; 
     166size_t __eh_find_caller(size_t regbp, size_t *pretaddr) 
     167{ 
     168    size_t bp = *cast(size_t *)regbp; 
    170169 
    171170    if (bp)         // if not end of call chain 
     
    177176            terminate(); 
    178177 
    179         *pretaddr = *cast(uint *)(regbp + int.sizeof); 
     178        *pretaddr = *cast(size_t *)(regbp + size_t.sizeof); 
    180179    } 
    181180    return bp; 
     
    196195*/ 
    197196 
    198 extern(C) void _d_throwc(Object *h){ 
    199     uint regebp; 
     197extern(C) void _d_throwc(Object *h) 
     198
     199    size_t regebp; 
    200200 
    201201    debug(deh) 
     
    205205    } 
    206206 
    207     asm 
    208     { 
    209         mov regebp,EBP  ; 
    210     } 
     207    version (D_InlineAsm_X86) 
     208        asm 
     209        { 
     210            mov regebp,EBP  ; 
     211        } 
     212    else version (D_InlineAsm_X86_64) 
     213        asm 
     214        { 
     215            mov regebp,RBP  ; 
     216        } 
     217    else 
     218        static assert(0); 
    211219 
    212220//static uint abc; 
     
    219227        FuncTable *pfunc; 
    220228        DHandlerInfo *phi; 
    221         uint retaddr; 
    222         uint funcoffset; 
     229        size_t retaddr; 
     230        size_t funcoffset; 
    223231        uint spoff; 
    224232        uint retoffset; 
    225233        int index; 
    226         int dim; 
     234        size_t dim; 
    227235        int ndx; 
    228236        int prev_ndx; 
     
    245253            continue; 
    246254        } 
    247         funcoffset = cast(uint)handler_table.fptr; 
     255        funcoffset = cast(size_t)handler_table.fptr; 
    248256        spoff = handler_table.espoffset; 
    249257        retoffset = handler_table.retoffset; 
     
    262270        { 
    263271            printf("handler_info[]:\n"); 
    264             for (int i = 0; i < dim; i++) 
     272            for (size_t i = 0; i < dim; i++) 
    265273            { 
    266274                phi = handler_table.handler_info.ptr + i; 
     
    271279 
    272280        index = -1; 
    273         for (int i = 0; i < dim; i++) 
     281        for (size_t i = 0; i < dim; i++) 
    274282        { 
    275283            phi = handler_table.handler_info.ptr + i; 
    276284 
    277285            debug(deh) printf("i = %d, phi.offset = %04x\n", i, funcoffset + phi.offset); 
    278             if (cast(uint)retaddr > funcoffset + phi.offset && 
    279                 cast(uint)retaddr <= funcoffset + phi.endoffset) 
     286            if (retaddr > funcoffset + phi.offset && 
     287                retaddr <= funcoffset + phi.endoffset) 
    280288                index = i; 
    281289        } 
     
    288296            phi = handler_table.handler_info.ptr + ndx; 
    289297            prev_ndx = phi.prev_index; 
     298 
    290299            if (phi.cioffset) 
    291300            { 
    292301                // this is a catch handler (no finally) 
    293302                DCatchInfo *pci; 
    294                 int ncatches; 
    295                 int i; 
     303                size_t ncatches; 
     304                size_t i; 
    296305 
    297306                pci = cast(DCatchInfo *)(cast(char *)handler_table + phi.cioffset); 
    298307                ncatches = pci.ncatches; 
     308 
    299309                for (i = 0; i < ncatches; i++) 
    300310                { 
     
    312322                        // Jump to catch block. Does not return. 
    313323                        { 
    314                             uint catch_esp; 
     324                            size_t catch_esp; 
    315325                            fp_t catch_addr; 
    316326 
    317327                            catch_addr = cast(fp_t)(pcb.code); 
    318328                            catch_esp = regebp - handler_table.espoffset - fp_t.sizeof; 
    319                             asm 
    320                             { 
    321                                 mov     EAX,catch_esp   ; 
    322                                 mov     ECX,catch_addr  ; 
    323                                 mov     [EAX],ECX       ; 
    324                                 mov     EBP,regebp      ; 
    325                                 mov     ESP,EAX         ; // reset stack 
    326                                 ret                     ; // jump to catch block 
    327                             } 
     329 
     330                            version (D_InlineAsm_X86) 
     331                                asm 
     332                                { 
     333                                    mov     EAX,catch_esp   ; 
     334                                    mov     ECX,catch_addr  ; 
     335                                    mov     [EAX],ECX       ; 
     336                                    mov     EBP,regebp      ; 
     337                                    mov     ESP,EAX         ; // reset stack 
     338                                    ret                     ; // jump to catch block 
     339                                } 
     340                            else version (D_InlineAsm_X86_64) 
     341                                asm 
     342                                { 
     343                                    mov     RAX,catch_esp   ; 
     344                                    mov     RCX,catch_esp   ; 
     345                                    mov     RCX,catch_addr  ; 
     346                                    mov     [RAX],RCX       ; 
     347                                    mov     RBP,regebp      ; 
     348                                    mov     RSP,RAX         ; // reset stack 
     349                                    ret                     ; // jump to catch block 
     350                                } 
     351                            else 
     352                                static assert(0); 
     353 
    328354                        } 
    329355                    } 
     
    339365                version (OSX) 
    340366                { 
    341                     asm { 
    342                         sub ESP,4       ; 
    343                         push    EBX     ; 
    344                         mov EBX,blockaddr   ; 
    345                         push    EBP     ; 
    346                         mov EBP,regebp  ; 
    347                         call    EBX     ; 
    348                         pop EBP     ; 
    349                         pop EBX     ; 
    350                         add ESP,4       ; 
    351                     } 
    352                 } else { 
    353                     asm { 
    354                         push        EBX             ; 
    355                         mov         EBX,blockaddr   ; 
    356                         push        EBP             ; 
    357                         mov         EBP,regebp      ; 
    358                         call        EBX             ; 
    359                         pop         EBP             ; 
    360                         pop         EBX             ; 
    361                     } 
     367                    version (D_InlineAsm_X86) 
     368                        asm 
     369                        { 
     370                            sub     ESP,4           ; 
     371                            push    EBX             ; 
     372                            mov     EBX,blockaddr   ; 
     373                            push    EBP             ; 
     374                            mov     EBP,regebp      ; 
     375                            call    EBX             ; 
     376                            pop     EBP             ; 
     377                            pop     EBX             ; 
     378                            add     ESP,4           ; 
     379                        } 
     380                    else version (D_InlineAsm_X86_64) 
     381                        asm 
     382                        { 
     383                            sub     RSP,8           ; 
     384                            push    RBX             ; 
     385                            mov     RBX,blockaddr   ; 
     386                            push    RBP             ; 
     387                            mov     RBP,regebp      ; 
     388                            call    RBX             ; 
     389                            pop     RBP             ; 
     390                            pop     RBX             ; 
     391                            add     RSP,8           ; 
     392                        } 
     393                    else 
     394                        static assert(0); 
     395                } 
     396                else 
     397                { 
     398                    version (D_InlineAsm_X86) 
     399                        asm 
     400                        { 
     401                            push    EBX             ; 
     402                            mov     EBX,blockaddr   ; 
     403                            push    EBP             ; 
     404                            mov     EBP,regebp      ; 
     405                            call    EBX             ; 
     406                            pop     EBP             ; 
     407                            pop     EBX             ; 
     408                        } 
     409                    else version (D_InlineAsm_X86_64) 
     410                        asm 
     411                        { 
     412                            sub     RSP,8           ; 
     413                            push    RBX             ; 
     414                            mov     RBX,blockaddr   ; 
     415                            push    RBP             ; 
     416                            mov     RBP,regebp      ; 
     417                            call    RBX             ; 
     418                            pop     RBP             ; 
     419                            pop     RBX             ; 
     420                            add     RSP,8           ; 
     421                        } 
     422                    else 
     423                        static assert(0); 
    362424                } 
    363425            } 
  • trunk/tango/core/rt/compiler/dmd/posix/llmath.d

    r5192 r5652  
    2020 */ 
    2121 
     22 
    2223void __ULDIV__() 
    2324{ 
     25  version (D_InlineAsm_X86) 
    2426    asm 
    2527    { 
     
    179181        ret                     ; 
    180182    } 
     183  else version (D_InlineAsm_X86_64) 
     184        assert(0); 
     185  else 
     186        static assert(0); 
    181187} 
    182188 
     
    194200void __LDIV__() 
    195201{ 
     202  version (D_InlineAsm_X86) 
    196203    asm 
    197204    { 
     
    242249L12:    jmp     __ULDIV__       ; 
    243250    } 
    244 
    245  
     251  else version (D_InlineAsm_X86_64) 
     252        assert(0); 
     253  else 
     254        static assert(0); 
     255
    246256 
    247257/*************************************** 
     
    253263void __LCMP__() 
    254264{ 
     265  version (D_InlineAsm_X86) 
    255266    asm 
    256267    { 
     
    271282C1:     ret                     ; 
    272283    } 
    273 
    274  
    275  
    276  
     284  else version (D_InlineAsm_X86_64) 
     285        assert(0); 
     286  else 
     287        static assert(0); 
     288
    277289 
    278290// Convert ulong to real 
     
    282294real __U64_LDBL() 
    283295{ 
    284     version (OSX) { 
    285         asm 
    286         {   naked               ; 
    287             push    EDX         ; 
    288             push    EAX         ; 
    289             and     dword ptr 4[ESP], 0x7FFFFFFF    ; 
    290             fild    qword ptr [ESP]     ; 
    291             test    EDX,EDX         ; 
    292             jns     L1          ; 
    293             push    0x0000403e      ; 
    294             push    0x80000000      ; 
    295             push    0           ; 
    296             fld     real ptr [ESP]      ; // adjust 
    297             add     ESP,12          ; 
    298             faddp   ST(1), ST       ; 
    299         L1:                 ; 
    300             add     ESP, 8          ; 
    301             ret                 ; 
    302         } 
    303     } else { 
    304         asm 
    305         {   naked                                   ; 
    306             push    EDX                             ; 
    307             push    EAX                             ; 
    308             and     dword ptr 4[ESP], 0x7FFFFFFF    ; 
    309             fild    qword ptr [ESP]                 ; 
    310             test    EDX,EDX                         ; 
    311             jns     L1                              ; 
    312             fld     real ptr adjust                 ; 
    313             faddp   ST(1), ST                       ; 
    314         L1:                                         ; 
    315             add     ESP, 8                          ; 
    316             ret                                     ; 
    317         } 
     296    version (OSX) 
     297    { 
     298      version (D_InlineAsm_X86) 
     299        asm 
     300        {   naked                               ; 
     301            push        EDX                     ; 
     302            push        EAX                     ; 
     303            and         dword ptr 4[ESP], 0x7FFFFFFF    ; 
     304            fild        qword ptr [ESP]         ; 
     305            test        EDX,EDX                 ; 
     306            jns         L1                      ; 
     307            push        0x0000403e              ; 
     308            push        0x80000000              ; 
     309            push        0                       ; 
     310            fld         real ptr [ESP]          ; // adjust 
     311            add         ESP,12                  ; 
     312            faddp       ST(1), ST               ; 
     313        L1:                                     ; 
     314            add         ESP, 8                  ; 
     315            ret                                 ; 
     316        } 
     317      else version (D_InlineAsm_X86_64) 
     318            static assert(0); 
     319      else 
     320            static assert(0); 
     321    } 
     322    else 
     323    { 
     324      version (D_InlineAsm_X86) 
     325        asm 
     326        {   naked                               ; 
     327            push        EDX                     ; 
     328            push        EAX                     ; 
     329            and         dword ptr 4[ESP], 0x7FFFFFFF    ; 
     330            fild        qword ptr [ESP]         ; 
     331            test        EDX,EDX                 ; 
     332            jns         L1                      ; 
     333            fld         real ptr adjust         ; 
     334            faddp       ST(1), ST               ; 
     335        L1:                                     ; 
     336            add         ESP, 8                  ; 
     337            ret                                 ; 
     338        } 
     339      else version (D_InlineAsm_X86_64) 
     340        asm 
     341        {   naked                               ; 
     342            push        RAX                     ; 
     343            and         dword ptr 4[RSP], 0x7FFFFFFF    ; 
     344            fild        qword ptr [RSP]         ; 
     345            test        RAX,RAX                 ; 
     346            jns         L1                      ; 
     347            fld         real ptr adjust         ; 
     348            faddp       ST(1), ST               ; 
     349        L1:                                     ; 
     350            add         RSP, 8                  ; 
     351            ret                                 ; 
     352        } 
     353      else 
     354            static assert(0); 
    318355    } 
    319356} 
     
    322359ulong __ULLNGDBL() 
    323360{ 
     361  version (D_InlineAsm_X86) 
    324362    asm 
    325363    {   naked                                   ; 
     
    331369        ret                                     ; 
    332370    } 
    333 
     371  else version (D_InlineAsm_X86_64) 
     372    asm 
     373    {   naked                                   ; 
     374        call __U64_LDBL                         ; 
     375        sub  RSP,8                              ; 
     376        fstp double ptr [RSP]                   ; 
     377        pop  RAX                                ; 
     378        ret                                     ; 
     379    } 
     380  else 
     381        static assert(0); 
     382
     383 
    334384 
    335385// Convert double to ulong 
     
    340390{ 
    341391    // BUG: should handle NAN's and overflows 
    342     version (OSX) { 
    343         asm { 
    344             naked               ; 
    345             push    0xFBF           ; // roundTo0 
    346             push    0x0000403e      ; 
    347             push    0x80000000      ; 
    348             push    0           ; // adjust 
    349             push    EDX         ; 
    350             push    EAX         ; 
    351             fld     double ptr [ESP]    ; 
    352             sub     ESP,8           ; 
    353             fld     real ptr 16[ESP]    ; // adjust 
    354             fcomp               ; 
    355             fstsw   AX          ; 
    356             fstcw   8[ESP]          ; 
    357             fldcw   28[ESP]         ; // roundTo0 
    358             sahf                ; 
    359             jae     L1          ; 
    360             fld     real ptr 16[ESP]    ; // adjust 
    361             fsubp   ST(1), ST       ; 
    362             fistp   qword ptr [ESP]     ; 
    363             pop     EAX         ; 
    364             pop     EDX         ; 
    365             fldcw   [ESP]           ; 
    366             add     ESP,24          ; 
    367             add     EDX,0x8000_0000     ; 
    368             ret                 ; 
    369         L1:                 ; 
    370             fistp   qword ptr [ESP]     ; 
    371             pop     EAX         ; 
    372             pop     EDX         ; 
    373             fldcw   [ESP]           ; 
    374             add     ESP,24          ; 
    375             ret                 ; 
    376         } 
    377     } else { 
    378         asm 
    379         {   naked                                   ; 
    380             push    EDX                             ; 
    381             push    EAX                             ; 
    382             fld     double ptr [ESP]                ; 
    383             sub     ESP,8                           ; 
    384             fld     real ptr adjust                 ; 
    385             fcomp                                   ; 
    386             fstsw   AX                              ; 
    387             fstcw   8[ESP]                          ; 
    388             fldcw   roundTo0                        ; 
    389             sahf                                    ; 
    390             jae     L1                              ; 
    391             fld     real ptr adjust                 ; 
    392             fsubp   ST(1), ST                       ; 
    393             fistp   qword ptr [ESP]                 ; 
    394             pop     EAX                             ; 
    395             pop     EDX                             ; 
    396             fldcw   [ESP]                           ; 
    397             add     ESP,8                           ; 
    398             add     EDX,0x8000_0000                 ; 
    399             ret                                     ; 
    400         L1:                                         ; 
    401             fistp   qword ptr [ESP]                 ; 
    402             pop     EAX                             ; 
    403             pop     EDX                             ; 
    404             fldcw   [ESP]                           ; 
    405             add     ESP,8                           ; 
    406             ret                                     ; 
    407         } 
     392    version (OSX) 
     393    { 
     394      version (D_InlineAsm_X86) 
     395        asm 
     396        {   naked                               ; 
     397            push        0xFBF                   ; // roundTo0 
     398            push        0x0000403e              ; 
     399            push        0x80000000              ; 
     400            push        0                       ; // adjust 
     401            push        EDX                     ; 
     402            push        EAX                     ; 
     403            fld         double ptr [ESP]        ; 
     404            sub         ESP,8                   ; 
     405            fld         real ptr 16[ESP]        ; // adjust 
     406            fcomp                               ; 
     407            fstsw       AX                      ; 
     408            fstcw       8[ESP]                  ; 
     409            fldcw       28[ESP]                 ; // roundTo0 
     410            sahf                                ; 
     411            jae         L1                      ; 
     412            fld         real ptr 16[ESP]        ; // adjust 
     413            fsubp       ST(1), ST               ; 
     414            fistp       qword ptr [ESP]         ; 
     415            pop         EAX                     ; 
     416            pop         EDX                     ; 
     417            fldcw       [ESP]                   ; 
     418            add         ESP,24                  ; 
     419            add         EDX,0x8000_0000         ; 
     420            ret                                 ; 
     421        L1:                                     ; 
     422            fistp       qword ptr [ESP]         ; 
     423            pop         EAX                     ; 
     424            pop         EDX                     ; 
     425            fldcw       [ESP]                   ; 
     426            add         ESP,24                  ; 
     427            ret                                 ; 
     428        } 
     429      else version (D_InlineAsm_X86_64) 
     430            static assert(0); 
     431      else 
     432            static assert(0); 
     433    } 
     434    else 
     435    { 
     436      version (D_InlineAsm_X86) 
     437        asm 
     438        {   naked                               ; 
     439            push        EDX                     ; 
     440            push        EAX                     ; 
     441            fld         double ptr [ESP]        ; 
     442            sub         ESP,8                   ; 
     443            fld         real ptr adjust         ; 
     444            fcomp                               ; 
     445            fstsw       AX                      ; 
     446            fstcw       8[ESP]                  ; 
     447            fldcw       roundTo0                ; 
     448            sahf                                ; 
     449            jae         L1                      ; 
     450            fld         real ptr adjust         ; 
     451            fsubp       ST(1), ST               ; 
     452            fistp       qword ptr [ESP]         ; 
     453            pop         EAX                     ; 
     454            pop         EDX                     ; 
     455            fldcw       [ESP]                   ; 
     456            add         ESP,8                   ; 
     457            add         EDX,0x8000_0000         ; 
     458            ret                                 ; 
     459        L1:                                     ; 
     460            fistp       qword ptr [ESP]         ; 
     461            pop         EAX                     ; 
     462            pop         EDX                     ; 
     463            fldcw       [ESP]                   ; 
     464            add         ESP,8                   ; 
     465            ret                                 ; 
     466        } 
     467      else version (D_InlineAsm_X86_64) 
     468        asm 
     469        {   naked                               ; 
     470            push        RAX                     ; 
     471            fld         double ptr [RSP]        ; 
     472            sub         RSP,8                   ; 
     473            fld         real ptr adjust         ; 
     474            fcomp                               ; 
     475            fstsw       AX                      ; 
     476            fstcw       8[RSP]                  ; 
     477            fldcw       roundTo0                ; 
     478            sahf                                ; 
     479            jae         L1                      ; 
     480            fld         real ptr adjust         ; 
     481            fsubp       ST(1), ST               ; 
     482            fistp       qword ptr [RSP]         ; 
     483            pop         RAX                     ; 
     484            fldcw       [RSP]                   ; 
     485            add         RSP,8                   ; 
     486            mov         EDX,0x8000_0000         ; 
     487            shl         RDX,32                  ; 
     488            add         RAX,RDX                 ; 
     489            ret                                 ; 
     490        L1:                                     ; 
     491            fistp       qword ptr [RSP]         ; 
     492            pop         RAX                     ; 
     493            fldcw       [RSP]                   ; 
     494            add         RSP,8                   ; 
     495            ret                                 ; 
     496        } 
     497      else 
     498            static assert(0); 
    408499    } 
    409500} 
     
    414505{ 
    415506    // BUG: should handle NAN's and overflows 
    416     version (OSX) { 
    417         asm { 
    418             naked                   ; 
    419             push    0xFBF           ; // roundTo0 
    420             sub     ESP,12          ; 
    421             fstcw   8[ESP]          ; 
    422             fldcw   12[ESP]         ; // roundTo0 
    423             fistp   qword ptr [ESP] ; 
    424             fldcw   8[ESP]          ; 
    425             pop     EAX             ; 
    426             add     ESP,12          ; 
    427             ret                     ; 
    428         } 
    429     } else { 
    430         asm { 
    431             naked                                   ; 
    432             sub     ESP,16                          ; 
    433             fstcw   8[ESP]                          ; 
    434             fldcw   roundTo0                        ; 
    435             fistp   qword ptr [ESP]                 ; 
    436             fldcw   8[ESP]                          ; 
    437             pop     EAX                             ; 
    438             add     ESP,12                          ; 
    439             ret                                     ; 
    440         } 
    441     } 
    442 
    443  
     507    version (OSX) 
     508    { 
     509      version (D_InlineAsm_X86) 
     510        asm 
     511        {   naked                               ; 
     512            push        0xFBF                   ; // roundTo0 
     513            sub         ESP,12                  ; 
     514            fstcw       8[ESP]                  ; 
     515            fldcw       12[ESP]                 ; // roundTo0 
     516            fistp       qword ptr [ESP]         ; 
     517            fldcw       8[ESP]                  ; 
     518            pop         EAX                     ; 
     519            add         ESP,12                  ; 
     520            ret                                 ; 
     521        } 
     522      else version (D_InlineAsm_X86_64) 
     523            assert(0); 
     524      else 
     525            static assert(0); 
     526    } 
     527    else 
     528    { 
     529      version (D_InlineAsm_X86) 
     530        asm 
     531        {   naked                               ; 
     532            sub         ESP,16                  ; 
     533            fstcw       8[ESP]                  ; 
     534            fldcw       roundTo0                ; 
     535            fistp       qword ptr [ESP]         ; 
     536            fldcw       8[ESP]                  ; 
     537            pop         EAX                     ; 
     538            add         ESP,12                  ; 
     539            ret                                 ; 
     540        } 
     541      else version (D_InlineAsm_X86_64) 
     542        asm 
     543        {   naked                               ; 
     544            sub         RSP,16                  ; 
     545            fstcw       8[RSP]                  ; 
     546            fldcw       roundTo0                ; 
     547            fistp       qword ptr [RSP]         ; 
     548            fldcw       8[RSP]                  ; 
     549            pop         RAX                     ; 
     550            add         RSP,8                   ; 
     551            ret                                 ; 
     552        } 
     553      else 
     554            static assert(0); 
     555    } 
     556
    444557 
    445558// Convert real in ST0 to ulong 
     
    449562    version (OSX) 
    450563    { 
    451     asm 
    452     {   naked               ; 
    453         push    0xFBF           ; // roundTo0 
    454         push    0x0000403e      ; 
    455         push    0x80000000      ; 
    456         push    0           ; // adjust 
    457         sub     ESP,16          ; 
    458         fld     real ptr 16[ESP]    ; // adjust 
    459         fcomp               ; 
    460         fstsw   AX          ; 
    461         fstcw   8[ESP]          ; 
    462         fldcw   28[ESP]         ; // roundTo0 
    463         sahf                ; 
    464         jae     L1          ; 
    465         fld     real ptr 16[ESP]    ; // adjust 
    466         fsubp   ST(1), ST       ; 
    467         fistp   qword ptr [ESP]     ; 
    468         pop     EAX         ; 
    469         pop     EDX         ; 
    470         fldcw   [ESP]           ; 
    471         add     ESP,24          ; 
    472         add     EDX,0x8000_0000     ; 
    473         ret                 ; 
    474     L1:                 ; 
    475         fistp   qword ptr [ESP]     ; 
    476         pop     EAX         ; 
    477         pop     EDX         ; 
    478         fldcw   [ESP]           ; 
    479         add     ESP,24          ; 
    480         ret                 ; 
    481     } 
     564      version (D_InlineAsm_X86) 
     565        asm 
     566        {   naked                               ; 
     567            push        0xFBF                   ; // roundTo0 
     568            push        0x0000403e              ; 
     569            push        0x80000000              ; 
     570            push        0                       ; // adjust 
     571            sub         ESP,16                  ; 
     572            fld         real ptr 16[ESP]        ; // adjust 
     573            fcomp                               ; 
     574            fstsw       AX                      ; 
     575            fstcw       8[ESP]                  ; 
     576            fldcw       28[ESP]                 ; // roundTo0 
     577            sahf                                ; 
     578            jae         L1                      ; 
     579            fld         real ptr 16[ESP]        ; // adjust 
     580            fsubp       ST(1), ST               ; 
     581            fistp       qword ptr [ESP]         ; 
     582            pop         EAX                     ; 
     583            pop         EDX                     ; 
     584            fldcw       [ESP]                   ; 
     585            add         ESP,24                  ; 
     586            add         EDX,0x8000_0000         ; 
     587            ret                                 ; 
     588        L1:                                     ; 
     589            fistp       qword ptr [ESP]         ; 
     590            pop         EAX                     ; 
     591            pop         EDX                     ; 
     592            fldcw       [ESP]                   ; 
     593            add         ESP,24                  ; 
     594            ret                                 ; 
     595        } 
     596      else version (D_InlineAsm_X86_64) 
     597            static assert(0); 
     598      else 
     599            static assert(0); 
    482600    } 
    483601    else 
    484602    { 
    485     asm 
    486     {   naked               ; 
    487         sub     ESP,16          ; 
    488         fld     real ptr adjust     ; 
    489         fcomp               ; 
    490         fstsw   AX          ; 
    491         fstcw   8[ESP]          ; 
    492         fldcw   roundTo0        ; 
    493         sahf                ; 
    494         jae     L1          ; 
    495         fld     real ptr adjust     ; 
    496         fsubp   ST(1), ST       ; 
    497         fistp   qword ptr [ESP]     ; 
    498         pop     EAX         ; 
    499         pop     EDX         ; 
    500         fldcw   [ESP]           ; 
    501         add     ESP,8           ; 
    502         add     EDX,0x8000_0000     ; 
    503         ret                 ; 
    504     L1:                 ; 
    505         fistp   qword ptr [ESP]     ; 
    506         pop     EAX         ; 
    507         pop     EDX         ; 
    508         fldcw   [ESP]           ; 
    509         add     ESP,8           ; 
    510         ret                 ; 
    511     } 
    512     } 
    513 
    514  
     603      version (D_InlineAsm_X86) 
     604        asm 
     605        {   naked                               ; 
     606            sub         ESP,16                  ; 
     607            fld         real ptr adjust         ; 
     608            fcomp                               ; 
     609            fstsw       AX                      ; 
     610            fstcw       8[ESP]                  ; 
     611            fldcw       roundTo0                ; 
     612            sahf                                ; 
     613            jae         L1                      ; 
     614            fld         real ptr adjust         ; 
     615            fsubp       ST(1), ST               ; 
     616            fistp       qword ptr [ESP]         ; 
     617            pop         EAX                     ; 
     618            pop         EDX                     ; 
     619            fldcw       [ESP]                   ; 
     620            add         ESP,8                   ; 
     621            add         EDX,0x8000_0000         ; 
     622            ret                                 ; 
     623        L1:                                     ; 
     624            fistp       qword ptr [ESP]         ; 
     625            pop         EAX                     ; 
     626            pop         EDX                     ; 
     627            fldcw       [ESP]                   ; 
     628            add         ESP,8                   ; 
     629            ret                                 ; 
     630        } 
     631      else version (D_InlineAsm_X86_64) 
     632        asm 
     633        {   naked                               ; 
     634            sub         RSP,16                  ; 
     635            fld         real ptr adjust         ; 
     636            fcomp                               ; 
     637            fstsw       AX                      ; 
     638            fstcw       8[RSP]                  ; 
     639            fldcw       roundTo0                ; 
     640            sahf                                ; 
     641            jae         L1                      ; 
     642            fld         real ptr adjust         ; 
     643            fsubp       ST(1), ST               ; 
     644            fistp       qword ptr [RSP]         ; 
     645            pop         RAX                     ; 
     646            fldcw       [RSP]                   ; 
     647            add         RSP,8                   ; 
     648            mov         RCX,0x8000_0000         ; 
     649            shl         RCX,32                  ; 
     650            add         RAX,RCX                 ; 
     651            ret                                 ; 
     652        L1:                                     ; 
     653            fistp       qword ptr [RSP]         ; 
     654            pop         RAX                     ; 
     655            fldcw       [RSP]                   ; 
     656            add         RSP,8                   ; 
     657            ret                                 ; 
     658        } 
     659      else 
     660            static assert(0); 
     661    } 
     662
  • trunk/tango/core/rt/compiler/dmd/rt/aaA.d

    r5609 r5652  
    7070 * gcc will not, so we instead use a 'long'. 
    7171 */ 
    72 alias long ArrayRet_t; 
     72alias void[] ArrayRet_t; 
    7373 
    7474struct Array 
     
    111111size_t aligntsize(size_t tsize) 
    112112{ 
    113     // Is pointer alignment on the x64 4 bytes or 8? 
    114     return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     113    version (X86_64) 
     114        // Size of key needed to align value on 16 bytes 
     115        return (tsize + 15) & ~(15); 
     116    else 
     117        return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
    115118} 
    116119 
     
    239242 
    240243void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, ...) 
     244{ 
     245    return _aaGetX(aa, keyti, valuesize, cast(void *)(&valuesize + 1)); 
     246} 
     247 
     248void* _aaGetX(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey) 
    241249in 
    242250{ 
     
    252260body 
    253261{ 
    254     auto pkey = cast(void *)(&valuesize + 1); 
    255262    size_t i; 
    256263    aaA *e; 
     
    259266    if (!aa.a) 
    260267        aa.a = new BB(); 
     268 
    261269    aa.a.keyti = keyti; 
    262270 
     
    270278 
    271279    auto key_hash = keyti.getHash(pkey); 
     280 
    272281    //printf("hash = %d\n", key_hash); 
     282 
    273283    i = key_hash % aa.a.b.length; 
    274284    auto pe = &aa.a.b[i]; 
     285 
    275286    while ((e = *pe) !is null) 
    276287    { 
     
    313324void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, ...) 
    314325{ 
     326    return _aaGetRvalueX(aa, keyti, valuesize, cast(void *)(&valuesize + 1)); 
     327} 
     328 
     329void* _aaGetRvalueX(AA aa, TypeInfo keyti, size_t valuesize, void* pkey) 
     330{ 
    315331    //printf("_aaGetRvalue(valuesize = %u)\n", valuesize); 
    316332    if (!aa.a) 
    317333        return null; 
    318334 
    319     auto pkey = cast(void *)(&valuesize + 1); 
    320335    auto keysize = aligntsize(keyti.tsize()); 
    321336    auto len = aa.a.b.length; 
     
    352367 
    353368void* _aaIn(AA aa, TypeInfo keyti, ...) 
     369{ 
     370    return _aaInX(aa, keyti, cast(void *)(&keyti + 1)); 
     371} 
     372 
     373void* _aaInX(AA aa, TypeInfo keyti, void* pkey) 
    354374in 
    355375{ 
     
    363383    if (aa.a) 
    364384    { 
    365         auto pkey = cast(void *)(&keyti + 1); 
    366  
    367385        //printf("_aaIn(), .length = %d, .ptr = %x\n", aa.a.length, cast(uint)aa.a.ptr); 
    368386        auto len = aa.a.b.length; 
     
    400418void _aaDel(AA aa, TypeInfo keyti, ...) 
    401419{ 
    402     auto pkey = cast(void *)(&keyti + 1); 
     420    return _aaDelX(aa, keyti, cast(void *)(&keyti + 1)); 
     421
     422 
     423void _aaDelX(AA aa, TypeInfo keyti, void* pkey) 
     424
    403425    aaA *e; 
    404426 
     
    674696    auto len = _aaLen(aa); 
    675697    if (!len) 
    676         return 0
     698        return null
    677699    res = (cast(byte*) gc_malloc(len * keysize, 
    678700                                 !(aa.a.keyti.flags() & 1) ? BlkAttr.NO_SCAN : 0))[0 .. len * keysize]; 
     
    802824} 
    803825 
     826extern (C) BB* _d_assocarrayliteralTX(TypeInfo_AssociativeArray ti, void[] keys, void[] values) 
     827{ 
     828    auto valueti = ti.next; 
     829    auto valuesize = valueti.tsize();           // value size 
     830    auto keyti = ti.key; 
     831    auto keysize = keyti.tsize();               // key size 
     832    auto length = keys.length; 
     833    BB* result; 
     834 
     835    //printf("_d_assocarrayliteralT(keysize = %d, valuesize = %d, length = %d)\n", keysize, valuesize, length); 
     836    //printf("tivalue = %.*s\n", ti.next.classinfo.name); 
     837    assert(length == values.length); 
     838    if (length == 0 || valuesize == 0 || keysize == 0) 
     839    { 
     840        ; 
     841    } 
     842    else 
     843    { 
     844        result = new BB(); 
     845 
     846        size_t i; 
     847        for (i = 0; i < prime_list.length - 1; i++) 
     848        { 
     849            if (length <= prime_list[i]) 
     850                break; 
     851        } 
     852        auto len = prime_list[i]; 
     853        result.b = new aaA*[len]; 
     854 
     855        size_t keytsize = aligntsize(keysize); 
     856 
     857        for (size_t j = 0; j < length; j++) 
     858        {   auto pkey = keys.ptr + j * keysize; 
     859            auto pvalue = values.ptr + j * valuesize; 
     860            aaA* e; 
     861 
     862            auto key_hash = keyti.getHash(pkey); 
     863            //printf("hash = %d\n", key_hash); 
     864            i = key_hash % len; 
     865            auto pe = &result.b[i]; 
     866            while (1) 
     867            { 
     868                e = *pe; 
     869                if (!e) 
     870                { 
     871                    // Not found, create new elem 
     872                    //printf("create new one\n"); 
     873                    e = cast(aaA *) cast(void*) new void[aaA.sizeof + keytsize + valuesize]; 
     874                    memcpy(e + 1, pkey, keysize); 
     875                    e.hash = key_hash; 
     876                    *pe = e; 
     877                    result.nodes++; 
     878                    break; 
     879                } 
     880                if (key_hash == e.hash) 
     881                { 
     882                    auto c = keyti.compare(pkey, e + 1); 
     883                    if (c == 0) 
     884                        break; 
     885                    pe = (c < 0) ? &e.left : &e.right; 
     886                } 
     887                else 
     888                    pe = (key_hash < e.hash) ? &e.left : &e.right; 
     889            } 
     890            memcpy(cast(void *)(e + 1) + keytsize, pvalue, valuesize); 
     891        } 
     892    } 
     893    return result; 
     894} 
    804895 
    805896/*********************************** 
     
    808899 */ 
    809900 
    810 extern (C) 
    811 BB* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...) 
     901extern (C) BB* _d_assocarrayliteralT(TypeInfo_AssociativeArray ti, size_t length, ...) 
    812902{ 
    813903    auto valuesize = ti.next.tsize();           // value size 
     
    825915    { 
    826916        va_list q; 
    827         va_start!(size_t)(q, length); 
     917        version(X86_64) va_start(q, __va_argsave); else va_start!(size_t)(q, length); 
    828918 
    829919        result = new BB(); 
  • trunk/tango/core/rt/compiler/dmd/rt/adi.d

    r5609 r5652  
    6969 */ 
    7070 
    71 extern (C) long _adReverseChar(char[] a) 
     71extern (C) char[] _adReverseChar(char[] a) 
    7272{ 
    7373    bool hadErrors=false; 
     
    101101 
    102102            uint stridehi = 1; 
    103             while ((chi & 0xC0) == 0x80 && hi >= lo
     103            while ((chi & 0xC0) == 0x80
    104104            { 
    105105                chi = *--hi; 
    106106                stridehi++; 
    107107            } 
    108             if (lo >= hi){ 
     108            if (lo == hi) 
     109            { 
    109110                if (lo>hi){ 
    110111                    hadErrors=true; 
     
    132133            memcpy(tmp.ptr, hi, stridehi); 
    133134            memcpy(tmplo.ptr, lo, stridelo); 
    134             memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); 
     135            memmove(lo + stridehi, lo + stridelo , cast(size_t)((hi - lo) - stridelo)); 
    135136            memcpy(lo, tmp.ptr, stridehi); 
    136137            memcpy(hi + stridehi - stridelo, tmplo.ptr, stridelo); 
    137138 
    138139            lo += stridehi; 
    139             hi = hi - 1 + (stridehi - stridelo); 
     140            hi = hi - 1 + cast(int)(stridehi - stridelo); 
    140141        } 
    141142    } 
    142143    if (hadErrors) 
    143144        throw new Exception("invalid UTF-8 sequence",__FILE__,__LINE__); 
    144     return *cast(long*)(&a)
     145    return a
    145146} 
    146147 
    147148unittest 
    148149{ 
    149     auto a = "abcd"c[]
     150    char[] a = "abcd"
    150151 
    151152    auto r = a.dup.reverse; 
  • trunk/tango/core/rt/compiler/dmd/rt/alloca.d

    r5015 r5652  
    2828 */ 
    2929 
     30 
    3031extern (C) void* __alloca(int nbytes) 
    3132{ 
     33  version (D_InlineAsm_X86) 
     34  { 
    3235    asm 
    3336    { 
     
    3841        push    EDI             ; 
    3942        push    ESI             ; 
     43    } 
     44 
     45    version (OSX) 
     46    { 
     47    asm 
     48    { 
     49        add     EAX,15          ; 
     50        and     EAX,0xFFFFFFF0  ; // round up to 16 byte boundary 
     51    } 
     52    } 
     53    else 
     54    { 
     55    asm 
     56    { 
    4057        add     EAX,3           ; 
    4158        and     EAX,0xFFFFFFFC  ; // round up to dword 
     59    } 
     60    } 
     61 
     62    asm 
     63    { 
    4264        jnz     Abegin          ; 
    4365        mov     EAX,4           ; // allow zero bytes allocation, 0 rounded to dword is 4.. 
     
    108130        ret                     ; 
    109131    } 
     132  } 
     133  else version (D_InlineAsm_X86_64) 
     134  { 
     135    asm 
     136    { 
     137        naked                   ; 
     138        mov     RDX,RCX         ; 
     139        mov     RAX,RDI         ; // get nbytes 
     140        add     RAX,15          ; 
     141        and     AL,0xF0         ; // round up to 16 byte boundary 
     142        test    RAX,RAX         ; 
     143        jnz     Abegin          ; 
     144        mov     RAX,16          ; // allow zero bytes allocation 
     145    Abegin: 
     146        mov     RSI,RAX         ; // RSI = nbytes 
     147        neg     RAX             ; 
     148        add     RAX,RSP         ; // RAX is now what the new RSP will be. 
     149        jae     Aoverflow       ; 
     150    } 
     151    version (Win64) 
     152    { 
     153    asm 
     154    { 
     155        // We need to be careful about the guard page 
     156        // Thus, for every 4k page, touch it to cause the OS to load it in. 
     157        mov     RCX,RAX         ; // RCX is new location for stack 
     158        mov     RBX,RSI         ; // RBX is size to "grow" stack 
     159    L1: 
     160        test    [RCX+RBX],RBX   ; // bring in page 
     161        sub     RBX,0x1000      ; // next 4K page down 
     162        jae     L1              ; // if more pages 
     163        test    [RCX],RBX       ; // bring in last page 
     164    } 
     165    } 
     166    version (Unix) 
     167    { 
     168    asm 
     169    { 
     170        cmp     RAX,_pastdata   ; 
     171        jbe     Aoverflow       ; // Unlikely - ~2 Gbytes under UNIX 
     172    } 
     173    } 
     174    asm 
     175    { 
     176        // Copy down to [RSP] the temps on the stack. 
     177        // The number of temps is (RBP - RSP - locals). 
     178        mov     RCX,RBP         ; 
     179        sub     RCX,RSP         ; 
     180        sub     RCX,[RDX]       ; // RCX = number of temps (bytes) to move. 
     181        add     [RDX],RSI       ; // adjust locals by nbytes for next call to alloca() 
     182        mov     RSP,RAX         ; // Set up new stack pointer. 
     183        add     RAX,RCX         ; // Return value = RSP + temps. 
     184        mov     RDI,RSP         ; // Destination of copy of temps. 
     185        add     RSI,RSP         ; // Source of copy. 
     186        shr     RCX,3           ; // RCX to count of qwords in temps 
     187        rep                     ; 
     188        movsq                   ; 
     189        jmp     done            ; 
     190 
     191    Aoverflow: 
     192        // Overflowed the stack.  Return null 
     193        xor     RAX,RAX         ; 
     194 
     195    done: 
     196        ret                     ; 
     197    } 
     198  } 
     199  else 
     200        static assert(0); 
    110201} 
  • trunk/tango/core/rt/compiler/dmd/rt/cast_.d

    r5248 r5652  
    8383Object _d_dynamic_cast(Object o, ClassInfo c) 
    8484{   ClassInfo oc; 
    85     size_t offset = 0; 
     85    uint offset = 0; 
    8686 
    8787    //printf("_d_dynamic_cast(o = %p, c = '%.*s')\n", o, c.name); 
     
    102102} 
    103103 
    104 int _d_isbaseof2(ClassInfo oc, ClassInfo c, ref size_t offset) 
     104int _d_isbaseof2(ClassInfo oc, ClassInfo c, ref uint offset) 
    105105{   int i; 
    106106 
  • trunk/tango/core/rt/compiler/dmd/rt/cover.d

    r5284 r5652  
    3535    { 
    3636        size_t  len; 
    37         uint*  ptr; 
     37        size_t* ptr; 
    3838 
    3939        bool opIndex( size_t i ) 
  • trunk/tango/core/rt/compiler/dmd/rt/dmain2.d

    r5603 r5652  
    1717    import tango.stdc.stdlib : malloc, free, exit, EXIT_FAILURE; 
    1818    import tango.stdc.string : strlen; 
    19     import tango.stdc.stdio : printf; 
    2019} 
    2120 
     
    9190{ 
    9291    static bool hasBeenCalled; 
    93      
     92 
    9493    if (hasBeenCalled) 
    9594        return; 
    96          
     95 
    9796    hasBeenCalled = true; 
    98      
     97 
    9998    version (Posix) 
    10099    { 
     
    109108{ 
    110109    static bool result; 
    111      
     110 
    112111    if (result) 
    113112        return result; 
    114      
     113 
    115114    _d_criticalInit(); 
    116115 
     
    146145{ 
    147146    static bool hasBeenCalled; 
    148      
     147 
    149148    if (hasBeenCalled) 
    150149        return; 
    151          
     150 
    152151    hasBeenCalled = true; 
    153      
     152 
    154153    version (Posix) 
    155154    { 
     
    162161{ 
    163162    static bool result; 
    164      
     163 
    165164    if (result) 
    166165        return result; 
    167      
     166 
    168167    try 
    169168    { 
    170169        _d_isHalting = true; 
    171         thread_joinAll();         
     170        thread_joinAll(); 
    172171        _moduleDtor(); 
    173172        gc_term(); 
     
    215214version(NoCMain) 
    216215{ 
    217      
     216 
    218217} 
    219218else 
     
    254253    __libc_stack_end = cast(void*)&argv; 
    255254    } 
    256      
     255 
    257256    version (Posix) 
    258257        _d_criticalInit(); 
     
    315314            catch (Object o) 
    316315            { 
    317                 //fprintf(stderr, "%.*s\n", o.toString()); 
    318316                console (o.toString)("\n"); 
    319317                result = EXIT_FAILURE; 
     
    344342        rt_init(); 
    345343        if (runModuleUnitTests()) 
     344        { 
    346345            tryExec(&runMain); 
     346        } 
     347 
    347348        rt_term(); 
    348349    } 
     
    352353    version (Posix) 
    353354        _d_criticalTerm(); 
    354          
     355 
    355356    return result; 
    356357} 
  • trunk/tango/core/rt/compiler/dmd/rt/lifetime.d

    r5609 r5652  
    3434    import tango.stdc.stdarg; 
    3535    debug(PRINTF) import tango.stdc.stdio : printf; 
     36 
     37    alias void[] array_t; 
    3638} 
    3739 
     
    193195 * (For when the array is initialized to 0) 
    194196 */ 
    195 extern (C) ulong _d_newarrayT(TypeInfo ti, size_t length) 
     197extern(C) array_t _d_newarrayT(TypeInfo ti, size_t length) 
    196198{ 
    197199    void* p; 
    198     ulong result; 
     200    array_t result; 
    199201    auto size = ti.next.tsize();                // array element size 
    200202 
    201203    debug(PRINTF) printf("_d_newarrayT(length = x%x, size = %d)\n", length, size); 
    202204    if (length == 0 || size == 0) 
    203         result = 0
     205        result = array_t.init
    204206    else 
    205207    { 
     
    214216            } 
    215217        } 
     218        else version (D_InlineAsm_X86_64) 
     219            asm 
     220            { 
     221                mov     RAX,size        ; 
     222                mul     RAX,length      ; 
     223                mov     size,RAX        ; 
     224                jc      Loverflow       ; 
     225            } 
    216226        else 
    217227            size *= length; 
     228 
    218229        PointerMap pm; 
    219         version (D_HavePointerMap) { 
    220             pm = ti.next.pointermap(); 
    221         } 
     230        version (D_HavePointerMap)  pm = ti.next.pointermap(); 
     231 
    222232        p = gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
    223233        debug(PRINTF) printf(" p = %p\n", p); 
    224234        memset(p, 0, size); 
    225         result = cast(ulong)length + (cast(ulong)cast(uint)p << 32)
     235        result = cast(array_t)p[0..length]
    226236    } 
    227237    return result; 
     
    234244 * For when the array has a non-zero initializer. 
    235245 */ 
    236 extern (C) ulong _d_newarrayiT(TypeInfo ti, size_t length) 
    237 { 
    238     ulong result; 
     246extern(C) array_t _d_newarrayiT(TypeInfo ti, size_t length) 
     247{ 
     248    array_t result; 
    239249    auto size = ti.next.tsize();                // array element size 
    240250 
     
    242252 
    243253    if (length == 0 || size == 0) 
    244         result = 0
     254        result = array_t.init
    245255    else 
    246256    { 
     
    258268            } 
    259269        } 
     270        else version (D_InlineAsm_X86_64) 
     271            asm 
     272            { 
     273                mov     RAX,size        ; 
     274                mul     RAX,length      ; 
     275                mov     size,RAX        ; 
     276                jc      Loverflow       ; 
     277            } 
    260278        else 
    261279            size *= length; 
     280 
    262281        PointerMap pm; 
    263282        version (D_HavePointerMap) { 
     
    285304        } 
    286305        va_end(q); 
    287         result = cast(ulong)length + (cast(ulong)cast(uint)p << 32)
     306        result = cast(array_t)p[0..length]
    288307    } 
    289308    return result; 
     
    296315 * 
    297316 */ 
    298 extern (C) ulong _d_newarraymT(TypeInfo ti, int ndims, ...) 
    299 { 
    300     ulong result; 
     317extern(C) array_t _d_newarraymT(TypeInfo ti, int ndims, ...) 
     318{ 
     319    array_t result; 
    301320 
    302321    debug(PRINTF) printf("_d_newarraymT(ndims = %d)\n", ndims); 
    303322    if (ndims == 0) 
    304         result = 0
     323        result = array_t.init
    305324    else 
    306     {   va_list q; 
    307         va_start!(int)(q, ndims); 
    308  
    309         void[] foo(TypeInfo ti, size_t* pdim, int ndims) 
    310         { 
    311             size_t dim = *pdim; 
     325    { 
     326        va_list q; 
     327 
     328        version(X86) 
     329            va_start(q, ndims); 
     330        else version(X86_64) 
     331            va_start(q, __va_argsave); 
     332        else 
     333            static assert(false, "platform not supported"); 
     334 
     335        void[] foo(TypeInfo ti, va_list ap, int ndims) 
     336        { 
     337            size_t dim; 
     338            va_arg(ap, dim); 
    312339            void[] p; 
    313340 
     
    321348            { 
    322349                p = gc_malloc(dim * (void[]).sizeof + 1)[0 .. dim]; 
    323                 for (int i = 0; i < dim; i++) 
     350 
     351                version (X86) 
    324352                { 
    325                     (cast(void[]*)p.ptr)[i] = foo(ti.next, pdim + 1, ndims - 1); 
     353                    va_list ap2; 
     354                    va_copy(ap2, ap); 
    326355                } 
     356 
     357                for (size_t i = 0; i < dim; i++) 
     358                { 
     359                    version (X86_64) 
     360                    { 
     361                        __va_list argsave = *cast(__va_list*)ap; 
     362                        va_list ap2 = &argsave; 
     363                    } 
     364                    (cast(void[]*)p.ptr)[i] = foo(ti.next, ap2, ndims - 1); 
     365                } 
    327366            } 
    328367            return p; 
    329368        } 
    330369 
    331         size_t* pdim = cast(size_t *)q; 
    332         result = cast(ulong)foo(ti, pdim, ndims); 
     370        result = cast(typeof(result))foo(ti, q, ndims); 
    333371        debug(PRINTF) printf("result = %llx\n", result); 
    334372 
     
    349387 * 
    350388 */ 
    351 extern (C) ulong _d_newarraymiT(TypeInfo ti, int ndims, ...) 
    352 { 
    353     ulong result; 
     389extern(C) array_t _d_newarraymiT(TypeInfo ti, size_t ndims, ...) 
     390{ 
     391    array_t result; 
    354392 
    355393    debug(PRINTF) printf("_d_newarraymiT(ndims = %d)\n", ndims); 
    356394    if (ndims == 0) 
    357         result = 0
     395        result = array_t.init
    358396    else 
    359397    { 
    360398        va_list q; 
    361         va_start!(int)(q, ndims); 
    362  
    363         void[] foo(TypeInfo ti, size_t* pdim, int ndims) 
    364         { 
    365             size_t dim = *pdim; 
     399 
     400        version(X86) 
     401            va_start(q, ndims); 
     402        else version(X86_64) 
     403            va_start(q, __va_argsave); 
     404        else 
     405            static assert(false, "platform not supported"); 
     406 
     407        void[] foo(TypeInfo ti, va_list ap, size_t ndims) 
     408        { 
     409            size_t dim; 
     410            va_arg(ap, dim); 
    366411            void[] p; 
    367412 
     
    374419            { 
    375420                p = gc_malloc(dim * (void[]).sizeof + 1)[0 .. dim]; 
    376                 for (int i = 0; i < dim; i++) 
     421 
     422                version (X86) 
    377423                { 
    378                     (cast(void[]*)p.ptr)[i] = foo(ti.next, pdim + 1, ndims - 1); 
     424                    va_list ap2; 
     425                    va_copy(ap2, ap); 
    379426                } 
    380             } 
     427 
     428                for (size_t i = 0; i < dim; i++) 
     429                { 
     430                    version (X86_64) 
     431                    { 
     432                        __va_list argsave = *cast(__va_list*)ap; 
     433                        va_list ap2 = &argsave; 
     434                    } 
     435                    (cast(void[]*)p.ptr)[i] = foo(ti.next, ap2, ndims - 1); 
     436                } 
     437            } 
     438 
    381439            return p; 
    382440        } 
    383441 
    384         size_t* pdim = cast(size_t *)q; 
    385         result = cast(ulong)foo(ti, pdim, ndims); 
     442        result = cast(typeof(result))foo(ti, q, ndims); 
    386443        debug(PRINTF) printf("result = %llx\n", result); 
    387444 
     
    458515        Interface *pi = **cast(Interface ***)p; 
    459516        Object o = cast(Object)(p - pi.offset); 
     517        debug(PRINTF)  printf("finalizing..."); 
    460518        rt_finalize(cast(void*)o); 
    461519    } 
     
    468526extern (C) void _d_callfinalizer(void* p) 
    469527{ 
     528    debug(PRINTF)  printf("dcall finalizing..."); 
    470529    rt_finalize( p ); 
    471530} 
     
    491550    { 
    492551        if (det) 
     552        { 
     553            debug(PRINTF) printf("\t det=true, calling dispose\n"); 
    493554           (cast(Object)p).dispose(); 
     555        } 
     556        debug(PRINTF) printf("\tcasting to class info\n"); 
    494557 
    495558        ClassInfo** pc = cast(ClassInfo**)p; 
    496559 
     560        debug(PRINTF) printf("\tdereferencing pc: %lu\n", *pc); 
     561 
    497562        if (*pc) 
    498563        { 
     
    501566            try 
    502567            { 
     568                debug(PRINTF) printf("\tdoing tests.. collecthandler is %lu\n", cast(void*)collectHandler); 
    503569                if (det || collectHandler is null || collectHandler(cast(Object)p)) 
    504570                { 
     
    510576                            dg.ptr = p; 
    511577                            dg.funcptr = cast(void function()) c.destructor; 
     578                            debug(PRINTF) printf("\tcalling dtor of %s\n", c.name.ptr); 
    512579                            dg(); // call destructor 
     580                            debug(PRINTF) printf("\tdtor done.\n"); 
    513581                        } 
    514582                        c = c.base; 
     
    520588            catch (Exception e) 
    521589            { 
     590                debug(PRINTF) printf("\tException while finalizing\n"); 
    522591                onFinalizeError(**pc, e); 
    523592            } 
     
    528597        } 
    529598    } 
     599    debug(PRINTF) printf("\tLeaving.\n"); 
    530600} 
    531601 
     
    754824} 
    755825 
     826/************************************** 
     827 * Extend an array by n elements. 
     828 * Caller must initialize that element. 
     829 */ 
     830extern (C) byte[] _d_arrayappendcTX(TypeInfo ti, inout byte[] x, size_t n) 
     831{ 
     832    auto sizeelem = ti.next.tsize();            // array element size 
     833    auto info = gc_query(x.ptr); 
     834    auto length = x.length; 
     835    auto newlength = length + n; 
     836    auto newsize = newlength * sizeelem; 
     837 
     838    assert(info.size == 0 || length * sizeelem <= info.size); 
     839 
     840    //printf("_d_arrayappendcTX(sizeelem = %d, ptr = %p, length = %d, cap = %d)\n", sizeelem, x.ptr, x.length, cap); 
     841 
     842    if (newsize >= info.size) 
     843    {   byte* newdata; 
     844 
     845        if (info.size >= PAGESIZE) 
     846        {   // Try to extend in-place 
     847            auto u = gc_extend(x.ptr, (newsize + 1) - info.size, (newsize + 1) - info.size); 
     848            if (u) 
     849            { 
     850                goto L1; 
     851            } 
     852        } 
     853 
     854        PointerMap pm; 
     855        version (D_HavePointerMap) { 
     856            pm = ti.next.pointermap(); 
     857        } 
     858 
     859        uint attr = !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0; 
     860        newdata = cast(byte *) gc_malloc(newCapacity(newlength, sizeelem) + 1, attr, pm); 
     861 
     862        memcpy(newdata, x.ptr, length * sizeelem); 
     863 
     864        (cast(void **)(&x))[1] = newdata; 
     865    } 
     866 
     867  L1: 
     868    *cast(size_t *)&x = newlength; 
     869    assert((cast(size_t)x.ptr & 15) == 0); 
     870    assert(gc_query(x.ptr).size > x.length * sizeelem); 
     871    return x; 
     872} 
     873 
    756874 
    757875/** 
     
    831949            const size_t a=100; // allocate at most a% of the requested size as extra space (rounding will change this) 
    832950            const size_t minBits=1; // minimum bit size 
    833              
     951 
    834952 
    835953            static size_t log2plusB(size_t c) 
     
    9031021} 
    9041022 
     1023import tango.io.Stdout; 
    9051024 
    9061025/** 
     
    11141233    auto size = ti.next.tsize(); // array element size 
    11151234 
    1116     p = cast(byte[]*)(&n + 1); 
    1117  
    1118     for (i = 0; i < n; i++) 
    1119     { 
    1120         b = *p++; 
    1121         length += b.length; 
    1122     } 
     1235    version (X86) 
     1236    { 
     1237        p = cast(byte[]*)(&n + 1); 
     1238        for (i = 0; i < n; i++) 
     1239        { 
     1240            b = *p++; 
     1241            length += b.length; 
     1242        } 
     1243    } 
     1244    else version (X86_64) 
     1245    { 
     1246        __va_list argsave = __va_argsave.va; 
     1247        va_list ap; 
     1248        va_start(ap, __va_argsave); 
     1249        for (i = 0; i < n; i++) 
     1250        { 
     1251            b.length = 0; 
     1252            va_arg(ap, b); 
     1253            length += b.length; 
     1254        } 
     1255        va_end(ap); 
     1256    } 
     1257 
    11231258    if (!length) 
    11241259        return null; 
     
    11291264    } 
    11301265    a = gc_malloc(length * size, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
    1131     p = cast(byte[]*)(&n + 1); 
    1132  
    1133     uint j = 0; 
    1134     for (i = 0; i < n; i++) 
    1135     { 
    1136         b = *p++; 
    1137         if (b.length) 
    1138         { 
    1139             memcpy(a + j, b.ptr, b.length * size); 
    1140             j += b.length * size; 
    1141         } 
     1266 
     1267    version (X86) 
     1268    { 
     1269        p = cast(byte[]*)(&n + 1); 
     1270        size_t j = 0; 
     1271        for (i = 0; i < n; i++) 
     1272        { 
     1273            b = *p++; 
     1274            if (b.length) 
     1275            { 
     1276                memcpy(a + j, b.ptr, b.length * size); 
     1277                j += b.length * size; 
     1278            } 
     1279        } 
     1280    } 
     1281    else version (X86_64) 
     1282    { 
     1283        va_list ap2 = &argsave; 
     1284        size_t j = 0; 
     1285        for (i = 0; i < n; i++) 
     1286        { 
     1287            b.length = 0; 
     1288            va_arg(ap2, b); 
     1289            if (b.length) 
     1290            { 
     1291                memcpy(a + j, b.ptr, b.length * size); 
     1292                j += b.length * size; 
     1293            } 
     1294        } 
     1295        va_end(ap2); 
    11421296    } 
    11431297 
     
    11481302} 
    11491303 
    1150  
    1151 /** 
    1152  * 
    1153  */ 
    1154 extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...) 
     1304extern (C) void* _d_arrayliteralTX(TypeInfo ti, size_t length) 
     1305
     1306    auto sizeelem = ti.next.tsize();            // array element size 
     1307    void* result; 
     1308 
     1309    //printf("_d_arrayliteralTX(sizeelem = %d, length = %d)\n", sizeelem, length); 
     1310    if (length == 0 || sizeelem == 0) 
     1311        result = null; 
     1312    else 
     1313    { 
     1314        PointerMap pm; 
     1315        version (D_HavePointerMap) { 
     1316            pm = ti.next.pointermap(); 
     1317        } 
     1318        result = gc_malloc(length * sizeelem, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
     1319    } 
     1320    return result; 
     1321
     1322 
     1323/** 
     1324 * 
     1325 */ 
     1326version (X86) extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...) 
    11551327{ 
    11561328    auto sizeelem = ti.next.tsize();            // array element size 
     
    11681340        result = gc_malloc(length * sizeelem, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
    11691341 
    1170         va_list q; 
    1171         va_start!(size_t)(q, length); 
    1172  
    1173         size_t stacksize = (sizeelem + int.sizeof - 1) & ~(int.sizeof - 1); 
    1174  
    1175         if (stacksize == sizeelem) 
    1176         { 
    1177             memcpy(result, q, length * sizeelem); 
    1178         } 
    1179         else 
    1180         { 
     1342        version(X86) 
     1343        { 
     1344            va_list q; 
     1345            va_start!(size_t)(q, length); 
     1346 
     1347            size_t stacksize = (sizeelem + int.sizeof - 1) & ~(int.sizeof - 1); 
     1348 
     1349            if (stacksize == sizeelem) 
     1350            { 
     1351                memcpy(result, q, length * sizeelem); 
     1352            } 
     1353            else 
     1354            { 
     1355                for (size_t i = 0; i < length; i++) 
     1356                { 
     1357                    memcpy(result + i * sizeelem, q, sizeelem); 
     1358                    q += stacksize; 
     1359                } 
     1360            } 
     1361 
     1362            va_end(q); 
     1363        } 
     1364        else version(X86_64) 
     1365        { 
     1366            va_list q; 
     1367            va_start(q, __va_argsave); 
    11811368            for (size_t i = 0; i < length; i++) 
    11821369            { 
    1183                 memcpy(result + i * sizeelem, q, sizeelem); 
    1184                 q += stacksize; 
    1185             } 
    1186         } 
    1187  
    1188         va_end(q); 
     1370                va_arg(q, ti.next, result + i * sizeelem); 
     1371            } 
     1372            va_end(q); 
     1373        } 
    11891374    } 
    11901375    return result; 
     
    12051390 * 
    12061391 */ 
    1207 extern (C) long _adDupT(TypeInfo ti, Array2 a) 
     1392extern (C) array_t _adDupT(TypeInfo ti, Array2 a) 
    12081393out (result) 
    12091394{ 
     
    12271412        memcpy(r.ptr, a.ptr, size); 
    12281413    } 
    1229     return *cast(long*)(&r); 
     1414    return *cast(array_t*)(&r); 
    12301415} 
    12311416 
  • trunk/tango/core/rt/compiler/dmd/rt/memory.d

    r5149 r5652  
    110110        } 
    111111    } 
     112    else version( D_InlineAsm_X86_64 ) 
     113    { 
     114        asm 
     115        { 
     116            naked; 
     117            mov RAX, RSP; 
     118            ret; 
     119        } 
     120    } 
    112121    else 
    113122    { 
     
    156165        } 
    157166    } 
    158      
     167 
    159168    version (Solaris) 
    160169    { 
  • trunk/tango/core/rt/compiler/dmd/rt/memset.d

    r5015 r5652  
    4242} 
    4343 
     44 
    4445int *_memset32(int *p, int value, size_t count) 
    4546{ 
    46 version (X86) 
     47version (D_InlineAsm_X86) 
    4748{ 
    4849    asm 
     
    119120    return pstart; 
    120121} 
     122 
     123float *_memsetFloat(float *p, float value, size_t count) 
     124{ 
     125    float *pstart = p; 
     126    float *ptop; 
     127 
     128    for (ptop = &p[count]; p < ptop; p++) 
     129        *p = value; 
     130    return pstart; 
     131} 
     132 
     133double *_memsetDouble(double *p, double value, size_t count) 
     134{ 
     135    double *pstart = p; 
     136    double *ptop; 
     137 
     138    for (ptop = &p[count]; p < ptop; p++) 
     139        *p = value; 
     140    return pstart; 
     141} 
  • trunk/tango/core/rt/compiler/dmd/rt/trace.d

    r5015 r5652  
    1818    import rt.compiler.util.string; 
    1919    import tango.stdc.string : memset, memcpy, strlen; 
    20     import tango.stdc.stdlib : malloc, free, exit, strtoul, strtoull, qsort,  
     20    import tango.stdc.stdlib : malloc, free, exit, strtoul, strtoull, qsort, 
    2121                                EXIT_FAILURE; 
    2222    import tango.stdc.ctype : isspace, isalpha, isgraph; 
     
    788788     *  ascii   string 
    789789     */ 
    790  
    791     version (OSX) { // 16 byte align stack 
    792         asm { 
    793             naked               ; 
    794             pushad              ; 
    795             mov ECX,8*4[ESP]        ; 
    796             xor EAX,EAX         ; 
    797             mov AL,[ECX]        ; 
    798             cmp AL,0xFF         ; 
    799             jne L1          ; 
    800             cmp byte ptr 1[ECX],0   ; 
    801             jne L1          ; 
    802             mov AX,2[ECX]       ; 
    803             add 8*4[ESP],3      ; 
    804             add ECX,3           ; 
    805                L1:  inc EAX         ; 
    806             inc ECX         ; 
    807             add 8*4[ESP],EAX        ; 
    808             dec EAX         ; 
    809             sub ESP,4           ; 
    810             push    ECX         ; 
    811             push    EAX         ; 
    812             call    trace_pro       ; 
    813             add ESP,12          ; 
    814             popad               ; 
    815             ret             ; 
    816         } 
    817     } else { 
    818         asm { 
    819             naked                           ; 
    820             pushad                          ; 
    821             mov     ECX,8*4[ESP]            ; 
    822             xor     EAX,EAX                 ; 
    823             mov     AL,[ECX]                ; 
    824             cmp     AL,0xFF                 ; 
    825             jne     L1                      ; 
    826             cmp     byte ptr 1[ECX],0       ; 
    827             jne     L1                      ; 
    828             mov     AX,2[ECX]               ; 
    829             add     8*4[ESP],3              ; 
    830             add     ECX,3                   ; 
    831         L1: inc     EAX                     ; 
    832             inc     ECX                     ; 
    833             add     8*4[ESP],EAX            ; 
    834             dec     EAX                     ; 
    835             push    ECX                     ; 
    836             push    EAX                     ; 
    837             call    trace_pro               ; 
    838             add     ESP,8                   ; 
    839             popad                           ; 
    840             ret                             ; 
    841         } 
    842     } 
     790  version (OSX) 
     791  { // 16 byte align stack 
     792   version (D_InlineAsm_X86) 
     793    asm 
     794    {   naked                           ; 
     795        pushad                          ; 
     796        mov     ECX,8*4[ESP]            ; 
     797        xor     EAX,EAX                 ; 
     798        mov     AL,[ECX]                ; 
     799        cmp     AL,0xFF                 ; 
     800        jne     L1                      ; 
     801        cmp     byte ptr 1[ECX],0       ; 
     802        jne     L1                      ; 
     803        mov     AX,2[ECX]               ; 
     804        add     8*4[ESP],3              ; 
     805        add     ECX,3                   ; 
     806    L1: inc     EAX                     ; 
     807        inc     ECX                     ; 
     808        add     8*4[ESP],EAX            ; 
     809        dec     EAX                     ; 
     810        sub     ESP,4                   ; 
     811        push    ECX                     ; 
     812        push    EAX                     ; 
     813        call    trace_pro               ; 
     814        add     ESP,12                  ; 
     815        popad                           ; 
     816        ret                             ; 
     817    } 
     818      else version (D_InlineAsm_X86_64) 
     819            static assert(0); 
     820      else 
     821            static assert(0); 
     822  } 
     823  else 
     824  { 
     825   version (D_InlineAsm_X86) 
     826    asm 
     827    {   naked                           ; 
     828        pushad                          ; 
     829        mov     ECX,8*4[ESP]            ; 
     830        xor     EAX,EAX                 ; 
     831        mov     AL,[ECX]                ; 
     832        cmp     AL,0xFF                 ; 
     833        jne     L1                      ; 
     834        cmp     byte ptr 1[ECX],0       ; 
     835        jne     L1                      ; 
     836        mov     AX,2[ECX]               ; 
     837        add     8*4[ESP],3              ; 
     838        add     ECX,3                   ; 
     839    L1: inc     EAX                     ; 
     840        inc     ECX                     ; 
     841        add     8*4[ESP],EAX            ; 
     842        dec     EAX                     ; 
     843        push    ECX                     ; 
     844        push    EAX                     ; 
     845        call    trace_pro               ; 
     846        add     ESP,8                   ; 
     847        popad                           ; 
     848        ret                             ; 
     849    } 
     850    else version (D_InlineAsm_X86_64) 
     851    asm 
     852    {   naked                           ; 
     853        push    RAX                     ; 
     854        push    RCX                     ; 
     855        push    RDX                     ; 
     856        push    RSI                     ; 
     857        push    RDI                     ; 
     858        push    R8                      ; 
     859        push    R9                      ; 
     860        push    R10                     ; 
     861        push    R11                     ; 
     862        mov     RCX,9*8[RSP]            ; 
     863        xor     RAX,RAX                 ; 
     864        mov     AL,[RCX]                ; 
     865        cmp     AL,0xFF                 ; 
     866        jne     L1                      ; 
     867        cmp     byte ptr 1[RCX],0       ; 
     868        jne     L1                      ; 
     869        mov     AX,2[RCX]               ; 
     870        add     9*8[RSP],3              ; 
     871        add     RCX,3                   ; 
     872    L1: inc     RAX                     ; 
     873        inc     RCX                     ; 
     874        add     9*8[RSP],RAX            ; 
     875        dec     RAX                     ; 
     876        push    RCX                     ; 
     877        push    RAX                     ; 
     878        call    trace_pro               ; 
     879        add     RSP,16                  ; 
     880        pop     R11                     ; 
     881        pop     R10                     ; 
     882        pop     R8                      ; 
     883        pop     R9                      ; 
     884        pop     RDI                     ; 
     885        pop     RSI                     ; 
     886        pop     RDX                     ; 
     887        pop     RCX                     ; 
     888        pop     RAX                     ; 
     889        ret                             ; 
     890    } 
     891    else 
     892            static assert(0); 
     893  } 
    843894} 
    844895 
     
    907958    } 
    908959} 
     960else version (D_InlineAsm_X86_64) 
     961{ 
     962    extern (D) 
     963    { 
     964        void QueryPerformanceCounter(timer_t* ctr) 
     965        { 
     966            asm 
     967            { 
     968                naked                   ; 
     969                rdtsc                   ; 
     970                mov   [RDI],EAX         ; 
     971                mov   4[RDI],EDX        ; 
     972                ret                     ; 
     973            } 
     974        } 
     975 
     976        void QueryPerformanceFrequency(timer_t* freq) 
     977        { 
     978            *freq = 3579545; 
     979        } 
     980    } 
     981} 
    909982else 
    910983{ 
  • trunk/tango/core/rt/compiler/dmd/std/intrinsic.d

    r5594 r5652  
    77 * integrated in with intrinsic functions, bringing to bear their full power on 
    88 * them. This can result in some surprising speedups. 
    9  *  
     9 * 
    1010 * Note that this module is only present in Tango because the module name is 
    11  * hardcoded into DMD, see http://d.puremagic.com/issues/show_bug.cgi?id=178  
     11 * hardcoded into DMD, see http://d.puremagic.com/issues/show_bug.cgi?id=178 
    1212 * To correctly use this functionality in Tango, import tango.core.BitManip. 
    1313 * 
     
    2626 *  The return value is undefined if v is zero. 
    2727 */ 
    28 int bsf( uint v ); 
     28int bsf( size_t v ); 
    2929 
    3030 
     
    134134</pre> 
    135135 */ 
     136 
    136137int bts( size_t* p, size_t bitnum ); 
    137  
    138138 
    139139/** 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_AC.d

    r4974 r5652  
    8383    } 
    8484 
     85    override size_t talign() 
     86    { 
     87        return (Object[]).alignof; 
     88    } 
     89 
    8590    override size_t tsize() 
    8691    { 
     
    97102        return typeid(Object); 
    98103    } 
     104 
     105    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     106    { 
     107        return 0; 
     108    } 
    99109} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Acdouble.d

    r4974 r5652  
    7676    } 
    7777 
     78    override size_t talign() 
     79    { 
     80        return (cdouble[]).alignof; 
     81    } 
     82 
    7883    override size_t tsize() 
    7984    { 
     
    9095        return typeid(cdouble); 
    9196    } 
     97 
     98    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     99    { 
     100        return 0; 
     101    } 
    92102} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Acfloat.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (cfloat[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(cfloat); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Acreal.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (creal[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(creal); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Adouble.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (double[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(double); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Afloat.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (float[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(float); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Ag.d

    r5012 r5652  
    4747            return 1; 
    4848        return 0; 
     49    } 
     50 
     51    override size_t talign() 
     52    { 
     53        return (byte[]).alignof; 
    4954    } 
    5055 
     
    118123    override hash_t getHash(in void* p){ 
    119124        char[] s = *cast(char[]*)p; 
     125 
    120126        version (OldHash) 
    121127        { 
     
    134140        return typeid(char); 
    135141    } 
     142 
     143    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     144    { 
     145        return 0; 
     146    } 
    136147} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Aint.d

    r5012 r5652  
    4848    } 
    4949 
     50    override size_t talign() 
     51    { 
     52        return (int[]).alignof; 
     53    } 
     54 
    5055    override size_t tsize() 
    5156    { 
     
    6166    { 
    6267        return typeid(int); 
     68    } 
     69 
     70    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     71    { 
     72        return 0; 
    6373    } 
    6474} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Along.d

    r5012 r5652  
    4949    } 
    5050 
     51    override size_t talign() 
     52    { 
     53        return (long[]).alignof; 
     54    } 
     55 
    5156    override size_t tsize() 
    5257    { 
     
    6267    { 
    6368        return typeid(long); 
     69    } 
     70 
     71    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     72    { 
     73        return 0; 
    6474    } 
    6575} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Areal.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (real[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(real); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_Ashort.d

    r5012 r5652  
    4848    } 
    4949 
     50    override size_t talign() 
     51    { 
     52        return (short[]).alignof; 
     53    } 
     54 
    5055    override size_t tsize() 
    5156    { 
     
    6166    { 
    6267        return typeid(short); 
     68    } 
     69 
     70    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     71    { 
     72        arg1 = typeid(size_t); 
     73        arg2 = typeid(void*); 
     74        return 0; 
    6375    } 
    6476} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_C.d

    r4974 r5652  
    6363    } 
    6464 
     65    override size_t talign() 
     66    { 
     67        return Object.alignof; 
     68    } 
     69 
    6570    override size_t tsize() 
    6671    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_byte.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return byte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_cdouble.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cdouble.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(cdouble *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        return 0; 
     75    } 
    6676} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_cfloat.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cfloat.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(cfloat *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        arg1 = typeid(double); 
     75        return 0; 
     76    } 
    6677} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_char.d

    r4974 r5652  
    2121    } 
    2222 
     23    override size_t talign() 
     24    { 
     25        return char.alignof; 
     26    } 
     27 
    2328    override size_t tsize() 
    2429    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_creal.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return creal.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(creal *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        arg1 = typeid(real); 
     75        arg2 = typeid(real); 
     76        return 0; 
     77    } 
    6678} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_dchar.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return dchar.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_delegate.d

    r4974 r5652  
    1919    } 
    2020 
     21    override size_t talign() 
     22    { 
     23        return dg.alignof; 
     24    } 
     25 
    2126    override size_t tsize() 
    2227    { 
     
    3742        return 1; 
    3843    } 
     44 
     45    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     46    { 
     47        arg1 = typeid(void*); 
     48        arg2 = typeid(void*); 
     49        return 0; 
     50    } 
    3951} 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_double.d

    r4974 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return double.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_float.d

    r4974 r5652  
    4343    } 
    4444 
     45    override size_t talign() 
     46    { 
     47        return float.alignof; 
     48    } 
     49 
    4550    override size_t tsize() 
    4651    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_int.d

    r4974 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return int.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_long.d

    r4974 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return long.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_ptr.d

    r4974 r5652  
    2626    } 
    2727 
     28    override size_t talign() 
     29    { 
     30        return (void*).alignof; 
     31    } 
     32 
    2833    override size_t tsize() 
    2934    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_real.d

    r4974 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return real.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_short.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return short.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_ubyte.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ubyte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_uint.d

    r4974 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return uint.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_ulong.d

    r4974 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return ulong.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_ushort.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ushort.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_void.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return void.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/dmd/typeinfo/ti_wchar.d

    r4974 r5652  
    2222    } 
    2323 
     24    override size_t talign() 
     25    { 
     26        return wchar.alignof; 
     27    } 
     28 
    2429    override size_t tsize() 
    2530    { 
  • trunk/tango/core/rt/compiler/gdc/object_.d

    r5609 r5652  
    4747    import rt.compiler.gdc.rt.aaA; 
    4848    import tango.core.Exception : onOutOfMemoryError; 
    49     debug(PRINTF) import tango.stdc.stdio : printf; 
     49    import tango.stdc.stdio : printf; 
    5050    extern (C) Object _d_newclass(ClassInfo ci); 
    5151} 
    5252 
    53 // NOTE: For some reason, this declaration method doesn't work 
    54 //       in this particular file (and this file only).  It must 
    55 //       be a DMD thing. 
    5653alias typeof(int.sizeof)                    size_t; 
    5754alias typeof(cast(void*)0 - cast(void*)0)   ptrdiff_t; 
    58 /+ 
    59 version( X86_64 ) 
    60 
    61     alias ulong size_t; 
    62     alias long  ptrdiff_t; 
    63 
    64 else 
    65 
    66     alias uint  size_t; 
    67     alias int   ptrdiff_t; 
    68 
    69 +/ 
     55 
    7056alias size_t hash_t; 
    7157alias int equals_t; 
    7258 
    73 version (PhobosCompatibility)  
    74 {  
     59version (PhobosCompatibility) 
     60{ 
    7561        alias char[]  string; 
    7662        alias wchar[] wstring; 
     
    8470{ 
    8571    /** 
    86      * Override this to capture an explicit delete or an implicit  
     72     * Override this to capture an explicit delete or an implicit 
    8773     * delete via a scoped-instance. Unlike a dtor(), GC references 
    8874     * are still intact when this method is invoked 
     
    328314        foreach (m; ModuleInfo) 
    329315        { 
     316            if (!m) 
     317                continue; 
     318 
    330319            //writefln("module %s, %d", m.name, m.localClasses.length); 
    331320            foreach (c; m.localClasses) 
     
    413402    /// Compares two instances for &lt;, ==, or &gt;. 
    414403    int compare(in void* p1, in void* p2) { return 0; } // throw new Exception("non comparable",__FILE__,__LINE__); 
     404 
     405     /// Return alignment of type 
     406    size_t talign() { return tsize(); } 
    415407 
    416408    /// Returns size of the type. 
     
    470462    /// Get type information on the contents of the type; null if not available 
    471463    OffsetTypeInfo[] offTi() { return null; } 
     464 
     465 
     466     /** Return internal info on arguments fitting into 8byte. 
     467       * See X86-64 ABI 3.2.3 
     468     */ 
     469    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     470    { 
     471        arg1 = this; 
     472        return 0; 
     473    } 
    472474} 
    473475 
     
    493495    override TypeInfo next() { return base; } 
    494496    override uint flags() { return base.flags(); } 
     497    override PointerMap pointermap() { return base.pointermap(); } 
    495498    override void[] init() { return m_init.length ? m_init : base.init(); } 
    496     override PointerMap pointermap() { return base.pointermap(); } 
     499 
     500    size_t talign() { return base.talign(); } 
     501 
     502    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     503    { 
     504        return base.argTypes(arg1, arg2); 
     505    } 
    497506 
    498507    TypeInfo base; 
     
    632641 
    633642    override uint flags() { return 1; } 
     643 
     644    size_t talign() 
     645    { 
     646        return (void[]).alignof; 
     647    } 
     648 
     649    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     650    {   //arg1 = typeid(size_t); 
     651        //arg2 = typeid(void*); 
     652        return 0; 
     653    } 
    634654 
    635655    override PointerMap pointermap() 
     
    747767    TypeInfo value; 
    748768    size_t   len; 
     769 
     770    size_t talign() 
     771    { 
     772        return value.talign(); 
     773    } 
     774 
     775    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     776    { 
     777        arg1 = typeid(void*); 
     778        return 0; 
     779    } 
     780 
    749781} 
    750782 
     
    815847    TypeInfo value; 
    816848    TypeInfo key; 
     849 
     850    size_t talign() 
     851    { 
     852        return (char[int]).alignof; 
     853    } 
     854 
     855    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     856    { 
     857        arg1 = typeid(void*); 
     858        return 0; 
     859    } 
    817860} 
    818861 
     
    899942 
    900943    TypeInfo next; 
     944 
     945    size_t talign() 
     946    { 
     947        alias int delegate() dg; 
     948        return dg.alignof; 
     949    } 
     950 
     951    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     952    {   //arg1 = typeid(void*); 
     953        //arg2 = typeid(void*); 
     954        return 0; 
     955    } 
     956 
    901957} 
    902958 
     
    11111167    override uint flags() { return m_flags; } 
    11121168 
     1169    size_t talign() { return m_align; } 
     1170 
     1171 
    11131172    char[] name; 
    11141173    void[] m_init;      // initializer; init.ptr == null if 0 initialize 
     
    11211180 
    11221181    uint m_flags; 
     1182    uint m_align; 
    11231183 
    11241184    version (D_HavePointerMap) { 
     
    11261186 
    11271187        override PointerMap pointermap() { return m_pointermap; } 
     1188    } 
     1189 
     1190    version (X86_64) 
     1191    { 
     1192        int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     1193        { 
     1194            arg1 = m_arg1; 
     1195            arg2 = m_arg2; 
     1196            return 0; 
     1197        } 
     1198        TypeInfo m_arg1; 
     1199        TypeInfo m_arg2; 
    11281200    } 
    11291201} 
     
    11911263 
    11921264    override PointerMap pointermap() 
     1265    { 
     1266        assert(0); 
     1267    } 
     1268 
     1269    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
    11931270    { 
    11941271        assert(0); 
     
    12461323                sink(file); 
    12471324                sink(":"); 
    1248                 sink(ulongToUtf8(buf, line)); 
     1325                sink(ulongToUtf8(buf, cast(size_t) line)); 
    12491326            } 
    12501327        } 
    1251          
     1328 
    12521329        void clear(){ 
    12531330            line=0; 
     
    14191496// Win32: this gets initialized by minit.asm 
    14201497// linux: this gets initialized in _moduleCtor() 
     1498// GDC: mod you I won't do what you tell me. 
    14211499extern (C) ModuleInfo[] _moduleinfo_array; 
    14221500 
    14231501 
    1424 version (linux) 
    1425 
    1426     // This linked list is created by a compiler generated function inserted 
    1427     // into the .ctor list by the compiler. 
    1428     struct ModuleReference 
    1429     { 
    1430         ModuleReference* next; 
    1431         ModuleInfo       mod; 
    1432     } 
    1433  
    1434     extern (C) ModuleReference* _Dmodule_ref;   // start of linked list 
    1435 
    1436  
    1437 version( freebsd ) 
    1438 
    1439     // This linked list is created by a compiler generated function inserted  
    1440     // into the .ctor list by the compiler.  
    1441     struct ModuleReference 
    1442     {  
    1443         ModuleReference* next;  
    1444         ModuleInfo mod;  
    1445      } 
    1446     extern (C) ModuleReference *_Dmodule_ref;   // start of linked list  
    1447 
     1502// This linked list is created by a compiler generated function inserted 
     1503// into the .ctor list by the compiler. 
     1504struct ModuleReference 
     1505
     1506    ModuleReference* next; 
     1507    ModuleInfo       mod; 
     1508
     1509 
     1510extern (C) ModuleReference* _Dmodule_ref;   // start of linked list 
    14481511 
    14491512ModuleInfo[] _moduleinfo_dtors; 
     
    14601523{ 
    14611524    debug(PRINTF) printf("_moduleCtor()\n"); 
    1462     version (linux) 
    1463     { 
    1464         int len = 0; 
    1465         ModuleReference *mr; 
    1466  
    1467         for (mr = _Dmodule_ref; mr; mr = mr.next) 
    1468             len++; 
    1469         _moduleinfo_array = new ModuleInfo[len]; 
    1470         len = 0; 
    1471         for (mr = _Dmodule_ref; mr; mr = mr.next) 
    1472         {   _moduleinfo_array[len] = mr.mod; 
    1473             len++; 
    1474         } 
    1475     } 
    1476  
    1477     version( freebsd ) 
    1478     { 
    1479         int len = 0; 
    1480         ModuleReference *mr; 
    1481  
    1482         for (mr = _Dmodule_ref; mr; mr = mr.next) 
    1483             len++; 
    1484         _moduleinfo_array = new ModuleInfo[len]; 
    1485         len = 0; 
    1486         for (mr = _Dmodule_ref; mr; mr = mr.next) 
    1487         { 
    1488             _moduleinfo_array[len] = mr.mod; 
    1489             len++; 
    1490         } 
    1491     } 
    1492  
    1493     version( OSX ) 
    1494     { 
    1495     /* The ModuleInfo references are stored in the special segment 
    1496      * __minfodata, which is bracketed by the segments __minfo_beg 
    1497      * and __minfo_end. The variables _minfo_beg and _minfo_end 
    1498      * are of zero size and are in the two bracketing segments, 
    1499      * respectively. 
    1500      *  
    1501      * The __minfo_beg and __minfo_end sections are not put into 
    1502      * dynamic libraries therefore we cannot use them or the 
    1503      * _minfo_beg and _minfo_end variables. Instead we loop through 
    1504      * all the loaded images (executables and dynamic libraries) and 
    1505      * collect all the ModuleInfo references. 
    1506      */ 
    1507         _moduleinfo_array = getSectionData!(ModuleInfo, "__DATA", "__minfodata");         
    1508         debug(PRINTF) printf("moduleinfo: ptr = %p, length = %d\n", _moduleinfo_array.ptr, _moduleinfo_array.length); 
    1509  
    1510         debug(PRINTF) foreach (m; _moduleinfo_array) 
    1511         { 
    1512             //printf("\t%p\n", m); 
    1513             printf("\t%.*s\n", m.name.length,m.name.ptr); 
    1514         } 
    1515     } 
    1516      
    1517     version (Win32) 
    1518     { 
    1519         // Ensure module destructors also get called on program termination 
    1520         //_fatexit(&_STD_moduleDtor); 
     1525 
     1526    int len = 0; 
     1527    ModuleReference *mr; 
     1528 
     1529    for (mr = _Dmodule_ref; mr; mr = mr.next) 
     1530        len++; 
     1531    _moduleinfo_array = new ModuleInfo[len]; 
     1532    len = 0; 
     1533    for (mr = _Dmodule_ref; mr; mr = mr.next) 
     1534    {   _moduleinfo_array[len] = mr.mod; 
     1535        len++; 
     1536    } 
     1537 
     1538    debug(PRINTF) foreach (m; _moduleinfo_array) 
     1539    { 
     1540        //printf("\t%p\n", m); 
     1541        printf("\t%.*s\n", m.name.length,m.name.ptr); 
    15211542    } 
    15221543 
     
    15491570        if (!m) 
    15501571            continue; 
    1551         debug(PRINTF) printf("\tmodule[%d] = '%.*s'\n", i, m.name); 
     1572        debug(PRINTF) printf("\tmodule[%d].name = '%s'\n", i, m.name); 
    15521573        if (m.flags & MIctordone) 
    15531574            continue; 
     
    15591580            {   if (skip || m.flags & MIstandalone) 
    15601581                    continue; 
    1561                 throw new Exception( "Cyclic dependency in module " ~ (from is null ? "*null*" : from.name) ~ " for import " ~ m.name);  
     1582                throw new Exception( "Cyclic dependency in module " ~ (from is null ? "*null*" : from.name) ~ " for import " ~ m.name); 
    15621583            } 
    15631584 
  • trunk/tango/core/rt/compiler/gdc/rt/aApply.d

    r5579 r5652  
    2626 */ 
    2727 
     28module rt.compiler.gdc.rt.aApply; 
     29 
    2830/* 
    2931 *  Modified by Sean Kelly <sean@f4.ca> for use with Tango. 
     
    3436 * and dchar, and 2 of each of those. 
    3537 */ 
    36 module rt.compiler.gdc.rt.aApply; 
     38 
    3739private import rt.compiler.util.utf; 
    3840 
     
    102104            else 
    103105            { 
    104        w = cast(wchar)((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     106                w = cast(wchar)((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    105107                result = dg(cast(void *)&w); 
    106108                if (result) 
    107109                    break; 
    108        w = cast(wchar)(((d - 0x10000) & 0x3FF) + 0xDC00); 
     110                w = cast(wchar)(((d - 0x10000) & 0x3FF) + 0xDC00); 
    109111            } 
    110112        } 
     
    199201        else 
    200202        { 
    201        w = cast(wchar)((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     203            w = cast(wchar)((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    202204            result = dg(cast(void *)&w); 
    203205            if (result) 
    204206                break; 
    205        w = cast(wchar)(((d - 0x10000) & 0x3FF) + 0xDC00); 
     207            w = cast(wchar)(((d - 0x10000) & 0x3FF) + 0xDC00); 
    206208        } 
    207209        result = dg(cast(void *)&w); 
     
    290292            else 
    291293            { 
    292        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     294                w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    293295                result = dg(&i, cast(void *)&w); 
    294296                if (result) 
    295297                    break; 
    296        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     298                w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    297299            } 
    298300        } 
     
    393395        else 
    394396        { 
    395        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     397            w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    396398            result = dg(&j, cast(void *)&w); 
    397399            if (result) 
    398400                break; 
    399        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     401            w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    400402        } 
    401403        result = dg(&j, cast(void *)&w); 
  • trunk/tango/core/rt/compiler/gdc/rt/aApplyR.d

    r5579 r5652  
    2727 */ 
    2828 
     29module rt.compiler.gdc.rt.aApplyR; 
     30 
    2931/* 
    3032 *  Modified by Sean Kelly <sean@f4.ca> for use with Tango. 
     
    3537 * and dchar, and 2 of each of those. 
    3638 */ 
    37 module rt.compiler.gdc.rt.aApplyR; 
     39 
    3840private import rt.compiler.util.utf; 
    3941 
     
    8082    debug(apply) printf("_aApplyRcd1.unittest\n"); 
    8183 
    82     { 
    83         auto s = "hello"c; 
    84         int i; 
    85  
    86         foreach_reverse(dchar d; s) 
    87         { 
    88             switch (i) 
    89             { 
    90                 case 0:     assert(d == 'o'); break; 
    91                 case 1:     assert(d == 'l'); break; 
    92                 case 2:     assert(d == 'l'); break; 
    93                 case 3:     assert(d == 'e'); break; 
    94                 case 4:     assert(d == 'h'); break; 
    95                 default:    assert(0); 
    96             } 
    97             i++; 
    98         } 
    99         assert(i == 5); 
    100     } 
    101      
    102     { 
    103         auto s = "a\u1234\U00100456b"c; 
    104         int i = 0; 
    105         foreach_reverse(dchar d; s) 
    106         { 
    107             //printf("i = %d, d = %x\n", i, d); 
    108             switch (i) 
    109             { 
    110                 case 0:     assert(d == 'b'); break; 
    111                 case 1:     assert(d == '\U00100456'); break; 
    112                 case 2:     assert(d == '\u1234'); break; 
    113                 case 3:     assert(d == 'a'); break; 
    114                 default:    assert(0); 
    115             } 
    116             i++; 
    117         } 
    118         assert(i == 4); 
    119     } 
     84    auto s = "hello"c[]; 
     85    int i; 
     86 
     87    foreach_reverse(dchar d; s) 
     88    { 
     89        switch (i) 
     90        { 
     91            case 0:     assert(d == 'o'); break; 
     92            case 1:     assert(d == 'l'); break; 
     93            case 2:     assert(d == 'l'); break; 
     94            case 3:     assert(d == 'e'); break; 
     95            case 4:     assert(d == 'h'); break; 
     96            default:    assert(0); 
     97        } 
     98        i++; 
     99    } 
     100    assert(i == 5); 
     101 
     102    s = "a\u1234\U00100456b"; 
     103    i = 0; 
     104    foreach_reverse(dchar d; s) 
     105    { 
     106        //printf("i = %d, d = %x\n", i, d); 
     107        switch (i) 
     108        { 
     109            case 0:     assert(d == 'b'); break; 
     110            case 1:     assert(d == '\U00100456'); break; 
     111            case 2:     assert(d == '\u1234'); break; 
     112            case 3:     assert(d == 'a'); break; 
     113            default:    assert(0); 
     114        } 
     115        i++; 
     116    } 
     117    assert(i == 4); 
    120118} 
    121119 
     
    166164    assert(i == 5); 
    167165 
    168     s = "a\u1234\U00100456b"w[]
     166    s = "a\u1234\U00100456b"
    169167    i = 0; 
    170168    foreach_reverse(dchar d; s) 
     
    216214            else 
    217215            { 
    218        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     216                w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    219217                result = dg(cast(void *)&w); 
    220218                if (result) 
    221219                    break; 
    222        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     220                w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    223221            } 
    224222        } 
     
    252250    assert(i == 5); 
    253251 
    254     s = "a\u1234\U00100456b"c[]
     252    s = "a\u1234\U00100456b"
    255253    i = 0; 
    256254    foreach_reverse(wchar d; s) 
     
    333331    assert(i == 5); 
    334332 
    335     s = "a\u1234\U00100456b"w[]
     333    s = "a\u1234\U00100456b"
    336334    i = 0; 
    337335    foreach_reverse(char d; s) 
     
    412410    assert(i == 5); 
    413411 
    414     s = "a\u1234\U00100456b"d[]
     412    s = "a\u1234\U00100456b"
    415413    i = 0; 
    416414    foreach_reverse(char d; s) 
     
    449447        else 
    450448        { 
    451        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     449            w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    452450            result = dg(cast(void *)&w); 
    453451            if (result) 
    454452                break; 
    455        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     453            w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    456454        } 
    457455        result = dg(cast(void *)&w); 
     
    484482    assert(i == 5); 
    485483 
    486     s = "a\u1234\U00100456b"d[]
     484    s = "a\u1234\U00100456b"
    487485    i = 0; 
    488486    foreach_reverse(wchar d; s) 
     
    567565    assert(i == 5); 
    568566 
    569     s = "a\u1234\U00100456b"c[]
     567    s = "a\u1234\U00100456b"
    570568    i = 0; 
    571569    foreach_reverse(k, dchar d; s) 
     
    633631    assert(i == 5); 
    634632 
    635     s = "a\u1234\U00100456b"w[]
     633    s = "a\u1234\U00100456b"
    636634    i = 0; 
    637635    foreach_reverse(k, dchar d; s) 
     
    683681            else 
    684682            { 
    685        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     683                w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    686684                result = dg(&i, cast(void *)&w); 
    687685                if (result) 
    688686                    break; 
    689        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     687                w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    690688            } 
    691689        } 
     
    721719    assert(i == 5); 
    722720 
    723     s = "a\u1234\U00100456b"c[]
     721    s = "a\u1234\U00100456b"
    724722    i = 0; 
    725723    foreach_reverse(k, wchar d; s) 
     
    804802    assert(i == 5); 
    805803 
    806     s = "a\u1234\U00100456b"w[]
     804    s = "a\u1234\U00100456b"
    807805    i = 0; 
    808806    foreach_reverse(k, char d; s) 
     
    884882    assert(i == 5); 
    885883 
    886     s = "a\u1234\U00100456b"d[]
     884    s = "a\u1234\U00100456b"
    887885    i = 0; 
    888886    foreach_reverse(k, char d; s) 
     
    921919        else 
    922920        { 
    923        w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     921            w = cast(wchar) ((((d - 0x10000) >> 10) & 0x3FF) + 0xD800); 
    924922            result = dg(&i, cast(void *)&w); 
    925923            if (result) 
    926924                break; 
    927        w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
     925            w = cast(wchar) (((d - 0x10000) & 0x3FF) + 0xDC00); 
    928926        } 
    929927        result = dg(&i, cast(void *)&w); 
     
    958956    assert(i == 5); 
    959957 
    960     s = "a\u1234\U00100456b"d[]
     958    s = "a\u1234\U00100456b"
    961959    i = 0; 
    962960    foreach_reverse(k, wchar d; s) 
  • trunk/tango/core/rt/compiler/gdc/rt/aaA.d

    r5609 r5652  
    3737 *  Modified by Sean Kelly <sean@f4.ca> for use with Tango. 
    3838 */ 
     39 
    3940module rt.compiler.gdc.rt.aaA; 
     41 
    4042private 
    4143{ 
     
    7375 * gcc will not, so we instead use a 'long'. 
    7476 */ 
    75 alias long ArrayRet_t; 
     77alias void[] ArrayRet_t; 
    7678 
    7779struct Array 
     
    114116size_t aligntsize(size_t tsize) 
    115117{ 
    116     // Is pointer alignment on the x64 4 bytes or 8? 
    117     return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     118    version (X86_64) 
     119        // Size of key needed to align value on 16 bytes 
     120        return (tsize + 15) & ~(15); 
     121    else 
     122        return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
    118123} 
    119124 
     
    261266    if (!aa.a) 
    262267        aa.a = new BB(); 
     268 
    263269    aa.a.keyti = keyti; 
    264270 
     
    272278 
    273279    auto key_hash = keyti.getHash(pkey); 
     280 
    274281    //printf("hash = %d\n", key_hash); 
     282 
    275283    i = key_hash % aa.a.b.length; 
    276284    auto pe = &aa.a.b[i]; 
     285 
    277286    while ((e = *pe) !is null) 
    278287    { 
     
    364373    if (aa.a) 
    365374    { 
    366  
    367375        //printf("_aaIn(), .length = %d, .ptr = %x\n", aa.a.length, cast(uint)aa.a.ptr); 
    368376        auto len = aa.a.b.length; 
     
    457465 */ 
    458466 
    459 Array _aaValues(AA aa, size_t keysize, size_t valuesize) 
     467ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) 
    460468in 
    461469{ 
     
    499507        assert(resi == a.length); 
    500508    } 
    501     return a
     509    return *cast(ArrayRet_t*)(&a)
    502510} 
    503511 
     
    586594                    _aaRehash_x(e); 
    587595            } 
     596            delete aa.b; 
    588597 
    589598            newb.nodes = aa.nodes; 
     
    592601 
    593602        *paa.a = newb; 
     603        _aaBalance(paa); 
    594604    } 
    595605    return *paa; 
    596606} 
    597607 
     608/******************************************** 
     609 * Balance an array. 
     610 */ 
     611 
     612void _aaBalance(AA* paa) 
     613{ 
     614    //printf("_aaBalance()\n"); 
     615    if (paa.a) 
     616    { 
     617        aaA*[16] tmp; 
     618        aaA*[] array = tmp; 
     619        auto aa = paa.a; 
     620        foreach (j, e; aa.b) 
     621        { 
     622            /* Temporarily store contents of bucket in array[] 
     623             */ 
     624            size_t k = 0; 
     625            void addToArray(aaA* e) 
     626            { 
     627                while (e) 
     628                {   addToArray(e.left); 
     629                    if (k == array.length) 
     630                        array.length = array.length * 2; 
     631                    array[k++] = e; 
     632                    e = e.right; 
     633                } 
     634            } 
     635            addToArray(e); 
     636            /* The contents of the bucket are now sorted into array[]. 
     637             * Rebuild the tree. 
     638             */ 
     639            void buildTree(aaA** p, size_t x1, size_t x2) 
     640            { 
     641                if (x1 >= x2) 
     642                    *p = null; 
     643                else 
     644                {   auto mid = (x1 + x2) >> 1; 
     645                    *p = array[mid]; 
     646                    buildTree(&(*p).left, x1, mid); 
     647                    buildTree(&(*p).right, mid + 1, x2); 
     648                } 
     649            } 
     650            auto p = &aa.b[j]; 
     651            buildTree(p, 0, k); 
     652        } 
     653    } 
     654} 
    598655 
    599656/******************************************** 
     
    601658 */ 
    602659 
    603 Array _aaKeys(AA aa, size_t keysize) 
     660ArrayRet_t _aaKeys(AA aa, size_t keysize) 
    604661{ 
    605662    byte[] res; 
     
    623680    } 
    624681 
    625     Array a; 
    626682    auto len = _aaLen(aa); 
    627683    if (!len) 
    628         return a
     684        return null
    629685    res = (cast(byte*) gc_malloc(len * keysize, 
    630686                                 !(aa.a.keyti.flags() & 1) ? BlkAttr.NO_SCAN : 0))[0 .. len * keysize]; 
     
    637693    assert(resi == len); 
    638694 
     695    Array a; 
    639696    a.length = len; 
    640697    a.ptr = res.ptr; 
    641     return a
     698    return *cast(ArrayRet_t*)(&a)
    642699} 
    643700 
     
    758815 * length pairs of key/value pairs. 
    759816 */ 
    760  
    761 extern (C) 
    762 BB* _d_assocarrayliteralTp(TypeInfo_AssociativeArray ti, size_t length, void *keys, void *values) 
    763 
    764     auto valuesize = ti.next.tsize();           // value size 
     817extern (C) BB* _d_assocarrayliteralTp(TypeInfo_AssociativeArray ti, void[] keys, void[] values) 
     818
     819    auto valueti = ti.next; 
     820    auto valuesize = valueti.tsize();           // value size 
    765821    auto keyti = ti.key; 
    766822    auto keysize = keyti.tsize();               // key size 
     823    auto length = keys.length; 
    767824    BB* result; 
    768825 
    769826    //printf("_d_assocarrayliteralT(keysize = %d, valuesize = %d, length = %d)\n", keysize, valuesize, length); 
    770827    //printf("tivalue = %.*s\n", ti.next.classinfo.name); 
     828    assert(length == values.length); 
    771829    if (length == 0 || valuesize == 0 || keysize == 0) 
    772830    { 
     
    775833    else 
    776834    { 
    777         //va_list q; 
    778         //va_start!(size_t)(q, length); 
    779         void * qkey = keys; 
    780         void * qval = values; 
    781  
    782835        result = new BB(); 
    783         result.keyti = keyti; 
     836 
    784837        size_t i; 
    785  
    786838        for (i = 0; i < prime_list.length - 1; i++) 
    787839        { 
     
    792844        result.b = new aaA*[len]; 
    793845 
    794         size_t keystacksize   = (keysize   + int.sizeof - 1) & ~(int.sizeof - 1); 
    795         size_t valuestacksize = (valuesize + int.sizeof - 1) & ~(int.sizeof - 1); 
    796  
    797846        size_t keytsize = aligntsize(keysize); 
    798847 
    799848        for (size_t j = 0; j < length; j++) 
    800         {   void* pkey = qkey; 
    801             //q += keystacksize; 
    802             qkey += keysize; 
    803             void* pvalue = qval; 
    804             //q += valuestacksize; 
    805             qval += valuesize; 
     849        {   auto pkey = keys.ptr + j * keysize; 
     850            auto pvalue = values.ptr + j * valuesize; 
    806851            aaA* e; 
    807852 
     
    836881            memcpy(cast(void *)(e + 1) + keytsize, pvalue, valuesize); 
    837882        } 
    838  
    839         //va_end(q); 
    840883    } 
    841884    return result; 
    842885} 
    843886 
    844  
     887/*********************************** 
     888 * Compare AA contents for equality. 
     889 * Returns: 
     890 *      1       equal 
     891 *      0       not equal 
     892 */ 
     893int _aaEqual(TypeInfo_AssociativeArray ti, AA e1, AA e2) 
     894
     895    //printf("_aaEqual()\n"); 
     896    //printf("keyti = %.*s\n", ti.key.classinfo.name); 
     897    //printf("valueti = %.*s\n", ti.next.classinfo.name); 
     898 
     899    if (e1.a is e2.a) 
     900        return 1; 
     901 
     902    size_t len = _aaLen(e1); 
     903    if (len != _aaLen(e2)) 
     904        return 0; 
     905 
     906    /* Algorithm: Visit each key/value pair in e1. If that key doesn't exist 
     907     * in e2, or if the value in e1 doesn't match the one in e2, the arrays 
     908     * are not equal, and exit early. 
     909     * After all pairs are checked, the arrays must be equal. 
     910     */ 
     911 
     912    auto keyti = ti.key; 
     913    auto valueti = ti.next; 
     914    auto keysize = aligntsize(keyti.tsize()); 
     915    auto len2 = e2.a.b.length; 
     916 
     917    int _aaKeys_x(aaA* e) 
     918    { 
     919        do 
     920        { 
     921            auto pkey = cast(void*)(e + 1); 
     922            auto pvalue = pkey + keysize; 
     923            //printf("key = %d, value = %g\n", *cast(int*)pkey, *cast(double*)pvalue); 
     924 
     925            // We have key/value for e1. See if they exist in e2 
     926 
     927            auto key_hash = keyti.getHash(pkey); 
     928            //printf("hash = %d\n", key_hash); 
     929            auto i = key_hash % len2; 
     930            auto f = e2.a.b[i]; 
     931            while (1) 
     932            { 
     933                //printf("f is %p\n", f); 
     934                if (f is null) 
     935                    return 0;                   // key not found, so AA's are not equal 
     936                if (key_hash == f.hash) 
     937                { 
     938                    //printf("hash equals\n"); 
     939                    auto c = keyti.compare(pkey, f + 1); 
     940                    if (c == 0) 
     941                    {   // Found key in e2. Compare values 
     942                        //printf("key equals\n"); 
     943                        auto pvalue2 = cast(void *)(f + 1) + keysize; 
     944                        if (valueti.equals(pvalue, pvalue2)) 
     945                        { 
     946                            //printf("value equals\n"); 
     947                            break; 
     948                        } 
     949                        else 
     950                            return 0;           // values don't match, so AA's are not equal 
     951                    } 
     952                    f = (c < 0) ? f.left : f.right; 
     953                } 
     954                else 
     955                    f = (key_hash < f.hash) ? f.left : f.right; 
     956            } 
     957 
     958            // Look at next entry in e1 
     959            if (e.left) 
     960            {   if (!e.right) 
     961                {   e = e.left; 
     962                    continue; 
     963                } 
     964                if (_aaKeys_x(e.left) == 0) 
     965                    return 0; 
     966            } 
     967            e = e.right; 
     968        } while (e !is null); 
     969        return 1;                       // this subtree matches 
     970    } 
     971 
     972    foreach (e; e1.a.b) 
     973    { 
     974        if (e) 
     975        {   if (_aaKeys_x(e) == 0) 
     976                return 0; 
     977        } 
     978    } 
     979 
     980    return 1;           // equal 
     981
     982 
  • trunk/tango/core/rt/compiler/gdc/rt/adi.d

    r5609 r5652  
    7575 */ 
    7676 
    77 extern (C) Array _adReverseChar(char[] a) 
     77extern (C) char[] _adReverseChar(char[] a) 
    7878{ 
    7979    bool hadErrors=false; 
     
    103103            if (stridelo>6) { // invalid UTF-8 0xFF 
    104104                stridelo=1; 
    105                 hadErrors=true;  
     105                hadErrors=true; 
    106106            } 
    107107 
     
    112112                stridehi++; 
    113113            } 
    114             if (lo >= hi){ 
     114            if (lo >= hi) 
     115            { 
    115116                if (lo>hi){ 
    116117                    hadErrors=true; 
     
    138139            memcpy(tmp.ptr, hi, stridehi); 
    139140            memcpy(tmplo.ptr, lo, stridelo); 
    140             memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); 
     141            memmove(lo + stridehi, lo + stridelo , cast(size_t)((hi - lo) - stridelo)); 
    141142            memcpy(lo, tmp.ptr, stridehi); 
    142             memcpy(hi + cast(int) stridehi - cast(int) stridelo, tmplo.ptr, stridelo); 
     143            memcpy(hi + stridehi - stridelo, tmplo.ptr, stridelo); 
    143144 
    144145            lo += stridehi; 
     
    148149    if (hadErrors) 
    149150        throw new Exception("invalid UTF-8 sequence",__FILE__,__LINE__); 
    150     return *cast(Array*)(&a)
     151    return a
    151152} 
    152153 
    153154unittest 
    154155{ 
    155     auto a = "abcd"c[]
     156    char[] a = "abcd"
    156157 
    157158    auto r = a.dup.reverse; 
     
    183184 */ 
    184185 
    185 extern (C) Array _adReverseWchar(wchar[] a) 
     186extern (C) wchar[] _adReverseWchar(wchar[] a) 
    186187{ 
    187188    bool hadErrors=false; 
     
    237238             */ 
    238239            memcpy(tmp.ptr, hi, stridehi * wchar.sizeof); 
    239             memcpy(hi + cast(int) stridehi - cast(int) stridelo, lo, stridelo * wchar.sizeof); 
     240            memcpy(hi + stridehi - stridelo, lo, stridelo * wchar.sizeof); 
    240241            memmove(lo + stridehi, lo + stridelo , (hi - (lo + stridelo)) * wchar.sizeof); 
    241242            memcpy(lo, tmp.ptr, stridehi * wchar.sizeof); 
    242243 
    243244            lo += stridehi; 
    244             hi = hi - 1 + (cast(int) stridehi - cast(int) stridelo); 
     245            hi = hi - 1 + (stridehi - stridelo); 
    245246        } 
    246247    } 
    247248    if (hadErrors) 
    248249        throw new Exception("invalid UTF-16 sequence",__FILE__,__LINE__); 
    249     return *cast(Array*)(&a)
     250    return a
    250251} 
    251252 
    252253unittest 
    253254{ 
    254     alias wchar[] wstring; 
    255     wstring a = "abcd"; 
    256     wstring r; 
     255    wchar[] a = "abcd"; 
     256    wchar[] r; 
    257257 
    258258    r = a.dup.reverse; 
     
    549549/*************************************** 
    550550 * Support for array equality test. 
     551 * Returns: 
     552 *      1       equal 
     553 *      0       not equal 
    551554 */ 
    552555 
    553556extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) 
    554557{ 
    555     /+ 
    556      + TODO: Re-enable once the correct TypeInfo is passed: 
    557      +       http://d.puremagic.com/issues/show_bug.cgi?id=2161 
    558      + 
    559     debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
    560  
    561     if (a1.length != a2.length) 
    562         return 0; // not equal 
    563     if (a1.ptr == a2.ptr) 
    564         return 1; // equal 
    565  
    566     // We should really have a ti.isPOD() check for this 
    567     if (ti.tsize() != 1) 
    568         return ti.equals(&a1, &a2); 
    569     return memcmp(a1.ptr, a2.ptr, a1.length) == 0; 
    570     +/ 
    571558    debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
    572559    if (a1.length != a2.length) 
     
    588575} 
    589576 
     577extern (C) int _adEq2(Array a1, Array a2, TypeInfo ti) 
     578{ 
     579    debug(adi) printf("_adEq2(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
     580    if (a1.length != a2.length) 
     581        return 0;               // not equal 
     582    if (!ti.equals(&a1, &a2)) 
     583        return 0; 
     584    return 1; 
     585} 
     586 
    590587unittest 
    591588{ 
     
    607604extern (C) int _adCmp(Array a1, Array a2, TypeInfo ti) 
    608605{ 
    609     /+ 
    610      + TODO: Re-enable once the correct TypeInfo is passed: 
    611      +       http://d.puremagic.com/issues/show_bug.cgi?id=2161 
    612      + 
    613     debug(adi) printf("adCmp()\n"); 
    614  
    615     if (a1.ptr == a2.ptr && 
    616         a1.length == a2.length) 
    617         return 0; 
    618  
    619     auto len = a1.length; 
    620     if (a2.length < len) 
    621         len = a2.length; 
    622  
    623     // We should really have a ti.isPOD() check for this 
    624     if (ti.tsize() != 1) 
    625         return ti.compare(&a1, &a2); 
    626     auto c = memcmp(a1.ptr, a2.ptr, len); 
    627     if (c) 
    628         return c; 
    629     if (a1.length == a2.length) 
    630         return 0; 
    631     return a1.length > a2.length ? 1 : -1; 
    632     +/ 
    633606    debug(adi) printf("adCmp()\n"); 
    634607    auto len = a1.length; 
     
    657630        return 0; 
    658631    return (a1.length > a2.length) ? 1 : -1; 
     632} 
     633 
     634extern (C) int _adCmp2(Array a1, Array a2, TypeInfo ti) 
     635{ 
     636    debug(adi) printf("_adCmp2(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); 
     637    return ti.compare(&a1, &a2); 
    659638} 
    660639 
  • trunk/tango/core/rt/compiler/gdc/rt/arraycat.d

    r5579 r5652  
    5555    { 
    5656        throw new Exception("overlapping array copy"); 
    57 
     57   
    5858    return to; 
    5959} 
  • trunk/tango/core/rt/compiler/gdc/rt/lifetime.d

    r5609 r5652  
    3030private 
    3131{ 
    32     import tango.stdc.stdlib
    33     import tango.stdc.string
     32    import tango.stdc.stdlib : free, malloc
     33    import tango.stdc.string : memcpy, memset, memcmp
    3434    import tango.stdc.stdarg; 
    3535    debug(PRINTF) import tango.stdc.stdio; 
     36     
     37    alias void[] array_t; 
    3638} 
    3739 
     
    9597         * to zero. 
    9698     */ 
    97         p = tango.stdc.stdlib.malloc(ci.init.length); 
     99        p = malloc(ci.init.length); 
    98100        if (!p) 
    99101            onOutOfMemoryError(); 
     
    186188} 
    187189 
    188  
    189190/** 
    190191 * Allocate a new array of length elements. 
     
    192193 * (For when the array is initialized to 0) 
    193194 */ 
    194 extern (C) Array _d_newarrayT(TypeInfo ti, size_t length) 
    195 
    196     Array result; 
     195extern(C) array_t _d_newarrayT(TypeInfo ti, size_t length) 
     196
     197    void* p; 
     198    array_t result; 
    197199    auto size = ti.next.tsize();                // array element size 
    198200 
    199201    debug(PRINTF) printf("_d_newarrayT(length = x%x, size = %d)\n", length, size); 
    200202    if (length == 0 || size == 0) 
    201         {} 
     203        result = array_t.init; 
    202204    else 
    203     { 
    204         result.length = length; 
    205         /*version (D_InlineAsm_X86) 
     205    {         
     206        version (GNU) 
     207        { 
     208            // required to output the label; 
     209            static char x = 0; 
     210            if (x) 
     211                goto Loverflow; 
     212        } 
     213 
     214        version (D_InlineAsm_X86) 
    206215        { 
    207216            asm 
     
    213222            } 
    214223        } 
    215         else*/ 
     224        else version (D_InlineAsm_X86_64) 
     225            asm 
     226            { 
     227                mov     RAX,size        ; 
     228                mul     RAX,length      ; 
     229                mov     size,RAX        ; 
     230                jc      Loverflow       ; 
     231            } 
     232        else 
    216233            size *= length; 
     234 
    217235        PointerMap pm; 
    218         version (D_HavePointerMap) { 
    219             pm = ti.next.pointermap(); 
    220         } 
    221         result.data = cast(byte*) gc_malloc(size + 1, 
    222                 !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, 
    223                 pm); 
    224         memset(result.data, 0, size); 
     236        version (D_HavePointerMap)  pm = ti.next.pointermap(); 
     237 
     238        p = gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
     239        debug(PRINTF) printf(" p = %p\n", p); 
     240        memset(p, 0, size); 
     241        result = cast(array_t)p[0..length]; 
    225242    } 
    226243    return result; 
     
    234251 * For when the array has a non-zero initializer. 
    235252 */ 
    236 extern (C) Array _d_newarrayiT(TypeInfo ti, size_t length) 
    237 { 
    238     Array result; 
    239     auto size = ti.next.tsize(); // array element size 
     253extern(C) array_t _d_newarrayiT(TypeInfo ti, size_t length) 
     254{ 
     255    array_t result; 
     256    auto size = ti.next.tsize();                // array element size 
    240257 
    241258    debug(PRINTF) printf("_d_newarrayiT(length = %d, size = %d)\n", length, size); 
    242259 
    243260    if (length == 0 || size == 0) 
    244         {} 
     261        result = array_t.init; 
    245262    else 
    246263    { 
    247264        auto initializer = ti.next.init(); 
    248265        auto isize = initializer.length; 
    249         auto q = initializer.ptr; 
    250         /*version (D_InlineAsm_X86) 
     266        auto q = initializer.ptr;         
     267         
     268        version (GNU) 
     269        { 
     270            // required to output the label; 
     271            static char x = 0; 
     272            if (x) 
     273                goto Loverflow; 
     274        } 
     275 
     276        version (D_InlineAsm_X86) 
    251277        { 
    252278            asm 
     
    258284            } 
    259285        } 
    260         else*/ 
     286        else version (D_InlineAsm_X86_64) 
     287            asm 
     288            { 
     289                mov     RAX,size        ; 
     290                mul     RAX,length      ; 
     291                mov     size,RAX        ; 
     292                jc      Loverflow       ; 
     293            } 
     294        else 
    261295            size *= length; 
     296 
    262297        PointerMap pm; 
    263298        version (D_HavePointerMap) { 
    264299            pm = ti.next.pointermap(); 
    265300        } 
    266         auto p = gc_malloc(size + 1, 
    267                 !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, 
    268                 pm); 
     301        auto p = gc_malloc(size + 1, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
    269302        debug(PRINTF) printf(" p = %p\n", p); 
    270303        if (isize == 1) 
     
    286319            } 
    287320        } 
    288         result.length = length; 
    289         result.data = cast(byte*) p; 
     321        result = cast(array_t)p[0..length]; 
    290322    } 
    291323    return result; 
     
    323355            { 
    324356                p = gc_malloc(dim * (void[]).sizeof + 1)[0 .. dim]; 
    325                 for (int i = 0; i < dim; i++) 
     357                for (size_t i = 0; i < dim; i++) 
    326358                { 
    327359                    (cast(void[]*)p.ptr)[i] = foo(ti.next, pdim + 1, ndims - 1); 
     
    602634                        pm = ti.next.pointermap(); 
    603635                    } 
    604                     newdata = cast(byte *)gc_malloc(newsize + 1, info.attr, pm); 
     636                    newdata = cast(byte *)gc_malloc(newsize + 1, 
     637                            !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
     638 
    605639                    newdata[0 .. size] = p.data[0 .. size]; 
    606640                } 
     
    719753                        pm = ti.next.pointermap(); 
    720754                    } 
    721                     newdata = cast(byte *)gc_malloc(newsize + 1, info.attr, pm); 
     755                     
     756                    newdata = cast(byte *)gc_malloc(newsize + 1, 
     757                            !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
     758                     
     759                     
    722760                    newdata[0 .. size] = p.data[0 .. size]; 
    723761                L1: ; 
     
    767805} 
    768806 
     807/************************************** 
     808 * Extend an array by n elements. 
     809 * Caller must initialize that element. 
     810 */ 
     811extern (C) byte[] _d_arrayappendcTp(TypeInfo ti, inout byte[] x, size_t n) 
     812{ 
     813    auto sizeelem = ti.next.tsize();            // array element size 
     814    auto info = gc_query(x.ptr); 
     815    auto length = x.length; 
     816    auto newlength = length + n; 
     817    auto newsize = newlength * sizeelem; 
     818 
     819    assert(info.size == 0 || length * sizeelem <= info.size); 
     820 
     821    //printf("_d_arrayappendcTp(sizeelem = %d, ptr = %p, length = %d, cap = %d)\n", sizeelem, x.ptr, x.length, cap); 
     822 
     823    if (newsize >= info.size) 
     824    {   byte* newdata; 
     825 
     826        if (info.size >= PAGESIZE) 
     827        {   // Try to extend in-place 
     828            auto u = gc_extend(x.ptr, (newsize + 1) - info.size, (newsize + 1) - info.size); 
     829            if (u) 
     830            { 
     831                goto L1; 
     832            } 
     833        } 
     834 
     835        PointerMap pm; 
     836        version (D_HavePointerMap) { 
     837            pm = ti.next.pointermap(); 
     838        } 
     839 
     840        uint attr = !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0; 
     841        newdata = cast(byte *) gc_malloc(newCapacity(newlength, sizeelem) + 1, attr, pm); 
     842 
     843        memcpy(newdata, x.ptr, length * sizeelem); 
     844 
     845        (cast(void **)(&x))[1] = newdata; 
     846    } 
     847 
     848  L1: 
     849    *cast(size_t *)&x = newlength; 
     850    assert((cast(size_t)x.ptr & 15) == 0); 
     851    assert(gc_query(x.ptr).size > x.length * sizeelem); 
     852    return x; 
     853} 
    769854 
    770855/** 
     
    791876            } 
    792877        } 
    793         uint attr = info.attr; 
    794         // If this is the first allocation, set the NO_SCAN attribute appropriately 
    795         if (info.base is null && ti.next.flags() == 0) 
    796             attr = BlkAttr.NO_SCAN; 
    797878        PointerMap pm; 
    798879        version (D_HavePointerMap) { 
    799880            pm = ti.next.pointermap(); 
    800881        } 
    801         newdata = cast(byte *)gc_malloc(newCapacity(newlength, sizeelem) + 1, 
    802                 attr, pm); 
     882 
     883        uint attr = !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0; 
     884        newdata = cast(byte *)gc_malloc(newCapacity(newlength, sizeelem) + 1, attr, pm); 
     885 
    803886        memcpy(newdata, px.data, length * sizeelem); 
    804887        px.data = newdata; 
     
    847930            const size_t a=100; // allocate at most a% of the requested size as extra space (rounding will change this) 
    848931            const size_t minBits=1; // minimum bit size 
    849              
     932 
    850933 
    851934            static size_t log2plusB(size_t c) 
     
    870953} 
    871954 
    872  
    873 /** 
    874  * 
    875  */ 
    876 extern (C) byte[] _d_arrayappendcTp(TypeInfo ti, ref byte[] x, void *argp) 
    877 
    878     auto sizeelem = ti.next.tsize();            // array element size 
     955/** 
     956 * Append dchar to char[] 
     957 */ 
     958extern (C) char[] _d_arrayappendcd(ref char[] x, dchar c) 
     959
     960    const sizeelem = c.sizeof;            // array element size 
    879961    auto info = gc_query(x.ptr); 
    880962    auto length = x.length; 
    881     auto newlength = length + 1; 
     963 
     964    // c could encode into from 1 to 4 characters 
     965    int nchars; 
     966    if (c <= 0x7F) 
     967        nchars = 1; 
     968    else if (c <= 0x7FF) 
     969        nchars = 2; 
     970    else if (c <= 0xFFFF) 
     971        nchars = 3; 
     972    else if (c <= 0x10FFFF) 
     973        nchars = 4; 
     974    else 
     975    assert(0);  // invalid utf character - should we throw an exception instead? 
     976 
     977    auto newlength = length + nchars; 
    882978    auto newsize = newlength * sizeelem; 
    883979 
    884980    assert(info.size == 0 || length * sizeelem <= info.size); 
    885981 
    886     debug(PRINTF) printf("_d_arrayappendcTp(sizeelem = %d, ptr = %p, length = %d, cap = %d)\n", sizeelem, x.ptr, x.length, info.size); 
     982    debug(PRINTF) printf("_d_arrayappendcd(sizeelem = %d, ptr = %p, length = %d, cap = %d)\n", sizeelem, x.ptr, x.length, info.size); 
    887983 
    888984    if (info.size <= newsize || info.base != x.ptr) 
     
    897993            } 
    898994        } 
    899         debug(PRINTF) printf("_d_arrayappendcTp(length = %d, newlength = %d, cap = %d)\n", length, newlength, info.size); 
     995        debug(PRINTF) printf("_d_arrayappendcd(length = %d, newlength = %d, cap = %d)\n", length, newlength, info.size); 
    900996        auto newcap = newCapacity(newlength, sizeelem); 
    901997        assert(newcap >= newlength * sizeelem); 
    902         uint attr = info.attr; 
    903         // If this is the first allocation, set the NO_SCAN attribute appropriately 
    904         if (info.base is null && ti.next.flags() == 0) 
    905             attr = BlkAttr.NO_SCAN; 
    906         PointerMap pm; 
    907         version (D_HavePointerMap) { 
    908             pm = ti.next.pointermap(); 
    909         } 
    910         newdata = cast(byte *)gc_malloc(newcap + 1, attr, pm); 
     998        newdata = cast(byte *)gc_malloc(newcap + 1, BlkAttr.NO_SCAN); 
    911999        memcpy(newdata, x.ptr, length * sizeelem); 
    9121000        (cast(void**)(&x))[1] = newdata; 
     
    9141002  L1: 
    9151003    *cast(size_t *)&x = newlength; 
    916     x.ptr[length * sizeelem .. newsize] = (cast(byte*)argp)[0 .. sizeelem]; 
     1004    char* ptr = &x.ptr[length]; 
     1005 
     1006    if (c <= 0x7F) 
     1007    { 
     1008        ptr[0] = cast(char) c; 
     1009    } 
     1010    else if (c <= 0x7FF) 
     1011    { 
     1012        ptr[0] = cast(char)(0xC0 | (c >> 6)); 
     1013        ptr[1] = cast(char)(0x80 | (c & 0x3F)); 
     1014    } 
     1015    else if (c <= 0xFFFF) 
     1016    { 
     1017        ptr[0] = cast(char)(0xE0 | (c >> 12)); 
     1018        ptr[1] = cast(char)(0x80 | ((c >> 6) & 0x3F)); 
     1019        ptr[2] = cast(char)(0x80 | (c & 0x3F)); 
     1020    } 
     1021    else if (c <= 0x10FFFF) 
     1022    { 
     1023        ptr[0] = cast(char)(0xF0 | (c >> 18)); 
     1024        ptr[1] = cast(char)(0x80 | ((c >> 12) & 0x3F)); 
     1025        ptr[2] = cast(char)(0x80 | ((c >> 6) & 0x3F)); 
     1026        ptr[3] = cast(char)(0x80 | (c & 0x3F)); 
     1027    } 
     1028    else 
     1029    assert(0); 
     1030 
    9171031    assert((cast(size_t)x.ptr & 15) == 0); 
    9181032    assert(gc_sizeOf(x.ptr) > x.length * sizeelem); 
    9191033    return x; 
    9201034} 
     1035 
     1036 
     1037/** 
     1038 * Append dchar to wchar[] 
     1039 */ 
     1040extern (C) wchar[] _d_arrayappendwd(ref wchar[] x, dchar c) 
     1041{ 
     1042    const sizeelem = c.sizeof;            // array element size 
     1043    auto info = gc_query(x.ptr); 
     1044    auto length = x.length; 
     1045 
     1046    // c could encode into from 1 to 2 w characters 
     1047    int nchars; 
     1048    if (c <= 0xFFFF) 
     1049        nchars = 1; 
     1050    else 
     1051        nchars = 2; 
     1052 
     1053    auto newlength = length + nchars; 
     1054    auto newsize = newlength * sizeelem; 
     1055 
     1056    assert(info.size == 0 || length * sizeelem <= info.size); 
     1057 
     1058    debug(PRINTF) printf("_d_arrayappendwd(sizeelem = %d, ptr = %p, length = %d, cap = %d)\n", sizeelem, x.ptr, x.length, info.size); 
     1059 
     1060    if (info.size <= newsize || info.base != x.ptr) 
     1061    {   byte* newdata; 
     1062 
     1063        if (info.size >= PAGESIZE && info.base == x.ptr) 
     1064        {   // Try to extend in-place 
     1065            auto u = gc_extend(x.ptr, (newsize + 1) - info.size, (newsize + 1) - info.size); 
     1066            if (u) 
     1067            { 
     1068                goto L1; 
     1069            } 
     1070        } 
     1071        debug(PRINTF) printf("_d_arrayappendwd(length = %d, newlength = %d, cap = %d)\n", length, newlength, info.size); 
     1072        auto newcap = newCapacity(newlength, sizeelem); 
     1073        assert(newcap >= newlength * sizeelem); 
     1074        newdata = cast(byte *)gc_malloc(newcap + 1, BlkAttr.NO_SCAN); 
     1075        memcpy(newdata, x.ptr, length * sizeelem); 
     1076        (cast(void**)(&x))[1] = newdata; 
     1077    } 
     1078  L1: 
     1079    *cast(size_t *)&x = newlength; 
     1080    wchar* ptr = &x.ptr[length]; 
     1081 
     1082    if (c <= 0xFFFF) 
     1083    { 
     1084        ptr[0] = cast(wchar) c; 
     1085    } 
     1086    else 
     1087    { 
     1088        ptr[0] = cast(wchar) ((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); 
     1089        ptr[1] = cast(wchar) (((c - 0x10000) & 0x3FF) + 0xDC00); 
     1090    } 
     1091 
     1092    assert((cast(size_t)x.ptr & 15) == 0); 
     1093    assert(gc_sizeOf(x.ptr) > x.length * sizeelem); 
     1094    return x; 
     1095} 
     1096 
    9211097 
    9221098 
     
    10241200 
    10251201 
    1026 /** 
    1027  * 
    1028  */ 
    1029 version (GNU) { } else 
    1030 extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...) 
     1202extern (C) void* _d_arrayliteralTp(TypeInfo ti, size_t length) 
    10311203{ 
    10321204    auto sizeelem = ti.next.tsize();            // array element size 
    10331205    void* result; 
    10341206 
    1035     debug(PRINTF) printf("_d_arrayliteralT(sizeelem = %d, length = %d)\n", sizeelem, length); 
     1207    //printf("_d_arrayliteralTX(sizeelem = %d, length = %d)\n", sizeelem, length); 
    10361208    if (length == 0 || sizeelem == 0) 
    10371209        result = null; 
     
    10421214            pm = ti.next.pointermap(); 
    10431215        } 
    1044         result = gc_malloc(length * sizeelem, 
    1045                 !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, 
    1046                 pm); 
    1047  
    1048         va_list q; 
    1049         va_start!(size_t)(q, length); 
    1050  
    1051         size_t stacksize = (sizeelem + int.sizeof - 1) & ~(int.sizeof - 1); 
    1052  
    1053         if (stacksize == sizeelem) 
    1054         { 
    1055             memcpy(result, q, length * sizeelem); 
    1056         } 
    1057         else 
    1058         { 
    1059             for (size_t i = 0; i < length; i++) 
    1060             { 
    1061                 memcpy(result + i * sizeelem, q, sizeelem); 
    1062                 q += stacksize; 
    1063             } 
    1064         } 
    1065  
    1066         va_end(q); 
     1216        result = gc_malloc(length * sizeelem, !(ti.next.flags() & 1) ? BlkAttr.NO_SCAN : 0, pm); 
    10671217    } 
    10681218    return result; 
    10691219} 
    1070  
    10711220 
    10721221/** 
  • trunk/tango/core/rt/compiler/gdc/rt/switch_.d

    r5579 r5652  
    102102body 
    103103{ 
    104 //printf("body _d_switch_string(%.*s)\n", ca); 
     104    //printf("body _d_switch_string(%.*s)\n", ca); 
    105105    int low; 
    106106    int high; 
     
    180180 
    181181int _d_switch_ustring(wchar[][] table, wchar[] ca) 
    182     in 
    183     { 
    184         //printf("in _d_switch_ustring()\n"); 
    185         assert(table.length >= 0); 
    186         assert(ca.length >= 0); 
    187  
    188         // Make sure table[] is sorted correctly 
    189         int j; 
    190  
    191         for (j = 1; j < table.length; j++) 
    192         { 
    193             int len1 = table[j - 1].length; 
    194             int len2 = table[j].length; 
    195  
    196             assert(len1 <= len2); 
    197             if (len1 == len2) 
    198             { 
    199                 int c; 
    200  
    201                 c = memcmp(table[j - 1].ptr, table[j].ptr, len1 * wchar.sizeof); 
    202                 assert(c < 0);  // c==0 means a duplicate 
    203             } 
    204         } 
    205     } 
    206     out (result) 
    207     { 
    208         int i; 
    209         int c; 
    210  
    211         //printf("out _d_switch_string()\n"); 
    212         if (result == -1) 
    213         { 
    214             // Not found 
    215             for (i = 0; i < table.length; i++) 
    216             { 
    217                 if (table[i].length == ca.length) 
    218                 {   c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); 
    219                     assert(c != 0); 
    220                 } 
    221             } 
     182in 
     183
     184    //printf("in _d_switch_ustring()\n"); 
     185    assert(table.length >= 0); 
     186    assert(ca.length >= 0); 
     187 
     188    // Make sure table[] is sorted correctly 
     189    int j; 
     190 
     191    for (j = 1; j < table.length; j++) 
     192    { 
     193        int len1 = table[j - 1].length; 
     194        int len2 = table[j].length; 
     195 
     196        assert(len1 <= len2); 
     197        if (len1 == len2) 
     198        { 
     199            int c; 
     200 
     201            c = memcmp(table[j - 1].ptr, table[j].ptr, len1 * wchar.sizeof); 
     202            assert(c < 0);  // c==0 means a duplicate 
     203        } 
     204    } 
     205
     206out (result) 
     207
     208    int i; 
     209    int c; 
     210 
     211    //printf("out _d_switch_string()\n"); 
     212    if (result == -1) 
     213    { 
     214        // Not found 
     215        for (i = 0; i < table.length; i++) 
     216        { 
     217            if (table[i].length == ca.length) 
     218            {   c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); 
     219                assert(c != 0); 
     220            } 
     221        } 
     222    } 
     223    else 
     224    { 
     225        assert(0 <= result && result < table.length); 
     226        for (i = 0; 1; i++) 
     227        { 
     228            assert(i < table.length); 
     229            if (table[i].length == ca.length) 
     230            { 
     231                c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); 
     232                if (c == 0) 
     233                { 
     234                    assert(i == result); 
     235                    break; 
     236                } 
     237            } 
     238        } 
     239    } 
     240
     241body 
     242
     243    //printf("body _d_switch_ustring()\n"); 
     244    int low; 
     245    int high; 
     246    int mid; 
     247    int c; 
     248    wchar[] pca; 
     249 
     250    low = 0; 
     251    high = table.length; 
     252 
     253    /* 
     254    // Print table 
     255    wprintf("ca[] = '%.*s'\n", ca); 
     256    for (mid = 0; mid < high; mid++) 
     257    { 
     258    pca = table[mid]; 
     259    wprintf("table[%d] = %d, '%.*s'\n", mid, pca.length, pca); 
     260    } 
     261     */ 
     262 
     263    // Do binary search 
     264    while (low < high) 
     265    { 
     266        mid = (low + high) >> 1; 
     267        pca = table[mid]; 
     268        c = ca.length - pca.length; 
     269        if (c == 0) 
     270        { 
     271            c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof); 
     272            if (c == 0) 
     273            {   //printf("found %d\n", mid); 
     274                return mid; 
     275            } 
     276        } 
     277        if (c < 0) 
     278        { 
     279            high = mid; 
    222280        } 
    223281        else 
    224282        { 
    225             assert(0 <= result && result < table.length); 
    226             for (i = 0; 1; i++) 
    227             { 
    228                 assert(i < table.length); 
    229                 if (table[i].length == ca.length) 
    230                 { 
    231                     c = memcmp(table[i].ptr, ca.ptr, ca.length * wchar.sizeof); 
    232                     if (c == 0) 
    233                     { 
    234                         assert(i == result); 
    235                         break; 
    236                     } 
    237                 } 
    238             } 
    239         } 
    240     } 
    241     body 
    242     { 
    243         //printf("body _d_switch_ustring()\n"); 
    244         int low; 
    245         int high; 
    246         int mid; 
    247         int c; 
    248         wchar[] pca; 
    249  
    250         low = 0; 
    251         high = table.length; 
    252  
    253     /* 
    254         // Print table 
    255         wprintf("ca[] = '%.*s'\n", ca); 
    256         for (mid = 0; mid < high; mid++) 
    257         { 
    258             pca = table[mid]; 
    259             wprintf("table[%d] = %d, '%.*s'\n", mid, pca.length, pca); 
    260         } 
    261     */ 
    262  
    263         // Do binary search 
    264         while (low < high) 
    265         { 
    266             mid = (low + high) >> 1; 
    267             pca = table[mid]; 
    268             c = ca.length - pca.length; 
    269             if (c == 0) 
    270             { 
    271                 c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof); 
    272                 if (c == 0) 
    273                 {   //printf("found %d\n", mid); 
    274                     return mid; 
    275                 } 
    276             } 
    277             if (c < 0) 
    278             { 
    279                 high = mid; 
    280             } 
    281             else 
    282             { 
    283                 low = mid + 1; 
    284             } 
    285         } 
    286         //printf("not found\n"); 
    287         return -1;              // not found 
    288     } 
     283            low = mid + 1; 
     284        } 
     285    } 
     286    //printf("not found\n"); 
     287    return -1;              // not found 
     288
    289289 
    290290 
     
    293293    switch (cast(wchar []) "c") 
    294294    { 
    295         case "coo": 
    296         default: 
    297             break; 
     295        case "coo": 
     296        default: 
     297            break; 
    298298    } 
    299299} 
  • trunk/tango/core/rt/compiler/gdc/std/intrinsic.d

    r5594 r5652  
    1  
    2 // Written in the D programming language 
    3 // written by Walter Bright 
    4 // www.digitalmars.com 
    5 // Placed into the public domain 
    6  
    7 /* NOTE: This file has been patched from the original DMD distribution to 
    8    work with the GDC compiler. 
    9  
    10    Modified by David Friedman, May 2006 
    11 */ 
    12  
    13 /** These functions are built-in intrinsics to the compiler. 
     1/** 
     2 * These functions are built-in intrinsics to the compiler. 
    143 * 
    15         Intrinsic functions are functions built in to the compiler, 
    16         usually to take advantage of specific CPU features that 
    17         are inefficient to handle via external functions. 
    18         The compiler's optimizer and code generator are fully 
    19         integrated in with intrinsic functions, bringing to bear 
    20         their full power on them. 
    21         This can result in some surprising speedups. 
     4 * Intrinsic functions are functions built in to the compiler, usually to take 
     5 * advantage of specific CPU features that are inefficient to handle via 
     6 * external functions.  The compiler's optimizer and code generator are fully 
     7 * integrated in with intrinsic functions, bringing to bear their full power on 
     8 * them. This can result in some surprising speedups. 
     9 * 
     10 * Note that this module is only present in Tango because the module name is 
     11 * hardcoded into DMD, see http://d.puremagic.com/issues/show_bug.cgi?id=178 
     12 * To correctly use this functionality in Tango, import tango.core.BitManip. 
    2213 * 
    2314 * Copyright: Public Domain 
    2415 * License:   Public Domain 
    2516 * Authors:   Walter Bright 
    26  * Macros: 
    27  *      WIKI=Phobos/StdIntrinsic 
    2817 */ 
     18module std.intrinsic; 
    2919 
    30 module std.intrinsic; 
    3120 
    3221/** 
     
    3423 * for the first set bit. 
    3524 * Returns: 
    36  *      The bit number of the first bit set. 
    37  *      The return value is undefined if v is zero. 
     25 * The bit number of the first bit set. 
     26 * The return value is undefined if v is zero. 
    3827 */ 
    39 version (GNU) 
    40     int bsf(uint v) 
    41     { 
    42         uint m = 1; 
    43         uint i; 
    44         for (i = 0; i < 32; i++,m<<=1) { 
    45             if (v&m) 
    46                 return i; 
    47         } 
    48         return i; // supposed to be undefined 
    49     } 
    50 else 
    51     int bsf(uint v); 
     28int bsf( size_t v ); 
     29 
    5230 
    5331/** 
     
    5634 * for the first set bit. 
    5735 * Returns: 
    58  *      The bit number of the first bit set. 
    59  *      The return value is undefined if v is zero. 
     36 * The bit number of the first bit set. 
     37 * The return value is undefined if v is zero. 
    6038 * Example: 
    6139 * --- 
    62  * import std.stdio; 
    6340 * import std.intrinsic; 
    6441 * 
     
    7047 *     v = 0x21; 
    7148 *     x = bsf(v); 
    72  *     writefln("bsf(x%x) = %d", v, x); 
     49 *     printf("bsf(x%x) = %d\n", v, x); 
    7350 *     x = bsr(v); 
    74  *     writefln("bsr(x%x) = %d", v, x); 
     51 *     printf("bsr(x%x) = %d\n", v, x); 
    7552 *     return 0; 
    7653 * } 
     
    8057 *  bsr(x21) = 5 
    8158 */ 
    82 version (GNU) 
    83 int bsr(size_t v) 
    84 
    85     size_t m = 0x80000000; 
    86     size_t i; 
    87     for (i = 32; i ; i--,m>>>=1) { 
    88         if (v&m) 
    89             return i-1; 
    90     } 
    91     return i; // supposed to be undefined 
    92 
    93 else 
    94     int bsr(size_t v); 
     59int bsr( size_t v ); 
     60 
    9561 
    9662/** 
    9763 * Tests the bit. 
    9864 */ 
    99 version (GNU) 
    100 int bt(in size_t* p, size_t bitnum) 
    101 
    102     return (p[bitnum / (size_t.sizeof*8)] & (1<<(bitnum & ((size_t.sizeof*8)-1)))) ? -1 : 0 ; 
    103 
    104 else 
    105     int bt(in size_t* p, size_t bitnum); 
     65int bt( size_t* p, size_t bitnum ); 
     66 
    10667 
    10768/** 
    10869 * Tests and complements the bit. 
    10970 */ 
    110 version (GNU) 
    111 int btc(size_t* p, size_t bitnum) 
    112 
    113     size_t*  q = p + (bitnum / (size_t.sizeof*8)); 
    114     size_t mask = 1 << (bitnum & ((size_t.sizeof*8) - 1)); 
    115     int result = *q & mask; 
    116     *q ^= mask; 
    117     return result ? -1 : 0; 
    118 
    119 else 
    120 int btc(size_t* p, size_t bitnum); 
     71int btc( size_t* p, size_t bitnum ); 
     72 
    12173 
    12274/** 
    12375 * Tests and resets (sets to 0) the bit. 
    12476 */ 
    125 version (GNU) 
    126 int btr(size_t* p, size_t bitnum) 
    127 
    128     size_t*  q = p + (bitnum / (size_t.sizeof*8)); 
    129     size_t mask = 1 << (bitnum & ((size_t.sizeof*8) - 1)); 
    130     int result = *q & mask; 
    131     *q &= ~mask; 
    132     return result ? -1 : 0; 
    133 
    134 else 
    135     int btr(size_t* p, size_t bitnum); 
     77int btr( size_t* p, size_t bitnum ); 
     78 
    13679 
    13780/** 
     
    14588--- 
    14689 * Returns: 
    147  *      A non-zero value if the bit was set, and a zero 
    148  *      if it was clear. 
     90 *     A non-zero value if the bit was set, and a zero 
     91 * if it was clear. 
    14992 * 
    15093 * Example: 
    15194 * --- 
    152 import std.stdio; 
    15395import std.intrinsic; 
    15496 
    15597int main() 
    15698{ 
    157     size_t[2] array
     99    size_t array[2]
    158100 
    159101    array[0] = 2; 
    160102    array[1] = 0x100; 
    161103 
    162     writefln("btc(array, 35) = %d", <b>btc</b>(array, 35)); 
    163     writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); 
     104    printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); 
     105    printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); 
    164106 
    165     writefln("btc(array, 35) = %d", <b>btc</b>(array, 35)); 
    166     writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); 
     107    printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35)); 
     108    printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); 
    167109 
    168     writefln("bts(array, 35) = %d", <b>bts</b>(array, 35)); 
    169     writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); 
     110    printf("bts(array, 35) = %d\n", <b>bts</b>(array, 35)); 
     111    printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); 
    170112 
    171     writefln("btr(array, 35) = %d", <b>btr</b>(array, 35)); 
    172     writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); 
     113    printf("btr(array, 35) = %d\n", <b>btr</b>(array, 35)); 
     114    printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); 
    173115 
    174     writefln("bt(array, 1) = %d", <b>bt</b>(array, 1)); 
    175     writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); 
     116    printf("bt(array, 1) = %d\n", <b>bt</b>(array, 1)); 
     117    printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]); 
    176118 
    177119    return 0; 
     
    192134</pre> 
    193135 */ 
    194 version (GNU) 
    195 int bts(size_t* p, size_t bitnum) 
    196 { 
    197     size_t*  q = p + (bitnum / (size_t.sizeof*8)); 
    198     size_t mask = 1 << (bitnum & ((size_t.sizeof*8) - 1)); 
    199     int result = *q & mask; 
    200     *q |= mask; 
    201     return result ? -1 : 0; 
    202 } 
    203 else 
    204     int bts(size_t* p, size_t bitnum); 
    205136 
     137int bts( size_t* p, size_t bitnum ); 
    206138 
    207139/** 
    208140 * Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes 
    209        byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 
    210        becomes byte 0. 
     141 * byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 
     142 * becomes byte 0. 
    211143 */ 
    212 version (GNU) 
    213 uint bswap(uint v) 
    214 
    215     return ((v&0xFF)<<24)|((v&0xFF00)<<8)|((v&0xFF0000)>>>8)|((v&0xFF000000)>>>24); 
    216 
    217 else 
    218     uint bswap(uint v); 
     144uint bswap( uint v ); 
    219145 
    220146 
     
    222148 * Reads I/O port at port_address. 
    223149 */ 
    224 version (GNU) 
    225     ubyte  inp(uint p) { return 0; } 
    226 else 
    227     ubyte  inp(uint port_address); 
     150ubyte inp( uint port_address ); 
     151 
    228152 
    229153/** 
    230154 * ditto 
    231155 */ 
    232 version (GNU) 
    233     ushort inpw(uint p) { return 0; } 
    234 else 
    235     ushort inpw(uint port_address); 
     156ushort inpw( uint port_address ); 
     157 
    236158 
    237159/** 
    238160 * ditto 
    239161 */ 
    240 version (GNU) 
    241     uint   inpl(uint p) { return 0; } 
    242 else 
    243     uint   inpl(uint port_address); 
     162uint inpl( uint port_address ); 
    244163 
    245164 
     
    247166 * Writes and returns value to I/O port at port_address. 
    248167 */ 
    249 version (GNU) 
    250     ubyte  outp(uint p, ubyte v) { return v; } 
    251 else 
    252     ubyte  outp(uint port_address, ubyte value); 
     168ubyte outp( uint port_address, ubyte value ); 
     169 
    253170 
    254171/** 
    255172 * ditto 
    256173 */ 
    257 version (GNU) 
    258     ushort outpw(uint p, ushort v) { return v; } 
    259 else 
    260     ushort outpw(uint port_address, ushort value); 
     174ushort outpw( uint port_address, ushort value ); 
     175 
    261176 
    262177/** 
    263178 * ditto 
    264179 */ 
    265 version (GNU) 
    266     uint   outpl(uint p, uint v) { return v; } 
    267 else 
    268     uint   outpl(uint port_address, uint value); 
    269  
    270  
     180uint outpl( uint port_address, uint value ); 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_AC.d

    r5577 r5652  
    8383    } 
    8484 
     85    override size_t talign() 
     86    { 
     87        return (Object[]).alignof; 
     88    } 
     89 
    8590    override size_t tsize() 
    8691    { 
     
    97102        return typeid(Object); 
    98103    } 
     104 
     105    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     106    { 
     107        return 0; 
     108    } 
    99109} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Acdouble.d

    r5577 r5652  
    7676    } 
    7777 
     78    override size_t talign() 
     79    { 
     80        return (cdouble[]).alignof; 
     81    } 
     82 
    7883    override size_t tsize() 
    7984    { 
     
    9095        return typeid(cdouble); 
    9196    } 
     97 
     98    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     99    { 
     100        return 0; 
     101    } 
    92102} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Acfloat.d

    r5577 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (cfloat[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(cfloat); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Acreal.d

    r5577 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (creal[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(creal); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Adouble.d

    r5577 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (double[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(double); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Afloat.d

    r5577 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (float[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(float); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Ag.d

    r5577 r5652  
    4747            return 1; 
    4848        return 0; 
     49    } 
     50 
     51    override size_t talign() 
     52    { 
     53        return (byte[]).alignof; 
    4954    } 
    5055 
     
    134139        return typeid(char); 
    135140    } 
     141 
     142    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     143    { 
     144        return 0; 
     145    } 
    136146} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Aint.d

    r5577 r5652  
    4848    } 
    4949 
     50    override size_t talign() 
     51    { 
     52        return (int[]).alignof; 
     53    } 
     54 
    5055    override size_t tsize() 
    5156    { 
     
    6166    { 
    6267        return typeid(int); 
     68    } 
     69 
     70    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     71    { 
     72        return 0; 
    6373    } 
    6474} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Along.d

    r5577 r5652  
    4949    } 
    5050 
     51    override size_t talign() 
     52    { 
     53        return (long[]).alignof; 
     54    } 
     55 
    5156    override size_t tsize() 
    5257    { 
     
    6267    { 
    6368        return typeid(long); 
     69    } 
     70 
     71    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     72    { 
     73        return 0; 
    6474    } 
    6575} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Areal.d

    r5577 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (real[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
     
    9196        return typeid(real); 
    9297    } 
     98 
     99    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     100    { 
     101        return 0; 
     102    } 
    93103} 
    94104 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_Ashort.d

    r5577 r5652  
    4646            return 1; 
    4747        return 0; 
     48    } 
     49 
     50    override size_t talign() 
     51    { 
     52        return (short[]).alignof; 
    4853    } 
    4954 
     
    109114        return typeid(wchar); 
    110115    } 
     116 
     117    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     118    { 
     119        arg1 = typeid(size_t); 
     120        arg2 = typeid(void*); 
     121        return 0; 
     122    } 
    111123} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_C.d

    r5577 r5652  
    6363    } 
    6464 
     65    override size_t talign() 
     66    { 
     67        return Object.alignof; 
     68    } 
     69 
    6570    override size_t tsize() 
    6671    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_byte.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return byte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_cdouble.d

    r5577 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cdouble.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(cdouble *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        return 0; 
     75    } 
    6676} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_cfloat.d

    r5577 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cfloat.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(cfloat *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        return 0; 
     75    } 
    6676} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_char.d

    r5577 r5652  
    2121    } 
    2222 
     23    override size_t talign() 
     24    { 
     25        return char.alignof; 
     26    } 
     27 
    2328    override size_t tsize() 
    2429    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_creal.d

    r5577 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return creal.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
     
    6469        return (cast(creal *)&r)[0 .. 1]; 
    6570    } 
     71 
     72    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     73    { 
     74        arg1 = typeid(real); 
     75        arg2 = typeid(real); 
     76        return 0; 
     77    } 
    6678} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_dchar.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return dchar.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_delegate.d

    r5577 r5652  
    1919    } 
    2020 
     21    override size_t talign() 
     22    { 
     23        return dg.alignof; 
     24    } 
     25 
    2126    override size_t tsize() 
    2227    { 
     
    3742        return 1; 
    3843    } 
     44 
     45    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     46    { 
     47        arg1 = typeid(void*); 
     48        arg2 = typeid(void*); 
     49        return 0; 
     50    } 
    3951} 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_double.d

    r5577 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return double.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_float.d

    r5577 r5652  
    4343    } 
    4444 
     45    override size_t talign() 
     46    { 
     47        return float.alignof; 
     48    } 
     49 
    4550    override size_t tsize() 
    4651    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_int.d

    r5577 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return int.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_long.d

    r5577 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return long.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_ptr.d

    r5577 r5652  
    2626    } 
    2727 
     28    override size_t talign() 
     29    { 
     30        return (void*).alignof; 
     31    } 
     32 
    2833    override size_t tsize() 
    2934    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_real.d

    r5577 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return real.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_short.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return short.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_ubyte.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ubyte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_uint.d

    r5577 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return uint.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_ulong.d

    r5577 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return ulong.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_ushort.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ushort.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_void.d

    r5577 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return void.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/gdc/typeinfo/ti_wchar.d

    r5577 r5652  
    2222    } 
    2323 
     24    override size_t talign() 
     25    { 
     26        return wchar.alignof; 
     27    } 
     28 
    2429    override size_t tsize() 
    2530    { 
  • trunk/tango/core/rt/compiler/ldc/object_.d

    r5609 r5652  
    323323        foreach (m; ModuleInfo) 
    324324        { 
     325            if (!m) 
     326                continue; 
     327 
    325328            //writefln("module %s, %d", m.name, m.localClasses.length); 
    326329            foreach (c; m.localClasses) 
     
    412415    /// Compares two instances for &lt;, ==, or &gt;. 
    413416    int compare(in void* p1, in void* p2) { return 0; } //throw new Exception("non comparable",__FILE__,__LINE__);  
     417 
     418     /// Return alignment of type 
     419    size_t   talign() { return tsize(); } 
    414420 
    415421    /// Returns size of the type. 
     
    469475    /// Get type information on the contents of the type; null if not available 
    470476    OffsetTypeInfo[] offTi() { return null; } 
     477 
     478 
     479     /** Return internal info on arguments fitting into 8byte. 
     480       * See X86-64 ABI 3.2.3 
     481     */ 
     482    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     483    { 
     484        arg1 = this; 
     485        return 0; 
     486} 
    471487} 
    472488 
     
    494510    override PointerMap pointermap() { return base.pointermap(); } 
    495511    override void[] init() { return m_init.length ? m_init : base.init(); } 
     512 
     513    size_t talign() { return base.talign(); } 
     514 
     515    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     516    {    
     517        return base.argTypes(arg1, arg2); 
     518    } 
    496519 
    497520    TypeInfo base; 
     
    632655 
    633656    override uint flags() { return 1; } 
     657 
     658    size_t talign() 
     659    { 
     660        return (void[]).alignof; 
     661    } 
     662 
     663    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     664    {   //arg1 = typeid(size_t); 
     665        //arg2 = typeid(void*); 
     666        return 0; 
     667    } 
    634668 
    635669    override PointerMap pointermap() 
     
    747781    TypeInfo value; 
    748782    size_t   len; 
     783 
     784    size_t talign() 
     785    { 
     786        return value.talign(); 
     787} 
     788 
     789    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     790    { 
     791        arg1 = typeid(void*); 
     792        return 0; 
     793    } 
     794 
    749795} 
    750796 
     
    816862    TypeInfo value; 
    817863    TypeInfo key; 
     864 
     865    size_t talign() 
     866    { 
     867        return (char[int]).alignof; 
     868} 
     869 
     870    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     871    { 
     872        arg1 = typeid(void*); 
     873        return 0; 
     874    } 
    818875} 
    819876 
     
    900957 
    901958    TypeInfo next; 
     959 
     960    size_t talign() 
     961    { 
     962        alias int delegate() dg; 
     963        return dg.alignof; 
     964} 
     965 
     966    version (X86_64) override int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     967    {   //arg1 = typeid(void*); 
     968        //arg2 = typeid(void*); 
     969        return 0; 
     970    } 
     971 
    902972} 
    903973 
     
    11121182    override uint flags() { return m_flags; } 
    11131183 
     1184    size_t talign() { return m_align; } 
     1185 
     1186 
    11141187    char[] name; 
    11151188    void[] m_init;      // initializer; init.ptr == null if 0 initialize 
     
    11221195 
    11231196    uint m_flags; 
     1197    uint m_align; 
    11241198 
    11251199    version (D_HavePointerMap) { 
     
    11271201 
    11281202        override PointerMap pointermap() { return m_pointermap; } 
     1203    } 
     1204 
     1205    version (X86_64) 
     1206    { 
     1207        int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     1208        { 
     1209            arg1 = m_arg1; 
     1210            arg2 = m_arg2; 
     1211            return 0; 
     1212} 
     1213        TypeInfo m_arg1; 
     1214        TypeInfo m_arg2; 
    11291215    } 
    11301216} 
     
    11951281        assert(0); 
    11961282    } 
     1283 
     1284    version (X86_64) int argTypes(out TypeInfo arg1, out TypeInfo arg2) 
     1285    { 
     1286        assert(0); 
     1287} 
    11971288} 
    11981289 
     
    14701561        } 
    14711562    } 
    1472     debug(PRINTF) printf("_moduleIndependentCtors() DONE\n"); 
    14731563} 
    14741564 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_AC.d

    r4974 r5652  
    8383    } 
    8484 
     85    override size_t talign() 
     86    { 
     87        return (Object[]).alignof; 
     88    } 
     89 
    8590    override size_t tsize() 
    8691    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Acdouble.d

    r4974 r5652  
    7676    } 
    7777 
     78    override size_t talign() 
     79    { 
     80        return (cdouble[]).alignof; 
     81    } 
     82 
    7883    override size_t tsize() 
    7984    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Acfloat.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (cfloat[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Acreal.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (creal[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Adouble.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (double[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Afloat.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (float[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Ag.d

    r5012 r5652  
    4747            return 1; 
    4848        return 0; 
     49    } 
     50 
     51    override size_t talign() 
     52    { 
     53        return (byte[]).alignof; 
    4954    } 
    5055 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Aint.d

    r5012 r5652  
    4646            return 1; 
    4747        return 0; 
     48    } 
     49 
     50    override size_t talign() 
     51    { 
     52        return (int[]).alignof; 
    4853    } 
    4954 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Along.d

    r5012 r5652  
    4747            return 1; 
    4848        return 0; 
     49    } 
     50 
     51    override size_t talign() 
     52    { 
     53        return (long[]).alignof; 
    4954    } 
    5055 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Areal.d

    r4974 r5652  
    7777    } 
    7878 
     79    override size_t talign() 
     80    { 
     81        return (real[]).alignof; 
     82    } 
     83 
    7984    override size_t tsize() 
    8085    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_Ashort.d

    r5012 r5652  
    4646            return 1; 
    4747        return 0; 
     48    } 
     49 
     50    override size_t talign() 
     51    { 
     52        return (short[]).alignof; 
    4853    } 
    4954 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_C.d

    r4974 r5652  
    6363    } 
    6464 
     65    override size_t talign() 
     66    { 
     67        return Object.alignof; 
     68    } 
     69 
    6570    override size_t tsize() 
    6671    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_byte.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return byte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_cdouble.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cdouble.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_cfloat.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return cfloat.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_char.d

    r4974 r5652  
    2121    } 
    2222 
     23    override size_t talign() 
     24    { 
     25        return char.alignof; 
     26    } 
     27 
    2328    override size_t tsize() 
    2429    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_creal.d

    r4974 r5652  
    4545    } 
    4646 
     47    override size_t talign() 
     48    { 
     49        return creal.alignof; 
     50    } 
     51 
    4752    override size_t tsize() 
    4853    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_dchar.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return dchar.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_delegate.d

    r4974 r5652  
    1717    { 
    1818        return *cast(dg *)p1 == *cast(dg *)p2; 
     19    } 
     20 
     21    override size_t talign() 
     22    { 
     23        return dg.alignof; 
    1924    } 
    2025 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_double.d

    r4974 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return double.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_float.d

    r4974 r5652  
    4343    } 
    4444 
     45    override size_t talign() 
     46    { 
     47        return float.alignof; 
     48    } 
     49 
    4550    override size_t tsize() 
    4651    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_int.d

    r4974 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return int.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_long.d

    r4974 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return long.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_ptr.d

    r4974 r5652  
    2626    } 
    2727 
     28    override size_t talign() 
     29    { 
     30        return (void*).alignof; 
     31    } 
     32 
    2833    override size_t tsize() 
    2934    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_real.d

    r4974 r5652  
    4444    } 
    4545 
     46    override size_t talign() 
     47    { 
     48        return real.alignof; 
     49    } 
     50 
    4651    override size_t tsize() 
    4752    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_short.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return short.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_ubyte.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ubyte.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_uint.d

    r4974 r5652  
    2727    } 
    2828 
     29    override size_t talign() 
     30    { 
     31        return uint.alignof; 
     32    } 
     33 
    2934    override size_t tsize() 
    3035    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_ulong.d

    r4974 r5652  
    3232    } 
    3333 
     34    override size_t talign() 
     35    { 
     36        return ulong.alignof; 
     37    } 
     38 
    3439    override size_t tsize() 
    3540    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_ushort.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return ushort.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_void.d

    r4974 r5652  
    2323    } 
    2424 
     25    override size_t talign() 
     26    { 
     27        return void.alignof; 
     28    } 
     29 
    2530    override size_t tsize() 
    2631    { 
  • trunk/tango/core/rt/compiler/ldc/typeinfo/ti_wchar.d

    r4974 r5652  
    2222    } 
    2323 
     24    override size_t talign() 
     25    { 
     26        return wchar.alignof; 
     27    } 
     28 
    2429    override size_t tsize() 
    2530    { 
  • trunk/tango/core/rt/compiler/util/utf.d

    r5248 r5652  
    6969} 
    7070 
     71debug import tango.stdc.stdio : printf; 
     72 
    7173unittest 
    7274{ 
     
    885887    assert(w == "hello"); 
    886888 
     889    debug(utf) printf("utf.toUTF.unittest\n"); 
    887890 
    888891    c = "hel\u1234o"; 
     
    902905    assert(w == "hel\u1234o"); 
    903906 
     907    debug(utf) printf("utf.toUTF.unittest\n"); 
    904908 
    905909    c = "he\U0010AAAAllo"; 
  • trunk/tango/core/rt/gc/basic/gcalloc.d

    r5396 r5652  
    116116else static if (is(typeof(mmap)))  // else version (GC_Use_Alloc_MMap) 
    117117{ 
     118    debug(PRINTF) import tango.stdc.stdio: printf; 
     119 
     120 
    118121    void *os_mem_map(size_t nbytes) 
    119122    {   void *p; 
    120123 
     124        debug(PRINTF) printf("mmap alloc of %p bytes\n", nbytes); 
    121125        p = mmap(null, nbytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); 
    122126        return (p == MAP_FAILED) ? null : p; 
  • trunk/tango/core/rt/gc/basic/gcbits.d

    r5529 r5652  
    5151struct GCBits 
    5252{ 
    53     const int BITS_PER_WORD = 32; 
    54     const int BITS_SHIFT = 5; 
    55     const int BITS_MASK = 31; 
    56  
    57     uint*  data = null; 
     53    alias size_t wordtype; 
     54 
     55    const BITS_PER_WORD = (wordtype.sizeof * 8); 
     56    const BITS_SHIFT = (wordtype.sizeof == 8 ? 6 : 5); 
     57    const BITS_MASK = (BITS_PER_WORD - 1); 
     58    const BITS_1 = cast(wordtype)1; 
     59 
     60    wordtype*  data = null; 
    5861    size_t nwords = 0;    // allocated words in data[] excluding sentinals 
    5962    size_t nbits = 0;     // number of bits in data[] excluding sentinals 
     
    8083        this.nbits = nbits; 
    8184        nwords = (nbits + (BITS_PER_WORD - 1)) >> BITS_SHIFT; 
    82         data = cast(uint*)calloc(nwords + 2, uint.sizeof); 
     85        data = cast(wordtype*)calloc(nwords + 2, wordtype.sizeof); 
    8386        if (!data) 
    8487            onOutOfMemoryError(); 
    8588    } 
    8689 
    87     uint test(size_t i) 
     90    wordtype test(size_t i) 
    8891    in 
    8992    { 
     
    9396    { 
    9497        //return (cast(bit *)(data + 1))[i]; 
    95         return data[1 + (i >> BITS_SHIFT)] & (1 << (i & BITS_MASK)); 
     98        return data[1 + (i >> BITS_SHIFT)] & (BITS_1 << (i & BITS_MASK)); 
    9699    } 
    97100 
     
    104107    { 
    105108        //(cast(bit *)(data + 1))[i] = 1; 
    106         data[1 + (i >> BITS_SHIFT)] |= (1 << (i & BITS_MASK)); 
     109        data[1 + (i >> BITS_SHIFT)] |= (BITS_1 << (i & BITS_MASK)); 
    107110    } 
    108111 
     
    115118    { 
    116119        //(cast(bit *)(data + 1))[i] = 0; 
    117         data[1 + (i >> BITS_SHIFT)] &= ~(1 << (i & BITS_MASK)); 
    118     } 
    119  
    120     uint testClear(size_t i) 
     120        data[1 + (i >> BITS_SHIFT)] &= ~(BITS_1 << (i & BITS_MASK)); 
     121    } 
     122 
     123    wordtype testClear(size_t i) 
    121124    { 
    122125        version (bitops) 
     
    137140        } 
    138141        else 
    139         {   uint result; 
     142        {   wordtype result; 
    140143 
    141144            //result = (cast(bit *)(data + 1))[i]; 
    142145            //(cast(bit *)(data + 1))[i] = 0; 
    143146 
    144             uint* p = &data[1 + (i >> BITS_SHIFT)]; 
    145             uint  mask = (1 << (i & BITS_MASK)); 
     147            wordtype* p = &data[1 + (i >> BITS_SHIFT)]; 
     148            wordtype  mask = (BITS_1 << (i & BITS_MASK)); 
    146149            result = *p & mask; 
    147150            *p &= ~mask; 
     
    150153    } 
    151154 
    152     uint testSet(size_t i) 
     155    wordtype testSet(size_t i) 
    153156    { 
    154157        version (bitops) 
     
    169172        } 
    170173        else 
    171         {   uint result; 
    172  
     174        { 
    173175            //result = (cast(bit *)(data + 1))[i]; 
    174176            //(cast(bit *)(data + 1))[i] = 0; 
    175177 
    176             uint* p = &data[1 + (i >> BITS_SHIFT)]; 
    177             uint  mask = (1 << (i & BITS_MASK)); 
    178             result = *p & mask; 
     178            auto p = &data[1 + (i >> BITS_SHIFT)]; 
     179            auto mask = (BITS_1 << (i & BITS_MASK)); 
     180            auto result = *p & mask; 
    179181            *p |= mask; 
    180182            return result; 
     
    189191                *d1=0u; 
    190192        } else { 
    191             memset(data + 1, 0, nwords * uint.sizeof); 
     193            memset(data + 1, 0, nwords * wordtype.sizeof); 
    192194        } 
    193195    } 
     
    201203    { 
    202204        version(MEMCPY_NON_SIG_SAFE) { 
    203             uint * d1=data+1,d2=f.data+1,dEnd=d1+nwords; 
     205            wordtype * d1=data+1,d2=f.data+1,dEnd=d1+nwords; 
    204206            for (;d1!=dEnd;++d1,++d2) 
    205207                *d1=*d2; 
    206208        } else { 
    207             memcpy(data + 1, f.data + 1, nwords * uint.sizeof); 
    208         } 
    209     } 
    210  
    211     uint* base() 
     209            memcpy(data + 1, f.data + 1, nwords * wordtype.sizeof); 
     210        } 
     211    } 
     212 
     213    wordtype* base() 
    212214    in 
    213215    { 
  • trunk/tango/core/rt/gc/basic/gcx.d

    r5560 r5652  
    6565} 
    6666 
    67  
    6867struct BlkInfo 
    6968{ 
     
    238237    Gcx *gcx;                   // implementation 
    239238    static ClassInfo gcLock;    // global lock 
    240      
     239 
    241240 
    242241    final void initialize() 
     
    13401339 
    13411340    //call locked if necessary 
    1342     private T locked(T)(in T delegate() code)  
     1341    private T locked(T)(in T delegate() code) 
    13431342    { 
    13441343        if (thread_needLock) 
     
    13481347    } 
    13491348 
    1350     private struct WeakPointer  
     1349    private struct WeakPointer 
    13511350    { 
    13521351        Object reference; 
    13531352 
    1354         void ondestroy(Object r)  
     1353        void ondestroy(Object r) 
    13551354        { 
    13561355            assert(r is reference); 
     
    13581357            // 
    13591358            //also ensures that weakpointerDestroy can be called while another 
    1360             //thread is freeing the reference with "delete"                     
     1359            //thread is freeing the reference with "delete" 
    13611360            locked!(void)({ reference = null; }); 
    13621361        } 
     
    13901389    final void weakpointerDestroy( void* p ) 
    13911390    { 
    1392         if (p)         
     1391        if (p) 
    13931392           { 
    13941393           auto wp = cast(WeakPointer*)p; 
     
    14911490        void thread_Invariant() { } 
    14921491    } 
    1493      
     1492 
    14941493    void *cached_size_key; 
    14951494    size_t cached_size_val; 
    1496      
     1495 
    14971496    void *cached_info_key; 
    14981497    BlkInfo cached_info_val; 
     
    16671666    void addRange(void *pbot, void *ptop) 
    16681667    { 
    1669         debug(PRINTF) printf("Thread %x ", pthread_self()); 
     1668        debug(PRINTF) debug(THREADINVARIANT) printf("Thread %x ", pthread_self()); 
    16701669        debug(PRINTF) printf("%x.Gcx::addRange(%x, %x), nranges = %d\n", this, pbot, ptop, nranges); 
    16711670        if (nranges == rangedim) 
     
    16951694    void removeRange(void *pbot) 
    16961695    { 
    1697         debug(PRINTF) printf("Thread %x ", pthread_self()); 
     1696        debug(PRINTF) debug(THREADINVARIANT) printf("Thread %x ", pthread_self()); 
    16981697        debug(PRINTF) printf("%x.Gcx.removeRange(%x), nranges = %d\n", this, pbot, nranges); 
    16991698        for (size_t i = nranges; i--;) 
     
    17991798        if (USE_CACHE && p == cached_size_key) 
    18001799            return cached_size_val; 
    1801              
     1800 
    18021801        pool = findPool(p); 
    18031802        if (pool) 
     
    18361835        Pool*   pool; 
    18371836        BlkInfo info; 
    1838          
     1837 
    18391838        if (USE_CACHE && p == cached_info_key) 
    18401839            return cached_info_val; 
     
    18891888            // getBits 
    18901889            //////////////////////////////////////////////////////////////////// 
    1891              
     1890 
    18921891            assert(p >= info.base && p< info.base + info.size); 
    18931892            info.attr = getBits(pool, cast(size_t) (info.base - pool.baseAddr) / 16); 
     
    20992098        size_t i; 
    21002099 
    2101         //debug(PRINTF) printf("************Gcx::newPool(npages = %d)****************\n", npages); 
     2100 
     2101        debug(PRINTF) printf("************Gcx::newPool(npages = %x)****************\n", npages); 
    21022102 
    21032103        // Round up to COMMITSIZE pages 
     
    23272327                    movq rsi[RBP], RSI      ; 
    23282328                    movq rdi[RBP], RDI      ; 
    2329                     movq r8 [RBP], R8       ;  
    2330                     movq r9 [RBP], R9       ;  
     2329                    movq r8 [RBP], R8       ; 
     2330                    movq r9 [RBP], R9       ; 
    23312331                    movq r10[RBP], R10      ; 
    23322332                    movq r11[RBP], R11      ; 
     
    23452345        else 
    23462346        { 
    2347         asm 
    2348         { 
    2349             pushad              ; 
    2350             mov sp[EBP],ESP     ; 
     2347        version (D_InlineAsm_X86) 
     2348        { 
     2349            asm 
     2350            { 
     2351                pushad              ; 
     2352                mov sp[EBP],ESP     ; 
     2353            } 
     2354        } 
     2355        else version (D_InlineAsm_X86_64) 
     2356        { 
     2357            asm 
     2358            { 
     2359                push RAX ; 
     2360                push RBX ; 
     2361                push RCX ; 
     2362                push RDX ; 
     2363                push RSI ; 
     2364                push RDI ; 
     2365                push RBP ; 
     2366                push R8  ; 
     2367                push R9  ; 
     2368                push R10  ; 
     2369                push R11  ; 
     2370                push R12  ; 
     2371                push R13  ; 
     2372                push R14  ; 
     2373                push R15  ; 
     2374                push EAX ;   // 16 byte align the stack 
     2375            } 
     2376        } 
     2377        else 
     2378        { 
     2379            static assert( false, "Architecture not supported." ); 
    23512380        } 
    23522381        } 
     
    23602389            // nothing to do 
    23612390        } 
     2391        else version (D_InlineAsm_X86) 
     2392        { 
     2393            asm 
     2394            { 
     2395                popad; 
     2396            } 
     2397        } 
     2398        else version (D_InlineAsm_X86_64) 
     2399        { 
     2400            asm 
     2401            { 
     2402                pop EAX ;   // 16 byte align the stack 
     2403                pop R15  ; 
     2404                pop R14  ; 
     2405                pop R13  ; 
     2406                pop R12  ; 
     2407                pop R11  ; 
     2408                pop R10  ; 
     2409                pop R9  ; 
     2410                pop R8  ; 
     2411                pop RBP ; 
     2412                pop RDI ; 
     2413                pop RSI ; 
     2414                pop RDX ; 
     2415                pop RCX ; 
     2416                pop RBX ; 
     2417                pop RAX ; 
     2418            } 
     2419        } 
    23622420        else 
    23632421        { 
    2364         asm 
    2365         { 
    2366             popad               ; 
    2367         } 
     2422            static assert( false, "Architecture not supported." ); 
    23682423        } 
    23692424        return result; 
     
    24722527                    *b = 0; 
    24732528 
    2474                     auto o = pool.baseAddr + (b - bbase) * 32 * 16; 
     2529                    auto o = pool.baseAddr + (b - bbase) * (typeof(bitm).sizeof*8) * 16; 
    24752530                    if (!(bitm & 0xFFFF)) 
    24762531                    { 
     
    25202575        {   size_t pn; 
    25212576            size_t ncommitted; 
    2522             uint*  bbase; 
    25232577 
    25242578            pool = pooltable[n]; 
    2525             bbase = pool.mark.base(); 
     2579            auto bbase = pool.mark.base(); 
    25262580            ncommitted = pool.ncommitted; 
    25272581            for (pn = 0; pn < ncommitted; pn++, bbase += PAGESIZE / (32 * 16)) 
     
    25722626 
    25732627                            pool.freebits.set(biti); 
     2628 
    25742629                            if (pool.finals.nbits && pool.finals.testClear(biti)) 
    25752630                                rt_finalize(cast(List *)sentinel_add(p), false/*noStack > 0*/); 
     
    29102965        poolsize = npages * PAGESIZE; 
    29112966        assert(poolsize >= POOLSIZE); 
     2967 
     2968        debug(PRINTF) printf("alloc of pool: %p bytes\n", poolsize); 
     2969 
    29122970        baseAddr = cast(byte *)os_mem_map(poolsize); 
    29132971 
  • trunk/tango/core/rt/gc/cdgc/gc.d

    r5621 r5652  
    768768    else 
    769769    { 
    770     asm 
    771     { 
    772         pushad              ; 
    773         mov sp[EBP],ESP     ; 
    774     } 
     770        version (D_InlineAsm_X86) 
     771        { 
     772            asm 
     773            { 
     774                pushad              ; 
     775                mov sp[EBP],ESP     ; 
     776            } 
     777        } 
     778        else version (D_InlineAsm_X86_64) 
     779        { 
     780            asm 
     781            { 
     782                push RAX ; 
     783                push RBX ; 
     784                push RCX ; 
     785                push RDX ; 
     786                push RSI ; 
     787                push RDI ; 
     788                push RBP ; 
     789                push R8  ; 
     790                push R9  ; 
     791                push R10  ; 
     792                push R11  ; 
     793                push R12  ; 
     794                push R13  ; 
     795                push R14  ; 
     796                push R15  ; 
     797                push EAX ;   // 16 byte align the stack 
     798            } 
     799        } 
     800        else 
     801        { 
     802            static assert( false, "Architecture not supported." ); 
     803        } 
    775804    } 
    776805    result = fullcollect(sp, early, force_block); 
  • trunk/tango/core/sync/Atomic.d

    r5607 r5652  
    246246    } 
    247247} else version(D_InlineAsm_X86) { 
    248     T atomicSwap( T )( inout T val, T newval ) 
     248    T atomicSwap( T )( ref T val, T newval ) 
    249249    in { 
    250250        // NOTE: 32 bit x86 systems support 8 byte CAS, which only requires 
     
    290290    } 
    291291} else version (D_InlineAsm_X86_64){ 
    292     T atomicSwap( T )( inout T val, T newval ) 
     292    T atomicSwap( T )( ref T val, T newval ) 
    293293    in { 
    294294        assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); 
     
    333333    } 
    334334} else { 
    335     T atomicSwap( T )( inout T val, T newval ) 
     335    T atomicSwap( T )( ref T val, T newval ) 
    336336    in { 
    337337        assert( atomicValueIsProperlyAligned!(T)( cast(size_t) &val ) ); 
  • trunk/tango/core/tools/LinuxStackTrace.d

    r5607 r5652  
    184184            STB_LOCAL   = 0, 
    185185        } 
    186          
     186 
    187187    } 
    188188 
     
    232232            return newV; 
    233233        } 
    234          
     234 
    235235        // stores the global sections 
    236236        const MAX_SECTS=5; 
     
    238238        static size_t _nGSections,_nFileBuf; 
    239239        static char[MAX_SECTS*256] _fileNameBuf; 
    240          
     240 
    241241        /// loops on the global sections 
    242242        static int opApply(int delegate(ref StaticSectionInfo) loop){ 
     
    383383        } 
    384384 
    385    
     385 
    386386        /* find sections */ 
    387387        char[] string_table; 
     
    590590                return; 
    591591            } 
    592                  
     592 
    593593        } 
    594594    } 
     
    671671        } 
    672672        long sleb128() { 
    673             return cast(size_t) do_read_leb(true); 
     673            return cast(long) do_read_leb(true); 
    674674        } 
    675675 
     
    697697    } 
    698698 
    699     unittest { 
     699    unittest  
     700    { 
    700701        //examples from dwarf spec section 7.6 
    701         ubyte[] bytes = [2,127,0x80,1,0x81,1,0x82,1,57+0x80,100,2,0x7e,127+0x80,0, 
    702             0x81,0x7f,0x80,1,0x80,0x7f,0x81,1,0x7f+0x80,0x7e]; 
     702        ubyte[] bytes = [2, 127, 0x80,1, 0x81,1, 0x82,1, 57+0x80,100,  
     703                         2, 0x7e, 127+0x80,0, 0x81,0x7f, 0x80,1, 0x80,0x7f, 0x81,1, 0x7f+0x80,0x7e]; 
     704 
    703705        ulong[] u = [2, 127, 128, 129, 130, 12857]; 
    704706        long[] s = [2, -2, 127, -127, 128, -128, 129, -129]; 
     707 
    705708        auto rd = DwarfReader(bytes); 
     709 
    706710        foreach (x; u) 
    707711            assert(rd.uleb128() == x); 
     712 
    708713        foreach (x; s) 
    709714            assert(rd.sleb128() == x); 
  • trunk/tango/core/tools/StackTrace.d

    r5607 r5652  
    7373/// *return* addresses, the most likely the calling instruction is the one before them 
    7474/// (stack top excluded.) 
    75 extern(C) size_t rt_addrBacktrace(TraceContext* context, TraceContext *contextOut,size_t*traceBuf,size_t bufLength,int *flags){ 
    76     if (addrBacktraceFnc !is null){ 
     75extern(C) size_t rt_addrBacktrace(TraceContext* context, TraceContext *contextOut,size_t*traceBuf,size_t bufLength,int *flags) 
     76
     77    if (addrBacktraceFnc !is null) 
    7778        return addrBacktraceFnc(context,contextOut,traceBuf,bufLength,flags); 
    78     } else { 
     79    else 
    7980        return 0; 
    80     } 
    8181} 
    8282 
    8383/// Tries to sybolize a frame information, this should try to build the best 
    84 /// backtrace information, if possible finding the calling context, thus  
     84/// backtrace information, if possible finding the calling context, thus 
    8585/// if fInfo.exactAddress is false the address might be changed to the one preceding it 
    8686/// returns true if it managed to at least find the function name. 
     
    142142 
    143143/// Basic class that represents a stacktrace. 
    144 class BasicTraceInfo: Exception.TraceInfo{ 
     144class BasicTraceInfo: Exception.TraceInfo 
     145
    145146    size_t[] traceAddresses; 
    146147    size_t[128] traceBuf; 
     
    160161    } 
    161162    /// Takes a stacktrace. 
    162     void trace(TraceContext *contextIn=null,int skipFrames=0){ 
     163    void trace(TraceContext *contextIn=null,int skipFrames=0) 
     164    { 
    163165        int flags; 
    164166        size_t nFrames=rt_addrBacktrace(contextIn,&context,traceBuf.ptr,traceBuf.length,&flags); 
     
    179181            fInfo.exactAddress=(addrPrecision & 2) || (iframe==0 && (addrPrecision & 1)); 
    180182            rt_symbolizeFrameInfo(fInfo,&context,buf); 
    181              
     183 
    182184            auto r= fInfo.func in internalFuncs; 
    183185            fInfo.internalFunction |= (r !is null); 
     
    212214} 
    213215 
     216 
     217 
    214218/// Default (tango given) backtrace function. 
    215 size_t defaultAddrBacktrace(TraceContext* context,TraceContext*contextOut, 
    216     size_t*traceBuf,size_t length,int*flags){ 
    217     version(LibCBacktrace){ 
     219size_t defaultAddrBacktrace(TraceContext* context, TraceContext*contextOut, 
     220    size_t*traceBuf,size_t length,int*flags) 
     221
     222    version(LibCBacktrace) 
     223    { 
    218224        //if (context!is null) return 0; // now it just gives a local trace, uncomment & skip? 
    219225        *flags=AddrPrecision.TopExact; 
    220226        return cast(size_t)backtrace(cast(void**)traceBuf,length); 
    221     } else version (Windows){ 
     227    } 
     228    else version (Windows) 
     229    { 
    222230        return winAddrBacktrace(context,contextOut,traceBuf,length,flags); 
    223     } else { 
     231    } 
     232    else 
     233    { 
    224234        return 0; 
    225235    } 
     
    309319 
    310320/// Function that generates a trace (handler compatible with old TraceInfo.) 
    311 Exception.TraceInfo basicTracer( void* ptr = null ){ 
     321Exception.TraceInfo basicTracer( void* ptr = null ) 
     322
    312323    BasicTraceInfo res; 
    313     try{ 
    314         version(CatchRecursiveTracing){ 
     324    try 
     325    { 
     326        version(CatchRecursiveTracing) 
     327        { 
    315328            recursiveStackTraces.val=recursiveStackTraces.val+1; 
    316329            scope(exit) recursiveStackTraces.val=recursiveStackTraces.val-1; 
    317330            // printf("tracer %d\n",recursiveStackTraces.val); 
    318             if (recursiveStackTraces.val>10) { 
     331            if (recursiveStackTraces.val>10) 
     332            { 
    319333                Runtime.console.stderr("hit maximum recursive tracing (tracer asserting...?)\n"); 
    320334                abort(); 
     
    324338        res=new BasicTraceInfo(); 
    325339        res.trace(cast(TraceContext*)ptr); 
    326     } catch (Exception e){ 
     340    } 
     341    catch (Exception e) 
     342    { 
    327343        Runtime.console.stderr("tracer got exception:\n"); 
    328344        Runtime.console.stderr(e.msg); 
    329345        e.writeOut((char[]s){ Runtime.console.stderr(s); }); 
    330346        Runtime.console.stderr("\n"); 
    331     } catch (Object o){ 
     347    } 
     348    catch (Object o) 
     349    { 
    332350        Runtime.console.stderr("tracer got object exception:\n"); 
    333351        Runtime.console.stderr(o.toString()); 
     
    382400 
    383401    sigaction_t fault_action; 
    384          
     402 
    385403    void setupSegfaultTracer(){ 
    386404        //use an alternative stack; this is useful when infinite recursion 
     
    400418        } 
    401419    } 
    402      
     420 
    403421    version(noSegfaultTrace){ 
    404422    } else { 
  • trunk/tango/core/vendor/std/intrinsic.di

    r5594 r5652  
    2626 *  The return value is undefined if v is zero. 
    2727 */ 
    28 int bsf( uint v ); 
     28int bsf( size_t v ); 
    2929 
    3030 
  • trunk/tango/io/Console.d

    r5615 r5652  
    639639} 
    640640 
    641  
    642641/****************************************************************************** 
    643642 
  • trunk/tango/io/Path.d

    r5615 r5652  
    185185        /*********************************************************************** 
    186186 
     187                Return an adjusted path such that non-empty instances always 
     188                have a leading separator. 
     189 
     190                Note: Allocates memory where path is not already terminated. 
     191 
     192        ***********************************************************************/ 
     193 
     194        static char[] paddedLeading (char[] path, char c = '/') 
     195        { 
     196                if (path.length && path[0] != c) 
     197                    path = c ~ path; 
     198                return path; 
     199        } 
     200 
     201        /*********************************************************************** 
     202 
    187203                Return an adjusted path such that non-empty instances do not 
    188204                have a trailing separator. 
     
    211227 
    212228                if (paths.length) 
    213                    { 
    214                    foreach (path; paths[0 .. $-1]) 
    215                             result ~= padded (path); 
    216                    result ~= paths [$-1]; 
     229                { 
     230                    result ~= paths[0]; 
     231 
     232                    foreach (path; paths[1 .. $-1]) 
     233                        result ~= paddedLeading (stripped(path)); 
     234 
     235                    result ~= paddedLeading(paths[$-1]); 
     236 
    217237                   return result; 
    218                    
     238               
    219239                return ""; 
    220240        } 
  • trunk/tango/io/device/Device.d

    r5615 r5652  
    292292                override size_t read (void[] dst) 
    293293                { 
    294                         int read = posix.read (handle, dst.ptr, dst.length); 
     294                        auto read = posix.read (handle, dst.ptr, dst.length); 
     295 
    295296                        if (read is -1) 
    296297                            error; 
  • trunk/tango/io/stream/Format.d

    r5615 r5652  
    1616 
    1717private import tango.text.convert.Layout; 
     18 
     19version(DigitalMars) 
     20{ 
     21    version(X86_64) version=DigitalMarsX64; 
     22 
     23    private import tango.core.Vararg; 
     24} 
     25else version (GNU) 
     26{ 
     27    private import tango.core.Vararg; 
     28} 
     29 
    1830 
    1931/******************************************************************************* 
     
    137149        final FormatOutput format (T[] fmt, ...) 
    138150        { 
     151            version (DigitalMarsX64) 
     152            { 
     153                va_list ap; 
     154 
     155                va_start(ap, __va_argsave); 
     156 
     157                scope(exit) va_end(ap); 
     158 
     159                convert (&emit, _arguments, ap, fmt); 
     160            } 
     161            else 
    139162                convert (&emit, _arguments, _argptr, fmt); 
    140                 return this; 
     163 
     164            return this; 
    141165        } 
    142166 
     
    149173        final FormatOutput formatln (T[] fmt, ...) 
    150174        { 
     175            version (DigitalMarsX64) 
     176            { 
     177                va_list ap; 
     178 
     179                va_start(ap, __va_argsave); 
     180 
     181                scope(exit) va_end(ap); 
     182 
     183                convert (&emit, _arguments, ap, fmt); 
     184            } 
     185            else 
    151186                convert (&emit, _arguments, _argptr, fmt); 
    152                 return newline; 
     187 
     188           return newline; 
    153189        } 
    154190 
     
    160196        **********************************************************************/ 
    161197 
    162         final FormatOutput print (...
    163         { 
    164                 static T[] slice =  "{}, {}, {}, {}, {}, {}, {}, {}, " 
    165                                      "{}, {}, {}, {}, {}, {}, {}, {}, " 
    166                                      "{}, {}, {}, {}, {}, {}, {}, {}, "; 
     198        final FormatOutput print ( ...
     199        { 
     200                static T[] slice =  "{}, {}, {}, {}, {}, {}, {}, {}, " 
     201                                          "{}, {}, {}, {}, {}, {}, {}, {}, " 
     202                                          "{}, {}, {}, {}, {}, {}, {}, {}, "; 
    167203 
    168204                assert (_arguments.length <= slice.length/4, "FormatOutput :: too many arguments"); 
    169205 
    170                 if (_arguments.length is 0) 
     206                if (_arguments.length == 0) 
    171207                    sink.flush; 
    172208                else 
    173                    convert (&emit, _arguments, _argptr, slice[0 .. _arguments.length * 4 - 2]); 
    174  
     209                { 
     210 
     211                    version (DigitalMarsX64) 
     212                    { 
     213                        va_list ap; 
     214 
     215                        va_start(ap, __va_argsave); 
     216 
     217                        scope(exit) va_end(ap); 
     218 
     219                        convert (&emit, _arguments, ap, slice[0 .. _arguments.length * 4 - 2]); 
     220                    } 
     221                    else 
     222                        convert (&emit, _arguments, _argptr, slice[0 .. _arguments.length * 4 - 2]); 
     223                } 
    175224                return this; 
    176225        } 
  • trunk/tango/io/stream/Snoop.d

    r5615 r5652  
    1717 
    1818private import  tango.text.convert.Format; 
     19 
     20version(DigitalMars) 
     21{ 
     22    private import tango.core.Vararg; 
     23}else version (GNU) 
     24    private import tango.core.Vararg; 
    1925 
    2026private alias void delegate(char[]) Snoop; 
  • trunk/tango/io/vfs/ZipFolder.d

    r5615 r5652  
    456456    } 
    457457 
     458 
     459    // workaround for a bug in gdb. See ticket #190 
     460    version (GNU)  
     461    { 
     462        override VfsFolder close(bool commit = true) 
     463        { 
     464            assert( valid ); 
     465            return closeImpl(commit); 
     466        } 
     467 
     468        override VfsFolder sync() 
     469        {  
     470            assert( valid );  
     471            return syncImpl(); 
     472        } 
     473    } 
     474    else 
     475    { 
     476        override VfsFolder close(bool commit = true) 
     477        in { assert( valid ); } 
     478        body 
     479        { 
     480            return closeImpl(commit); 
     481        }    
     482 
     483 
     484        override VfsFolder sync() 
     485        in { assert( valid ); } 
     486        body 
     487        { 
     488            return syncImpl(); 
     489        } 
     490    } 
     491 
    458492    /** 
    459493     * Closes this folder object.  If commit is true, then the folder is 
    460494     * sync'ed before being closed. 
    461495     */ 
    462     override VfsFolder close(bool commit = true) 
    463     in { assert( valid ); } 
    464     body 
     496    protected VfsFolder closeImpl(bool commit = true) 
    465497    { 
    466498        // MUTATE 
     
    477509     * applies to the entire archive, not just this folder and its contents. 
    478510     */ 
    479     override VfsFolder sync() 
    480     in { assert( valid ); } 
    481     body 
     511    protected VfsFolder syncImpl() 
    482512    { 
    483513        // MUTATE 
     
    634664     * argument is true (the default), then changes to the archive will be 
    635665     * flushed out to disk.  If false, changes will simply be discarded. 
     666         
    636667     */ 
     668 
    637669    final override VfsFolder close(bool commit = true) 
    638670    in { assert( valid ); } 
  • trunk/tango/net/device/Berkeley.d

    r5650 r5652  
    2727        LINGER       =   consts.SO_LINGER    ,       /* linger on close if data present */ 
    2828        DONTLINGER   = ~(consts.SO_LINGER), 
    29          
     29 
    3030        OOBINLINE    =   consts.SO_OOBINLINE ,       /* leave received OOB data in line */ 
    3131        ACCEPTCONN   =   consts.SO_ACCEPTCONN,       /* socket has had listen() */ 
     
    3333        DONTROUTE    =   consts.SO_DONTROUTE ,       /* just use interface addresses */ 
    3434        TYPE         =   consts.SO_TYPE      ,       /* get socket type */ 
    35      
     35 
    3636        /* 
    3737         * Additional options, not kept in so_options. 
     
    4646        ADD_MEMBERSHIP  = consts.IP_ADD_MEMBERSHIP , 
    4747        DROP_MEMBERSHIP = consts.IP_DROP_MEMBERSHIP, 
    48      
     48 
    4949        // OptionLevel.TCP settings 
    5050        TCP_NODELAY     = consts.TCP_NODELAY , 
    5151 
    52         // Windows specifics     
    53         WIN_UPDATE_ACCEPT_CONTEXT  = 0x700B,  
    54         WIN_CONNECT_TIME           = 0x700C,  
    55         WIN_UPDATE_CONNECT_CONTEXT = 0x7010,  
     52        // Windows specifics 
     53        WIN_UPDATE_ACCEPT_CONTEXT  = 0x700B, 
     54        WIN_CONNECT_TIME           = 0x700C, 
     55        WIN_UPDATE_CONNECT_CONTEXT = 0x7010, 
    5656} 
    57      
     57 
    5858/******************************************************************************* 
    5959 
     
    6363{ 
    6464        SOCKET = consts.SOL_SOCKET    , 
    65         IP     = consts.IPPROTO_IP    ,    
    66         TCP    = consts.IPPROTO_TCP   ,    
    67         UDP    = consts.IPPROTO_UDP   ,    
     65        IP     = consts.IPPROTO_IP    , 
     66        TCP    = consts.IPPROTO_TCP   , 
     67        UDP    = consts.IPPROTO_UDP   , 
    6868} 
    69      
     69 
    7070/******************************************************************************* 
    7171 
     
    134134} 
    135135 
    136 enum AIFlags: int  
     136enum AIFlags: int 
    137137{ 
    138138        PASSIVE = consts.AI_PASSIVE,            /// get address to use bind() 
    139139        CANONNAME = consts.AI_CANONNAME,        /// fill ai_canonname 
    140140        NUMERICHOST = consts.AI_NUMERICHOST,    /// prevent host name resolution 
    141         NUMERICSERV = consts.AI_NUMERICSERV,    /// prevent service name resolution valid  
    142                                                 /// flags for addrinfo (not a standard def,  
     141        NUMERICSERV = consts.AI_NUMERICSERV,    /// prevent service name resolution valid 
     142                                                /// flags for addrinfo (not a standard def, 
    143143                                                /// apps should not use it) 
    144         ALL = consts.AI_ALL,                    /// IPv6 and IPv4-mapped (with AI_V4MAPPED)  
     144        ALL = consts.AI_ALL,                    /// IPv6 and IPv4-mapped (with AI_V4MAPPED) 
    145145        ADDRCONFIG = consts.AI_ADDRCONFIG,      /// only if any address is assigned 
    146         V4MAPPED = consts.AI_V4MAPPED,          /// accept IPv4-mapped IPv6 address special  
     146        V4MAPPED = consts.AI_V4MAPPED,          /// accept IPv4-mapped IPv6 address special 
    147147                                                /// recommended flags for getipnodebyname 
    148148        MASK = consts.AI_MASK, 
     
    164164 
    165165 
    166 enum NIFlags: int  
     166enum NIFlags: int 
    167167{ 
    168168        MAXHOST = consts.NI_MAXHOST, 
     
    175175} 
    176176 
    177               
     177 
    178178/******************************************************************************* 
    179179 
     
    194194        } 
    195195} 
    196 else  
     196else 
    197197{ 
    198198        private import tango.core.BitManip; 
     
    225225        { 
    226226                alias closesocket close; 
    227          
     227 
    228228                socket_t socket(int af, int type, int protocol); 
    229229                int ioctlsocket(socket_t s, int cmd, uint* argp); 
     
    249249                NetHost.hostent* gethostbyaddr(void* addr, int len, int type); 
    250250                /** 
    251                 The gai_strerror function translates error codes of getaddrinfo,  
    252                 freeaddrinfo and getnameinfo to a human readable string, suitable  
     251                The gai_strerror function translates error codes of getaddrinfo, 
     252                freeaddrinfo and getnameinfo to a human readable string, suitable 
    253253                for error reporting. (C) MAN 
    254254                */ 
     
    256256 
    257257                /** 
    258                 Given node and service, which identify an Internet host and a service,  
    259                 getaddrinfo() returns one or more addrinfo structures, each of which  
    260                 contains an Internet address that can be specified in a call to bind  
    261                 or connect. The getaddrinfo() function combines the functionality  
    262                 provided by the getservbyname and getservbyport functions into a single  
    263                 interface, but unlike the latter functions, getaddrinfo() is reentrant  
     258                Given node and service, which identify an Internet host and a service, 
     259                getaddrinfo() returns one or more addrinfo structures, each of which 
     260                contains an Internet address that can be specified in a call to bind 
     261                or connect. The getaddrinfo() function combines the functionality 
     262                provided by the getservbyname and getservbyport functions into a single 
     263                interface, but unlike the latter functions, getaddrinfo() is reentrant 
    264264                and allows programs to eliminate IPv4-versus-IPv6 dependencies.(C) MAN 
    265265                */ 
    266266                int function(char* node, char* service, Address.addrinfo* hints, Address.addrinfo** res) getaddrinfo; 
    267          
     267 
    268268                /** 
    269                 The freeaddrinfo() function frees the memory that was allocated for the  
     269                The freeaddrinfo() function frees the memory that was allocated for the 
    270270                dynamically allocated linked list res.  (C) MAN 
    271                 */                              
    272                 void function(Address.addrinfo *res) freeaddrinfo;  
    273                                  
     271                */ 
     272                void function(Address.addrinfo *res) freeaddrinfo; 
     273 
    274274                /** 
    275                 The getnameinfo() function is the inverse of getaddrinfo: it converts  
     275                The getnameinfo() function is the inverse of getaddrinfo: it converts 
    276276                a socket address to a corresponding host and service, in a protocol- 
    277                 independent manner. It combines the functionality of gethostbyaddr and  
    278                 getservbyport, but unlike those functions, getaddrinfo is reentrant and  
     277                independent manner. It combines the functionality of gethostbyaddr and 
     278                getservbyport, but unlike those functions, getaddrinfo is reentrant and 
    279279                allows programs to eliminate IPv4-versus-IPv6 dependencies. (C) MAN 
    280280                */ 
    281                 int function(Address.sockaddr* sa, int salen, char* host, int hostlen, char* serv, int servlen, int flags) getnameinfo;  
    282                  
     281                int function(Address.sockaddr* sa, int salen, char* host, int hostlen, char* serv, int servlen, int flags) getnameinfo; 
     282 
    283283                bool function (socket_t, uint, void*, DWORD, DWORD, DWORD, DWORD*, OVERLAPPED*) AcceptEx; 
    284284                bool function (socket_t, HANDLE, DWORD, DWORD, OVERLAPPED*, void*, DWORD) TransmitFile; 
    285285                bool function (socket_t, void*, int, void*, DWORD, DWORD*, OVERLAPPED*) ConnectEx; 
    286                                  
     286 
    287287                //char* inet_ntop(int af, void *src, char *dst, int len); 
    288288        } 
    289289 
    290         private HMODULE lib;                
     290        private HMODULE lib; 
    291291 
    292292        static this() 
     
    294294                lib = LoadLibraryA ("Ws2_32.dll"); 
    295295                getnameinfo = cast(typeof(getnameinfo)) GetProcAddress(lib, "getnameinfo"); 
    296                 if (!getnameinfo)  
    297                    {  
     296                if (!getnameinfo) 
     297                   { 
    298298                   FreeLibrary (lib); 
    299299                   lib = LoadLibraryA ("Wship6.dll"); 
    300                    }  
    301                 getnameinfo = cast(typeof(getnameinfo)) GetProcAddress(lib, "getnameinfo");  
    302             getaddrinfo = cast(typeof(getaddrinfo)) GetProcAddress(lib, "getaddrinfo");  
    303                 freeaddrinfo = cast(typeof(freeaddrinfo)) GetProcAddress(lib, "freeaddrinfo");  
    304                 if (!getnameinfo)  
    305                    {  
     300                   } 
     301                getnameinfo = cast(typeof(getnameinfo)) GetProcAddress(lib, "getnameinfo"); 
     302            getaddrinfo = cast(typeof(getaddrinfo)) GetProcAddress(lib, "getaddrinfo"); 
     303                freeaddrinfo = cast(typeof(freeaddrinfo)) GetProcAddress(lib, "freeaddrinfo"); 
     304                if (!getnameinfo) 
     305                   { 
    306306                   FreeLibrary (lib); 
    307307                   lib = null; 
    308                    }  
     308                   } 
    309309 
    310310                WSADATA wd = void; 
     
    319319                auto s = cast(HANDLE) socket (AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP); 
    320320                assert (s != cast(HANDLE) -1); 
    321                                  
    322                 WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER,  
    323                           &connectG, connectG.sizeof, &ConnectEx,  
     321 
     322                WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER, 
     323                          &connectG, connectG.sizeof, &ConnectEx, 
    324324                          ConnectEx.sizeof, &result, null, null); 
    325325 
    326                 WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER,  
    327                           &acceptG, acceptG.sizeof, &AcceptEx,  
     326                WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER, 
     327                          &acceptG, acceptG.sizeof, &AcceptEx, 
    328328                          AcceptEx.sizeof, &result, null, null); 
    329329 
    330                 WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER,  
    331                           &transmitG, transmitG.sizeof, &TransmitFile,  
     330                WSAIoctl (s, SIO_GET_EXTENSION_FUNCTION_POINTER, 
     331                          &transmitG, transmitG.sizeof, &TransmitFile, 
    332332                          TransmitFile.sizeof, &result, null, null); 
    333333                closesocket (cast(socket_t) s); 
     
    371371                NetHost.hostent* gethostbyname(char* name); 
    372372                NetHost.hostent* gethostbyaddr(void* addr, int len, int type); 
    373                                  
     373 
    374374                /** 
    375                 Given node and service, which identify an Internet host and a service,  
    376                 getaddrinfo() returns one or more addrinfo structures, each of which  
    377                 contains an Internet address that can be specified in a call to bind or  
    378                 connect. The getaddrinfo() function combines the functionality provided  
     375                Given node and service, which identify an Internet host and a service, 
     376                getaddrinfo() returns one or more addrinfo structures, each of which 
     377                contains an Internet address that can be specified in a call to bind or 
     378                connect. The getaddrinfo() function combines the functionality provided 
    379379                by the getservbyname and getservbyport functions into a single interface, 
    380                 but unlike the latter functions, getaddrinfo() is reentrant and allows  
     380                but unlike the latter functions, getaddrinfo() is reentrant and allows 
    381381                programs to eliminate IPv4-versus-IPv6 dependencies. (C) MAN 
    382382                */ 
    383                 int getaddrinfo(char* node, char* service, Address.addrinfo* hints, Address.addrinfo** res);  
    384                                          
     383                int getaddrinfo(char* node, char* service, Address.addrinfo* hints, Address.addrinfo** res); 
     384 
    385385                /** 
    386                 The freeaddrinfo() function frees the memory that was allocated for the  
     386                The freeaddrinfo() function frees the memory that was allocated for the 
    387387                dynamically allocated linked list res.  (C) MAN 
    388388                */ 
    389                 void freeaddrinfo(Address.addrinfo *res);  
    390                                  
     389                void freeaddrinfo(Address.addrinfo *res); 
     390 
    391391                /** 
    392392                The getnameinfo() function is the inverse of getaddrinfo: it converts a socket 
    393                 address to a corresponding host and service, in a protocol-independent manner.  
    394                 It combines the functionality of gethostbyaddr and getservbyport, but unlike  
    395                 those functions, getaddrinfo is reentrant and allows programs to eliminate  
     393                address to a corresponding host and service, in a protocol-independent manner. 
     394                It combines the functionality of gethostbyaddr and getservbyport, but unlike 
     395                those functions, getaddrinfo is reentrant and allows programs to eliminate 
    396396                IPv4-versus-IPv6 dependencies. (C) MAN 
    397397                */ 
    398                 int getnameinfo(Address.sockaddr* sa, int salen, char* host, int hostlen, char* serv, int servlen, int flags);  
    399                                  
     398                int getnameinfo(Address.sockaddr* sa, int salen, char* host, int hostlen, char* serv, int servlen, int flags); 
     399 
    400400                /** 
    401                 The gai_strerror function translates error codes of getaddrinfo, freeaddrinfo  
     401                The gai_strerror function translates error codes of getaddrinfo, freeaddrinfo 
    402402                and getnameinfo to a human readable string, suitable for error reporting. (C) MAN 
    403403                */ 
    404                 char* gai_strerror(int errcode);  
    405                                  
     404                char* gai_strerror(int errcode); 
     405 
    406406                char* inet_ntop(int af, void *src, char *dst, int len); 
    407407       } 
     
    422422         bool           synchronous; 
    423423 
    424         enum : socket_t  
     424        enum : socket_t 
    425425        { 
    426426                INVALID_SOCKET = socket_t.init 
    427427        } 
    428          
    429         enum  
     428 
     429        enum 
    430430        { 
    431431                Error = -1 
     
    435435        alias noDelay      setNoDelay;          // backward compatibility 
    436436        alias addressReuse setAddressReuse;     // backward compatibility 
    437          
     437 
    438438 
    439439        /*********************************************************************** 
     
    608608        void accept (ref Berkeley target) 
    609609        { 
    610                 auto newsock = .accept (sock, null, null);  
     610                auto newsock = .accept (sock, null, null); 
    611611                if (socket_t.init is newsock) 
    612612                    exception ("Unable to accept socket connection: "); 
     
    795795        /*********************************************************************** 
    796796 
    797                 Send data on the connection. Returns the number of bytes  
    798                 actually sent, or ERROR on failure. If the socket is blocking  
     797                Send data on the connection. Returns the number of bytes 
     798                actually sent, or ERROR on failure. If the socket is blocking 
    799799                and there is no buffer space left, send waits. 
    800800 
     
    804804 
    805805        int send (void[] buf, SocketFlags flags=SocketFlags.NONE) 
    806         {        
     806        { 
    807807                if (buf.length is 0) 
    808808                    return 0; 
     
    810810                version (Posix) 
    811811                        { 
    812                         auto ret = .send (sock, buf.ptr, buf.length,  
     812                        auto ret = .send (sock, buf.ptr, buf.length, 
    813813                                          SocketFlags.NOSIGNAL + cast(int) flags); 
    814814                        if (errno is EPIPE) 
     
    822822        /*********************************************************************** 
    823823 
    824                 Send data to a specific destination Address. If the  
    825                 destination address is not specified, a connection  
    826                 must have been made and that address is used. If the  
    827                 socket is blocking and there is no buffer space left,  
     824                Send data to a specific destination Address. If the 
     825                destination address is not specified, a connection 
     826                must have been made and that address is used. If the 
     827                socket is blocking and there is no buffer space left, 
    828828                sendTo waits. 
    829829 
     
    859859        /*********************************************************************** 
    860860 
    861                 Send data to a specific destination Address. If the  
    862                 destination address is not specified, a connection  
    863                 must have been made and that address is used. If the  
    864                 socket is blocking and there is no buffer space left,  
     861                Send data to a specific destination Address. If the 
     862                destination address is not specified, a connection 
     863                must have been made and that address is used. If the 
     864                socket is blocking and there is no buffer space left, 
    865865                sendTo waits. 
    866866 
     
    874874                version (Posix) 
    875875                        { 
    876                         auto ret = .sendto (sock, buf.ptr, buf.length,  
     876                        auto ret = .sendto (sock, buf.ptr, buf.length, 
    877877                                            flags | SocketFlags.NOSIGNAL, to, len); 
    878878                        if (errno is EPIPE) 
     
    885885 
    886886        /*********************************************************************** 
    887                 Receive data on the connection. Returns the number of  
    888                 bytes actually received, 0 if the remote side has closed  
    889                 the connection, or ERROR on failure. If the socket is blocking,  
     887                Receive data on the connection. Returns the number of 
     888                bytes actually received, 0 if the remote side has closed 
     889                the connection, or ERROR on failure. If the socket is blocking, 
    890890                receive waits until there is data to be received. 
    891                  
    892                 Returns number of bytes actually received, 0 on connection  
     891 
     892                Returns number of bytes actually received, 0 on connection 
    893893                closure, or -1 on error 
    894894 
     
    905905        /*********************************************************************** 
    906906 
    907                 Receive data and get the remote endpoint Address. Returns  
    908                 the number of bytes actually received, 0 if the remote side  
    909                 has closed the connection, or ERROR on failure. If the socket  
    910                 is blocking, receiveFrom waits until there is data to be  
     907                Receive data and get the remote endpoint Address. Returns 
     908                the number of bytes actually received, 0 if the remote side 
     909                has closed the connection, or ERROR on failure. If the socket 
     910                is blocking, receiveFrom waits until there is data to be 
    911911                received. 
    912912 
     
    10031003                        synchronous = yes; 
    10041004                        } 
    1005                      else  
     1005                     else 
    10061006                        { 
    10071007                        int x = fcntl(sock, F_GETFL, 0); 
     
    10131013                           exception("Unable to set socket blocking: "); 
    10141014                        } 
    1015                 return;  
     1015                return; 
    10161016        } 
    10171017 
     
    10501050        } 
    10511051 
    1052         struct addrinfo  
    1053         {  
    1054                 int       ai_flags;  
    1055                 int       ai_family;  
    1056                 int       ai_socktype;  
    1057                 int       ai_protocol;  
    1058                 uint      ai_addrlen;  
     1052        struct addrinfo 
     1053        { 
     1054                int       ai_flags; 
     1055                int       ai_family; 
     1056                int       ai_socktype; 
     1057                int       ai_protocol; 
     1058                uint      ai_addrlen; 
    10591059                version (freebsd) 
    10601060                        { 
    1061                         char*     ai_canonname;  
    1062                         sockaddr* ai_addr;  
     1061                        char*     ai_canonname; 
     1062                        sockaddr* ai_addr; 
    10631063                        } 
    10641064                     else 
    10651065                        { 
    1066                         sockaddr* ai_addr;  
    1067                         char*     ai_canonname;  
     1066                        sockaddr* ai_addr; 
     1067                        char*     ai_canonname; 
    10681068                        } 
    1069                 addrinfo* ai_next;  
    1070         }  
     1069                addrinfo* ai_next; 
     1070        } 
    10711071 
    10721072        abstract sockaddr*      name(); 
     
    11621162                throw new SocketException (msg); 
    11631163        } 
    1164                  
     1164 
    11651165        /*********************************************************************** 
    11661166 
     
    11691169        ***********************************************************************/ 
    11701170 
    1171         static Address create (sockaddr* sa)  
    1172         {  
    1173                 switch  (sa.sa_family)  
    1174                         {  
    1175                         case AddressFamily.INET:  
    1176                              return new IPv4Address(sa);  
    1177                         case AddressFamily.INET6:  
    1178                              return new IPv6Address(sa);  
    1179                         default:  
    1180                              return null;  
    1181                         }  
    1182         }  
    1183                  
    1184         /***********************************************************************  
    1185    
    1186         ***********************************************************************/  
    1187           
    1188         static Address resolve (char[] host, char[] service = null,  
    1189                                 AddressFamily af = AddressFamily.UNSPEC,  
    1190                                 AIFlags flags = cast(AIFlags)0)  
    1191         {  
    1192                 return resolveAll (host, service, af, flags)[0];  
    1193         }  
    1194           
    1195         /***********************************************************************  
    1196    
    1197         ***********************************************************************/  
    1198           
    1199         static Address resolve (char[] host, ushort port,  
    1200                                 AddressFamily af = AddressFamily.UNSPEC,  
    1201                                 AIFlags flags = cast(AIFlags)0)  
    1202         {  
    1203                 return resolveAll (host, port, af, flags)[0];  
    1204         }  
    1205           
    1206         /***********************************************************************  
    1207    
    1208         ***********************************************************************/  
    1209           
    1210         static Address[] resolveAll (char[] host, char[] service = null,  
    1211                                      AddressFamily af = AddressFamily.UNSPEC,  
    1212                                      AIFlags flags = cast(AIFlags)0)  
    1213         {  
    1214                 Address[] retVal;  
    1215                 version (Win32)  
    1216                         {  
    1217                         if (!getaddrinfo)  
    1218                            { // *old* windows, let's fall back to NetHost  
    1219                            uint port = toInt(service);  
    1220                            if (flags & AIFlags.PASSIVE && host is null)  
    1221                                return [new IPv4Address(0, port)];  
    1222  
    1223                            auto nh = new NetHost;  
    1224                            if (!nh.getHostByName(host))  
    1225                                 throw new AddressException("couldn't resolve " ~ host);  
    1226  
    1227                            retVal.length = nh.addrList.length;  
     1171        static Address create (sockaddr* sa) 
     1172        { 
     1173                switch  (sa.sa_family) 
     1174                        { 
     1175                        case AddressFamily.INET: 
     1176                             return new IPv4Address(sa); 
     1177                        case AddressFamily.INET6: 
     1178                             return new IPv6Address(sa); 
     1179                        default: 
     1180                             return null; 
     1181                        } 
     1182        } 
     1183 
     1184        /*********************************************************************** 
     1185 
     1186        ***********************************************************************/ 
     1187 
     1188        static Address resolve (char[] host, char[] service = null, 
     1189                                AddressFamily af = AddressFamily.UNSPEC, 
     1190                                AIFlags flags = cast(AIFlags)0) 
     1191        { 
     1192                return resolveAll (host, service, af, flags)[0]; 
     1193        } 
     1194 
     1195        /*********************************************************************** 
     1196 
     1197        ***********************************************************************/ 
     1198 
     1199        static Address resolve (char[] host, ushort port, 
     1200                                AddressFamily af = AddressFamily.UNSPEC, 
     1201                                AIFlags flags = cast(AIFlags)0) 
     1202        { 
     1203                return resolveAll (host, port, af, flags)[0]; 
     1204        } 
     1205 
     1206        /*********************************************************************** 
     1207 
     1208        ***********************************************************************/ 
     1209 
     1210        static Address[] resolveAll (char[] host, char[] service = null, 
     1211                                     AddressFamily af = AddressFamily.UNSPEC, 
     1212                                     AIFlags flags = cast(AIFlags)0) 
     1213        { 
     1214                Address[] retVal; 
     1215                version (Win32) 
     1216                        { 
     1217                        if (!getaddrinfo) 
     1218                           { // *old* windows, let's fall back to NetHost 
     1219                           uint port = toInt(service); 
     1220                           if (flags & AIFlags.PASSIVE && host is null) 
     1221                               return [new IPv4Address(0, port)]; 
     1222 
     1223                           auto nh = new NetHost; 
     1224                           if (!nh.getHostByName(host)) 
     1225                                throw new AddressException("couldn't resolve " ~ host); 
     1226 
     1227                           retVal.length = nh.addrList.length; 
    12281228                           foreach (i, addr; nh.addrList) 
    1229                                     retVal[i] = new IPv4Address(addr, port);  
    1230                            return retVal;  
    1231                            }  
    1232                         }  
    1233  
    1234                 addrinfo* info;  
    1235                 addrinfo hints;  
    1236                 hints.ai_flags = flags;  
    1237                 hints.ai_family = (flags & AIFlags.PASSIVE && af == AddressFamily.UNSPEC) ? AddressFamily.INET6 : af;  
    1238                 hints.ai_socktype = SocketType.STREAM;  
    1239                 int error = getaddrinfo(toStringz(host), service.length == 0 ? null : toStringz(service), &hints, &info);  
    1240                 if (error != 0)   
    1241                     throw new AddressException("couldn't resolve " ~ host);  
    1242  
    1243                 retVal.length = 16;  
    1244                 retVal.length = 0;  
    1245                 while (info)  
    1246                       {  
    1247                       if (auto addr = create(info.ai_addr))  
    1248                           retVal ~= addr;  
    1249                       info = info.ai_next;  
    1250                       }  
    1251                 freeaddrinfo (info);  
    1252                 return retVal;  
    1253         }  
    1254           
    1255         /***********************************************************************  
    1256    
    1257         ***********************************************************************/  
    1258           
    1259         static Address[] resolveAll (char host[], ushort port,  
    1260                                      AddressFamily af = AddressFamily.UNSPEC,  
    1261                                      AIFlags flags = cast(AIFlags)0)  
    1262         {  
    1263                 char[16] buf;  
    1264                 return resolveAll (host, fromInt(buf, port), af, flags);  
    1265         }  
    1266           
    1267         /***********************************************************************  
    1268    
    1269         ***********************************************************************/  
    1270           
    1271         static Address passive (char[] service,  
    1272                                 AddressFamily af = AddressFamily.UNSPEC,  
    1273                                 AIFlags flags = cast(AIFlags)0)  
    1274         {  
    1275                 return resolve (null, service, af, flags | AIFlags.PASSIVE);  
    1276         }  
    1277           
    1278         /***********************************************************************  
    1279   
    1280          ***********************************************************************/  
    1281           
    1282         static Address passive (ushort port, AddressFamily af = AddressFamily.UNSPEC,  
    1283                                 AIFlags flags = cast(AIFlags)0)  
    1284         {  
    1285                 return resolve (null, port, af, flags | AIFlags.PASSIVE);  
    1286         }  
    1287           
    1288         /***********************************************************************  
    1289    
    1290         ***********************************************************************/  
    1291   
    1292         char[] toAddrString()  
    1293         {  
    1294                 char[1025] host = void;  
    1295                 // Getting name info. Don't look up hostname, returns  
     1229                                    retVal[i] = new IPv4Address(addr, port); 
     1230                           return retVal; 
     1231                           } 
     1232                        } 
     1233 
     1234                addrinfo* info; 
     1235                addrinfo hints; 
     1236                hints.ai_flags = flags; 
     1237                hints.ai_family = (flags & AIFlags.PASSIVE && af == AddressFamily.UNSPEC) ? AddressFamily.INET6 : af; 
     1238                hints.ai_socktype = SocketType.STREAM; 
     1239                int error = getaddrinfo(toStringz(host), service.length == 0 ? null : toStringz(service), &hints, &info); 
     1240                if (error != 0) 
     1241                    throw new AddressException("couldn't resolve " ~ host); 
     1242 
     1243                retVal.length = 16; 
     1244                retVal.length = 0; 
     1245                while (info) 
     1246                      { 
     1247                      if (auto addr = create(info.ai_addr)) 
     1248                          retVal ~= addr; 
     1249                      info = info.ai_next; 
     1250                      } 
     1251                freeaddrinfo (info); 
     1252                return retVal; 
     1253        } 
     1254 
     1255        /*********************************************************************** 
     1256 
     1257        ***********************************************************************/ 
     1258 
     1259        static Address[] resolveAll (char host[], ushort port, 
     1260                                     AddressFamily af = AddressFamily.UNSPEC, 
     1261                                     AIFlags flags = cast(AIFlags)0) 
     1262        { 
     1263                char[16] buf; 
     1264                return resolveAll (host, fromInt(buf, port), af, flags); 
     1265        } 
     1266 
     1267        /*********************************************************************** 
     1268 
     1269        ***********************************************************************/ 
     1270 
     1271        static Address passive (char[] service, 
     1272                                AddressFamily af = AddressFamily.UNSPEC, 
     1273                                AIFlags flags = cast(AIFlags)0) 
     1274        { 
     1275                return resolve (null, service, af, flags | AIFlags.PASSIVE); 
     1276        } 
     1277 
     1278        /*********************************************************************** 
     1279 
     1280         ***********************************************************************/ 
     1281 
     1282        static Address passive (ushort port, AddressFamily af = AddressFamily.UNSPEC, 
     1283                                AIFlags flags = cast(AIFlags)0) 
     1284        { 
     1285                return resolve (null, port, af, flags | AIFlags.PASSIVE); 
     1286        } 
     1287 
     1288        /*********************************************************************** 
     1289 
     1290        ***********************************************************************/ 
     1291 
     1292        char[] toAddrString() 
     1293        { 
     1294                char[1025] host = void; 
     1295                // Getting name info. Don't look up hostname, returns 
    12961296                // numeric name. (NIFlags.NUMERICHOST) 
    1297                 getnameinfo (name, nameLen, host.ptr, host.length, null, 0, NIFlags.NUMERICHOST);  
    1298                 return fromStringz (host.ptr);  
    1299         }  
    1300   
    1301         /***********************************************************************  
    1302   
    1303          ***********************************************************************/  
    1304   
    1305         char[] toPortString()  
    1306         {  
    1307                 char[32] service = void;  
    1308                 // Getting name info. Returns port number, not  
     1297                getnameinfo (name, nameLen, host.ptr, host.length, null, 0, NIFlags.NUMERICHOST); 
     1298                return fromStringz (host.ptr); 
     1299        } 
     1300 
     1301        /*********************************************************************** 
     1302 
     1303         ***********************************************************************/ 
     1304 
     1305        char[] toPortString() 
     1306        { 
     1307                char[32] service = void; 
     1308                // Getting name info. Returns port number, not 
    13091309                // service name. (NIFlags.NUMERICSERV) 
    1310                 getnameinfo (name, nameLen, null, 0, service.ptr, service.length, NIFlags.NUMERICSERV);  
    1311                 foreach (i, c; service)   
    1312                          if (c == '\0')   
    1313                              return service[0..i].dup;  
     1310                getnameinfo (name, nameLen, null, 0, service.ptr, service.length, NIFlags.NUMERICSERV); 
     1311                foreach (i, c; service) 
     1312                         if (c == '\0') 
     1313                             return service[0..i].dup; 
    13141314                return null; 
    1315         }  
    1316            
    1317         /***********************************************************************  
    1318    
    1319         ***********************************************************************/  
    1320   
    1321         char[] toString()  
    1322         {  
    1323                 return toAddrString ~ ":" ~ toPortString;  
    1324         }  
    1325                    
    1326         /***********************************************************************  
    1327   
    1328          ***********************************************************************/  
    1329   
    1330         AddressFamily addressFamily()  
    1331         {  
    1332                 return cast(AddressFamily)name.sa_family;  
    1333         }  
     1315        } 
     1316 
     1317        /*********************************************************************** 
     1318 
     1319        ***********************************************************************/ 
     1320 
     1321        char[] toString() 
     1322        { 
     1323                return toAddrString ~ ":" ~ toPortString; 
     1324        } 
     1325 
     1326        /*********************************************************************** 
     1327 
     1328         ***********************************************************************/ 
     1329 
     1330        AddressFamily addressFamily() 
     1331        { 
     1332                return cast(AddressFamily)name.sa_family; 
     1333        } 
    13341334} 
    13351335 
     
    13921392        ***********************************************************************/ 
    13931393 
    1394         enum  
    1395         { 
    1396                 ADDR_ANY = 0,  
    1397                 ADDR_NONE = cast(uint)-1,  
     1394        enum 
     1395        { 
     1396                ADDR_ANY = 0, 
     1397                ADDR_NONE = cast(uint)-1, 
    13981398                PORT_ANY = 0 
    13991399        } 
     
    14091409                        ubyte sin_len; 
    14101410                        ubyte sinfamily  = AddressFamily.INET; 
    1411                         }  
    1412                      else  
     1411                        } 
     1412                     else 
    14131413                        { 
    14141414                        ushort sinfamily = AddressFamily.INET; 
     
    14791479        ***********************************************************************/ 
    14801480 
    1481         this (sockaddr* addr)  
    1482         {  
    1483                 sin = *(cast(sockaddr_in*)addr);  
    1484         }  
    1485                  
    1486         /*********************************************************************** 
    1487  
    1488         ***********************************************************************/ 
    1489                  
     1481        this (sockaddr* addr) 
     1482        { 
     1483                sin = *(cast(sockaddr_in*)addr); 
     1484        } 
     1485 
     1486        /*********************************************************************** 
     1487 
     1488        ***********************************************************************/ 
     1489 
    14901490        sockaddr* name() 
    14911491        { 
     
    15901590} 
    15911591 
    1592 /*******************************************************************************  
    1593          
     1592/******************************************************************************* 
     1593 
    15941594        IPv6 is the next-generation Internet Protocol version 
    15951595        designated as the successor to IPv4, the first 
    15961596        implementation used in the Internet that is still in 
    15971597        dominant use currently. 
    1598                          
     1598 
    15991599        More information: http://ipv6.com/ 
    1600                  
     1600 
    16011601        IPv6 supports 128-bit address space as opposed to 32-bit 
    16021602        address space of IPv4. 
    1603                  
     1603 
    16041604        IPv6 is written as 8 blocks of 4 octal digits (16 bit) 
    16051605        separated by a colon (":"). Zero block can be replaced by "::". 
    1606                          
    1607         For example:  
     1606 
     1607        For example: 
    16081608        --- 
    16091609        0000:0000:0000:0000:0000:0000:0000:0001 
     
    16131613        ::1 
    16141614        is analogue IPv4 127.0.0.1 
    1615                  
     1615 
    16161616        0000:0000:0000:0000:0000:0000:0000:0000 
    16171617        is equal 
    16181618        :: 
    16191619        is analogue IPv4 0.0.0.0 
    1620                  
    1621         2001:cdba:0000:0000:0000:0000:3257:9652  
     1620 
     1621        2001:cdba:0000:0000:0000:0000:3257:9652 
    16221622        is equal 
    16231623        2001:cdba::3257:9652 
    1624                  
     1624 
    16251625        IPv4 address can be submitted through IPv6 as ::ffff:xx.xx.xx.xx, 
    16261626        where xx.xx.xx.xx 32-bit IPv4 addresses. 
    1627                  
     1627 
    16281628        ::ffff:51b0:ec6d 
    16291629        is equal 
    16301630        ::ffff:81.176.236.109 
    16311631        is analogue IPv4 81.176.236.109 
    1632                  
     1632 
    16331633        The URL for the IPv6 address will be of the form: 
    16341634        http://[2001:cdba:0000:0000:0000:0000:3257:9652]/ 
    1635                  
     1635 
    16361636        If needed to specify a port, it will be listed after the 
    16371637        closing square bracket followed by a colon. 
    1638                  
     1638 
    16391639        http://[2001:cdba:0000:0000:0000:0000:3257:9652]:8080/ 
    16401640        address: "2001:cdba:0000:0000:0000:0000:3257:9652" 
    16411641        port: 8080 
    1642                  
     1642 
    16431643        IPv6Address can be used as well as IPv4Address. 
    1644                  
    1645         scope addr = new IPv6Address(8080);  
     1644 
     1645        scope addr = new IPv6Address(8080); 
    16461646        address: "::" 
    16471647        port: 8080 
    1648                  
    1649         scope addr_2 = new IPv6Address("::1", 8081);  
     1648 
     1649        scope addr_2 = new IPv6Address("::1", 8081); 
    16501650        address: "::1" 
    16511651        port: 8081 
    1652                  
    1653         scope addr_3 = new IPv6Address("::1");  
     1652 
     1653        scope addr_3 = new IPv6Address("::1"); 
    16541654        address: "::1" 
    16551655        port: PORT_ANY 
    1656                  
     1656 
    16571657        Also in the IPv6Address constructor can specify the service name 
    16581658        or port as string 
    1659                  
    1660         scope addr_3 = new IPv6Address("::", "ssh");  
     1659 
     1660        scope addr_3 = new IPv6Address("::", "ssh"); 
    16611661        address: "::" 
    16621662        port: 22 (ssh service port) 
    1663                  
    1664         scope addr_4 = new IPv6Address("::", "8080");  
     1663 
     1664        scope addr_4 = new IPv6Address("::", "8080"); 
    16651665        address: "::" 
    16661666        port: 8080 
    1667                  
    1668 *******************************************************************************/  
    1669                  
    1670 class IPv6Address : Address  
    1671 {  
     1667 
     1668*******************************************************************************/ 
     1669 
     1670class IPv6Address : Address 
     1671{ 
    16721672protected: 
    1673         /***********************************************************************  
    1674           
    1675         ***********************************************************************/  
    1676   
    1677         struct sockaddr_in6  
    1678         {  
    1679                 ushort sin_family;  
    1680                 ushort sin_port;  
    1681                   
    1682                 uint sin6_flowinfo;  
    1683                 ubyte[16] sin6_addr;  
    1684                 uint sin6_scope_id;  
    1685         }  
    1686           
    1687         sockaddr_in6 sin;  
    1688   
    1689         /***********************************************************************  
    1690   
    1691          ***********************************************************************/  
    1692   
    1693         this ()  
    1694         {  
    1695         }  
    1696   
    1697         /*********************************************************************** 
    1698  
    1699         ***********************************************************************/ 
    1700  
    1701         this (sockaddr* sa)  
    1702         {  
    1703                 sin = *cast(sockaddr_in6*)sa;  
    1704         }  
    1705           
    1706         /***********************************************************************  
    1707   
    1708         ***********************************************************************/  
    1709   
    1710         sockaddr* name()  
    1711         {  
    1712                 return cast(sockaddr*)&sin;  
    1713         }  
    1714   
    1715         /***********************************************************************  
    1716   
    1717         ***********************************************************************/  
    1718   
    1719         int nameLen()  
    1720         {  
    1721                 return sin.sizeof;  
    1722         }  
    1723   
    1724  public:  
     1673        /*********************************************************************** 
     1674 
     1675        ***********************************************************************/ 
     1676 
     1677        struct sockaddr_in6 
     1678        { 
     1679                ushort sin_family; 
     1680                ushort sin_port; 
     1681 
     1682                uint sin6_flowinfo; 
     1683                ubyte[16] sin6_addr; 
     1684                uint sin6_scope_id; 
     1685        } 
     1686 
     1687        sockaddr_in6 sin; 
     1688 
     1689        /*********************************************************************** 
     1690 
     1691         ***********************************************************************/ 
     1692 
     1693        this () 
     1694        { 
     1695        } 
     1696 
     1697        /*********************************************************************** 
     1698 
     1699        ***********************************************************************/ 
     1700 
     1701        this (sockaddr* sa) 
     1702        { 
     1703                sin = *cast(sockaddr_in6*)sa; 
     1704        } 
     1705 
     1706        /*********************************************************************** 
     1707 
     1708        ***********************************************************************/ 
     1709 
     1710        sockaddr* name() 
     1711        { 
     1712                return cast(sockaddr*)&sin; 
     1713        } 
     1714 
     1715        /*********************************************************************** 
     1716 
     1717        ***********************************************************************/ 
     1718 
     1719        int nameLen() 
     1720        { 
     1721                return sin.sizeof; 
     1722        } 
     1723 
     1724 public: 
    17251725 
    17261726        /*********************************************************************** 
     
    17331733        } 
    17341734 
    1735   
    1736         const ushort PORT_ANY = 0;  
    1737    
    1738         /***********************************************************************  
    1739   
    1740          ***********************************************************************/  
    1741   
    1742         ushort port()  
    1743         {  
    1744                 return ntohs(sin.sin_port);  
    1745         }  
    1746                  
    1747         /***********************************************************************  
    1748   
     1735 
     1736        const ushort PORT_ANY = 0; 
     1737 
     1738        /*********************************************************************** 
     1739 
     1740         ***********************************************************************/ 
     1741 
     1742        ushort port() 
     1743        { 
     1744                return ntohs(sin.sin_port); 
     1745        } 
     1746 
     1747        /*********************************************************************** 
     1748 
    17491749                Create IPv6Address with zero address 
    17501750 
    1751         ***********************************************************************/  
    1752                  
    1753         this (int port)  
    1754         {  
     1751        ***********************************************************************/ 
     1752 
     1753        this (int port) 
     1754        { 
    17551755          this ("::", port); 
    1756         }  
    1757                  
    1758         /***********************************************************************  
    1759   
    1760                 -port- can be PORT_ANY  
    1761                 -addr- is an IP address or host name  
    1762   
    1763         ***********************************************************************/  
    1764                  
    1765         this (char[] addr, int port = PORT_ANY)  
    1766         {  
    1767                 version (Win32)  
    1768                         {  
    1769                         if (!getaddrinfo)  
    1770                              exception ("This platform does not support IPv6.");  
    1771                         }  
    1772                 addrinfo* info;  
    1773                 addrinfo hints;  
    1774                 hints.ai_family = AddressFamily.INET6;  
    1775                 int error = getaddrinfo((addr ~ '\0').ptr, null, &hints, &info);  
    1776                 if (error != 0)   
    1777                     exception("failed to create IPv6Address: ");  
    1778                   
    1779                 sin = *cast(sockaddr_in6*)(info.ai_addr);  
    1780                 sin.sin_port = htons(cast(ushort) port);  
    1781         }  
    1782                 
    1783         /***********************************************************************  
    1784   
    1785                 -service- can be a port number or service name  
    1786                 -addr- is an IP address or host name  
    1787   
    1788         ***********************************************************************/  
    1789   
    1790         this (char[] addr, char[] service)  
    1791         {  
    1792                 version (Win32)  
    1793                         {  
    1794                         if(! getaddrinfo)  
    1795                              exception ("This platform does not support IPv6.");  
    1796                         }  
    1797                 addrinfo* info;  
    1798                 addrinfo hints;  
    1799                 hints.ai_family = AddressFamily.INET6;  
    1800                 int error = getaddrinfo((addr ~ '\0').ptr, (service ~ '\0').ptr, &hints, &info);  
    1801                 if (error != 0)   
    1802                     exception ("failed to create IPv6Address: ");  
    1803                 sin = *cast(sockaddr_in6*)(info.ai_addr);  
    1804         }  
    1805   
    1806         /***********************************************************************  
    1807    
    1808         ***********************************************************************/  
    1809   
    1810         ubyte[] addr()  
    1811         {  
    1812                 return sin.sin6_addr;  
    1813         }  
    1814   
    1815         /***********************************************************************  
    1816    
    1817         ***********************************************************************/  
    1818   
     1756        } 
     1757 
     1758        /*********************************************************************** 
     1759 
     1760                -port- can be PORT_ANY 
     1761                -addr- is an IP address or host name 
     1762 
     1763        ***********************************************************************/ 
     1764 
     1765        this (char[] addr, int port = PORT_ANY) 
     1766        { 
     1767                version (Win32) 
     1768                        { 
     1769                        if (!getaddrinfo) 
     1770                             exception ("This platform does not support IPv6."); 
     1771                        } 
     1772                addrinfo* info; 
     1773                addrinfo hints; 
     1774                hints.ai_family = AddressFamily.INET6; 
     1775                int error = getaddrinfo((addr ~ '\0').ptr, null, &hints, &info); 
     1776                if (error != 0) 
     1777                    exception("failed to create IPv6Address: "); 
     1778 
     1779                sin = *cast(sockaddr_in6*)(info.ai_addr); 
     1780                sin.sin_port = htons(cast(ushort) port); 
     1781        } 
     1782 
     1783        /*********************************************************************** 
     1784 
     1785                -service- can be a port number or service name 
     1786                -addr- is an IP address or host name 
     1787 
     1788        ***********************************************************************/ 
     1789 
     1790        this (char[] addr, char[] service) 
     1791        { 
     1792                version (Win32) 
     1793                        { 
     1794                        if(! getaddrinfo) 
     1795                             exception ("This platform does not support IPv6."); 
     1796                        } 
     1797                addrinfo* info; 
     1798                addrinfo hints; 
     1799                hints.ai_family = AddressFamily.INET6; 
     1800                int error = getaddrinfo((addr ~ '\0').ptr, (service ~ '\0').ptr, &hints, &info); 
     1801                if (error != 0) 
     1802                    exception ("failed to create IPv6Address: "); 
     1803                sin = *cast(sockaddr_in6*)(info.ai_addr); 
     1804        } 
     1805 
     1806        /*********************************************************************** 
     1807 
     1808        ***********************************************************************/ 
     1809 
     1810        ubyte[] addr() 
     1811        { 
     1812                return sin.sin6_addr; 
     1813        } 
     1814 
     1815        /*********************************************************************** 
     1816 
     1817        ***********************************************************************/ 
     1818 
    18191819        version (Posix) 
    18201820        char[] toAddrString() 
    18211821        { 
    1822                  
     1822 
    18231823                char[100] buff = 0; 
    18241824                return fromStringz(inet_ntop(AddressFamily.INET6, &sin.sin6_addr, buff.ptr, 100)).dup; 
     
    18341834                return fromInt (_port, port()).dup; 
    18351835        } 
    1836   
    1837         /*********************************************************************** 
    1838  
    1839         ***********************************************************************/ 
    1840  
    1841         char[] toString()  
    1842         {  
    1843                 return "[" ~ toAddrString ~ "]:" ~ toPortString;  
    1844         }  
    1845 }  
     1836 
     1837        /*********************************************************************** 
     1838 
     1839        ***********************************************************************/ 
     1840 
     1841        char[] toString() 
     1842        { 
     1843                return "[" ~ toAddrString ~ "]:" ~ toPortString; 
     1844        } 
     1845} 
    18461846 
    18471847/******************************************************************************* 
     
    18841884                        short h_length; 
    18851885                        } 
    1886                      else  
     1886                     else 
    18871887                        { 
    18881888                        int h_addrtype; 
     
    20242024        assert(ih.addrList.length > 0); 
    20252025        IPv4Address ia = new IPv4Address(ih.addrList[0], IPv4Address.PORT_ANY); 
     2026        printf("addrses: %x %x\n", ia.toAddrString.ptr, ih.name.ptr); 
    20262027        printf("IP address = %.*s\nname = %.*s\n", ia.toAddrString(), ih.name); 
    20272028        foreach(int i, char[] s; ih.aliases) 
     
    20542055        struct timeval 
    20552056        { 
    2056                 c_long  seconds, microseconds;  
     2057                c_long  seconds, microseconds; 
    20572058        } 
    20582059 
     
    21382139        } 
    21392140 
    2140         this (SocketSet o)  
     2141        this (SocketSet o) 
    21412142        { 
    21422143                nbytes = o.nbytes; 
    21432144                auto size = nbytes; 
    2144                 version (Win32)  
     2145                version (Win32) 
    21452146                         size += uint.sizeof; 
    21462147 
    2147                 version (Posix)  
     2148                version (Posix) 
    21482149                        { 
    21492150                        nfdbits = o.nfdbits; 
    21502151                        _maxfd = o._maxfd; 
    21512152                        } 
    2152                  
     2153 
    21532154                auto b = new byte[size]; 
    21542155                b[] = o.buf[0..size]; 
     
    21722173        } 
    21732174 
    2174         SocketSet dup()  
     2175        SocketSet dup() 
    21752176        { 
    21762177                return new SocketSet (this); 
    21772178        } 
    2178          
     2179 
    21792180        SocketSet reset() 
    21802181        { 
     
    24082409 
    24092410        static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, long microseconds) 
    2410         {        
     2411        { 
    24112412                timeval tv = { 
    2412                              cast(typeof(timeval.seconds)) (microseconds / 1000000),  
     2413                             cast(typeof(timeval.seconds)) (microseconds / 1000000), 
    24132414                             cast(typeof(timeval.microseconds)) (microseconds % 1000000) 
    24142415                             }; 
  • trunk/tango/net/http/HttpConst.d

    r3686 r5652  
    156156        GatewayTimeout               = 504, 
    157157        VersionNotSupported          = 505, 
    158 }; 
     158} 
    159159 
    160160/******************************************************************************* 
     
    178178struct HttpResponses 
    179179{        
     180const: 
    180181        static HttpStatus Continue                     = {HttpResponseCode.Continue, "Continue"}; 
    181182        static HttpStatus SwitchingProtocols           = {HttpResponseCode.SwitchingProtocols, "SwitchingProtocols"}; 
  • trunk/tango/stdc/posix/netinet/in_.d

    r4378 r5652  
    1717 
    1818// 
    19 // Required     
     19// Required 
    2020// 
    2121/* 
     
    223223        } 
    224224    } 
    225      
     225 
    226226    struct sockaddr_in6 
    227227    { 
     
    232232        uint32_t    sin6_scope_id; 
    233233    } 
    234      
     234 
    235235    extern in6_addr in6addr_any; 
    236236    extern in6_addr in6addr_loopback; 
    237      
     237 
    238238    struct ipv6_mreq 
    239239    { 
     
    241241        uint        ipv6mr_interface; 
    242242    } 
    243      
     243 
    244244    enum : uint 
    245245    { 
    246246        IPPROTO_IPV6        = 41, 
    247      
     247 
    248248        INET6_ADDRSTRLEN    = 46, 
    249      
     249 
    250250        IPV6_JOIN_GROUP     = 20, 
    251251        IPV6_LEAVE_GROUP    = 21, 
     
    345345        } 
    346346    } 
    347      
     347 
    348348    struct sockaddr_in6 
    349349    { 
     
    355355        uint32_t    __sin6_src_id;  /* Impl. specific - UDP replies */ 
    356356    } 
    357      
     357 
    358358    extern in6_addr in6addr_any; 
    359359    extern in6_addr in6addr_loopback; 
    360      
     360 
    361361    struct ipv6_mreq 
    362362    { 
     
    364364        uint        ipv6mr_interface; 
    365365    } 
    366      
     366 
    367367    enum : uint 
    368368    { 
    369369        IPPROTO_IPV6        = 41, 
    370      
     370 
    371371        INET6_ADDRSTRLEN    = 46, 
    372      
     372 
    373373        IPV6_JOIN_GROUP     = 0x9, 
    374374        IPV6_LEAVE_GROUP    = 0xa, 
     
    395395        version(BigEndian)  enum : uint { N = 0x00000001 } 
    396396        else                enum : uint { N = 0x01000000 } 
    397          
     397 
    398398        return addr.s6_addr32[3] == N && 
    399399               addr.s6_addr32[2] == 0 && 
     
    411411    { 
    412412        version(BigEndian) 
    413             return addr.s6_addr32[0] & 0xff000000 == 0xff000000; 
    414         else 
    415             return addr.s6_addr32[0] & 0x000000ff == 0x000000ff; 
     413            return (addr.s6_addr32[0] & 0xff000000) == 0xff000000; 
     414        else 
     415            return (addr.s6_addr32[0] & 0x000000ff) == 0x000000ff; 
    416416    } 
    417417 
     
    419419    { 
    420420        version(BigEndian) 
    421             return addr.s6_addr32[0] & 0xffc00000 == 0xfe800000; 
    422         else 
    423             return addr.s6_addr32[0] & 0x0000c0ff == 0x000080fe; 
     421            return (addr.s6_addr32[0] & 0xffc00000) == 0xfe800000; 
     422        else 
     423            return (addr.s6_addr32[0] & 0x0000c0ff) == 0x000080fe; 
    424424    } 
    425425 
     
    427427    { 
    428428        version(BigEndian) 
    429             return addr.s6_addr32[0] & 0xffc00000 == 0xfec00000; 
    430         else 
    431             return addr.s6_addr32[0] & 0x0000c0ff == 0x0000c0fe; 
     429            return (addr.s6_addr32[0] & 0xffc00000) == 0xfec00000; 
     430        else 
     431            return (addr.s6_addr32[0] & 0x0000c0ff) == 0x0000c0fe; 
    432432    } 
    433433 
     
    436436        version(BigEndian)  enum : uint { N = 0x0000ffff } 
    437437        else                enum : uint { N = 0xffff0000 } 
    438          
     438 
    439439        return addr.s6_addr32[2] == N && 
    440440               addr.s6_addr32[1] == 0 && 
     
    446446        version(BigEndian)  enum : uint { N = 0x00000001 } 
    447447        else                enum : uint { N = 0x01000000 } 
    448          
     448 
    449449        return addr.s6_addr32[2] == 0 && 
    450450               addr.s6_addr32[1] == 0 && 
     
    457457    { 
    458458        version(BigEndian) 
    459             return addr.s6_addr32[0] & 0xff0f0000 == 0xff010000; 
    460         else 
    461             return addr.s6_addr32[0] & 0x00000fff == 0x000001ff; 
     459            return (addr.s6_addr32[0] & 0xff0f0000) == 0xff010000; 
     460        else 
     461            return (addr.s6_addr32[0] & 0x00000fff) == 0x000001ff; 
    462462    } 
    463463 
     
    465465    { 
    466466        version(BigEndian) 
    467             return addr.s6_addr32[0] & 0xff0f0000 == 0xff020000; 
    468         else 
    469             return addr.s6_addr32[0] & 0x00000fff == 0x000002ff; 
     467            return (addr.s6_addr32[0] & 0xff0f0000) == 0xff020000; 
     468        else 
     469            return (addr.s6_addr32[0] & 0x00000fff) == 0x000002ff; 
    470470    } 
    471471 
     
    473473    { 
    474474        version(BigEndian) 
    475             return addr.s6_addr32[0] & 0xff0f0000 == 0xff050000; 
    476         else 
    477             return addr.s6_addr32[0] & 0x00000fff == 0x000005ff; 
     475            return (addr.s6_addr32[0] & 0xff0f0000) == 0xff050000; 
     476        else 
     477            return (addr.s6_addr32[0] & 0x00000fff) == 0x000005ff; 
    478478    } 
    479479 
     
    481481    { 
    482482        version(BigEndian) 
    483             return addr.s6_addr32[0] & 0xff0f0000 == 0xff080000; 
    484         else 
    485             return addr.s6_addr32[0] & 0x00000fff == 0x000008ff; 
     483            return (addr.s6_addr32[0] & 0xff0f0000) == 0xff080000; 
     484        else 
     485            return (addr.s6_addr32[0] & 0x00000fff) == 0x000008ff; 
    486486    } 
    487487 
     
    489489    { 
    490490        version(BigEndian) 
    491             return addr.s6_addr32[0] & 0xff0f0000 == 0xff0e0000; 
    492         else 
    493             return addr.s6_addr32[0] & 0x00000fff == 0x00000eff; 
     491            return (addr.s6_addr32[0] & 0xff0f0000) == 0xff0e0000; 
     492        else 
     493            return (addr.s6_addr32[0] & 0x00000fff) == 0x00000eff; 
    494494    } 
    495495} 
  • trunk/tango/stdc/stdarg.d

    r5248 r5652  
    1010 
    1111 
     12debug(PRINTF) import tango.stdc.stdio: printf; 
     13 
     14 
    1215version( GNU ) 
    1316{ 
     
    2023else 
    2124{ 
     25version (X86) 
     26{ 
     27    /********************* 
     28     * The argument pointer type. 
     29     */ 
    2230    alias void* va_list; 
    2331 
    24     template va_start( T ) 
    25     { 
    26         void va_start( out va_list ap, ref T parmn ) 
     32    /********** 
     33     * Initialize ap. 
     34     * For 32 bit code, parmn should be the last named parameter. 
     35     * For 64 bit code, parmn should be __va_argsave. 
     36     */ 
     37    void va_start(T)(out va_list ap, ref T parmn) 
     38    { 
     39        ap = cast(va_list)(cast(void*)&parmn + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1))); 
     40    } 
     41 
     42    /************ 
     43     * Retrieve and return the next value that is type T. 
     44     * Should use the other va_arg instead, as this won't work for 64 bit code. 
     45     */ 
     46    T va_arg(T)(ref va_list ap) 
     47    { 
     48        T arg = *cast(T*)ap; 
     49        ap = cast(va_list)(cast(void*)ap + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1))); 
     50        return arg; 
     51    } 
     52 
     53    /************ 
     54     * Retrieve and return the next value that is type T. 
     55     * This is the preferred version. 
     56     */ 
     57    void va_arg(T)(ref va_list ap, ref T parmn) 
     58    { 
     59        parmn = *cast(T*)ap; 
     60        ap = cast(va_list)(cast(void*)ap + ((T.sizeof + int.sizeof - 1) & ~(int.sizeof - 1))); 
     61    } 
     62 
     63    /************* 
     64     * Retrieve and store through parmn the next value that is of TypeInfo ti. 
     65     * Used when the static type is not known. 
     66     */ 
     67    void va_arg()(ref va_list ap, TypeInfo ti, void* parmn) 
     68    { 
     69        // Wait until everyone updates to get TypeInfo.talign() 
     70        //auto talign = ti.talign(); 
     71        //auto p = cast(void*)(cast(size_t)ap + talign - 1) & ~(talign - 1); 
     72        auto p = ap; 
     73        auto tsize = ti.tsize(); 
     74        ap = cast(void*)(cast(size_t)p + ((tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1))); 
     75        parmn[0..tsize] = p[0..tsize]; 
     76    } 
     77 
     78    /*********************** 
     79     * End use of ap. 
     80     */ 
     81    void va_end(va_list ap) 
     82    { 
     83    } 
     84 
     85    void va_copy(out va_list dest, va_list src) 
     86    { 
     87        dest = src; 
     88    } 
     89
     90else version (X86_64) 
     91
     92    // Layout of this struct must match __gnuc_va_list for C ABI compatibility 
     93    struct __va_list 
     94    { 
     95        uint offset_regs = 6 * 8;            // no regs 
     96        uint offset_fpregs = 6 * 8 + 8 * 16; // no fp regs 
     97        void* stack_args; 
     98        void* reg_args; 
     99    } 
     100 
     101    struct __va_argsave_t 
     102    { 
     103        size_t[6] regs;   // RDI,RSI,RDX,RCX,R8,R9 
     104        real[8] fpregs;   // XMM0..XMM7 
     105        __va_list va; 
     106    } 
     107 
     108    /* 
     109     * Making it an array of 1 causes va_list to be passed as a pointer in 
     110     * function argument lists 
     111     */ 
     112    alias void* va_list; 
     113 
     114    void va_start(T)(out va_list ap, ref T parmn) 
     115    { 
     116        ap = &parmn.va; 
     117    } 
     118 
     119    T va_arg(T)(va_list ap) 
     120    {   T a; 
     121        va_arg(ap, a); 
     122        return a; 
     123    } 
     124 
     125    void va_arg(T)(va_list apx, ref T parmn) 
     126    { 
     127        debug(PRINTF) printf("va_arg(T) called\n"); 
     128        __va_list* ap = cast(__va_list*)apx; 
     129        static if (is(T U == __argTypes)) 
    27130        { 
    28             ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); 
     131            static if (U.length == 0 || T.sizeof > 16 || U[0].sizeof > 8) 
     132            {   // Always passed in memory 
     133                // The arg may have more strict alignment than the stack 
     134                auto p = (cast(size_t)ap.stack_args + T.alignof - 1) & ~(T.alignof - 1); 
     135                ap.stack_args = cast(void*)(p + ((T.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1))); 
     136                parmn = *cast(T*)p; 
     137            } 
     138            else static if (U.length == 1) 
     139            {   // Arg is passed in one register 
     140                alias U[0] T1; 
     141                static if (is(T1 == double) || is(T1 == float)) 
     142                {   // Passed in XMM register 
     143                    if (ap.offset_fpregs < (6 * 8 + 16 * 8)) 
     144                    { 
     145                        parmn = *cast(T*)(ap.reg_args + ap.offset_fpregs); 
     146                        ap.offset_fpregs += 16; 
     147                    } 
     148                    else 
     149                    { 
     150                        parmn = *cast(T*)ap.stack_args; 
     151                        ap.stack_args += (T1.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     152                    } 
     153                } 
     154                else 
     155                {   // Passed in regular register 
     156                    if (ap.offset_regs < 6 * 8 && T.sizeof <= 8) 
     157                    { 
     158                        parmn = *cast(T*)(ap.reg_args + ap.offset_regs); 
     159                        ap.offset_regs += 8; 
     160                    } 
     161                    else 
     162                    { 
     163                        auto p = (cast(size_t)ap.stack_args + T.alignof - 1) & ~(T.alignof - 1); 
     164                        ap.stack_args = cast(void*)(p + ((T.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1))); 
     165                        parmn = *cast(T*)p; 
     166                    } 
     167                } 
     168            } 
     169            else static if (U.length == 2) 
     170            {   // Arg is passed in two registers 
     171                alias U[0] T1; 
     172                alias U[1] T2; 
     173 
     174                static if (is(T1 == double) || is(T1 == float)) 
     175                { 
     176                    if (ap.offset_fpregs < (6 * 8 + 16 * 8)) 
     177                    { 
     178                        *cast(T1*)&parmn = *cast(T1*)(ap.reg_args + ap.offset_fpregs); 
     179                        ap.offset_fpregs += 16; 
     180                    } 
     181                    else 
     182                    { 
     183                        *cast(T1*)&parmn = *cast(T1*)ap.stack_args; 
     184                        ap.stack_args += (T1.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     185                    } 
     186                } 
     187                else 
     188                { 
     189                    if (ap.offset_regs < 6 * 8 && T1.sizeof <= 8) 
     190                    { 
     191                        *cast(T1*)&parmn = *cast(T1*)(ap.reg_args + ap.offset_regs); 
     192                        ap.offset_regs += 8; 
     193                    } 
     194                    else 
     195                    { 
     196                        *cast(T1*)&parmn = *cast(T1*)ap.stack_args; 
     197                        ap.stack_args += 8; 
     198                    } 
     199                } 
     200 
     201                auto p = cast(void*)&parmn + 8; 
     202                static if (is(T2 == double) || is(T2 == float)) 
     203                { 
     204                    if (ap.offset_fpregs < (6 * 8 + 16 * 8)) 
     205                    { 
     206                        *cast(T2*)p = *cast(T2*)(ap.reg_args + ap.offset_fpregs); 
     207                        ap.offset_fpregs += 16; 
     208                    } 
     209                    else 
     210                    { 
     211                        *cast(T2*)p = *cast(T2*)ap.stack_args; 
     212                        ap.stack_args += (T2.sizeof + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     213                    } 
     214                } 
     215                else 
     216                { 
     217                    void* a = void; 
     218                    if (ap.offset_regs < 6 * 8 && T2.sizeof <= 8) 
     219                    { 
     220                        a = ap.reg_args + ap.offset_regs; 
     221                        ap.offset_regs += 8; 
     222                    } 
     223                    else 
     224                    { 
     225                        a = ap.stack_args; 
     226                        ap.stack_args += 8; 
     227                    } 
     228                    // Be careful not to go past the size of the actual argument 
     229                    const sz2 = T.sizeof - 8; 
     230                    p[0..sz2] = a[0..sz2]; 
     231                } 
     232            } 
     233            else 
     234            { 
     235                static assert(0); 
     236            } 
    29237        } 
    30     } 
    31  
    32     template va_arg( T ) 
    33     { 
    34         T va_arg( ref va_list ap ) 
     238        else 
    35239        { 
    36             T arg = *cast(T*) ap; 
    37             ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); 
    38             return arg; 
     240            static assert(0, "not a valid argument type for va_arg"); 
    39241        } 
    40242    } 
    41243 
    42     void va_end( va_list ap ) 
    43     { 
    44  
    45     } 
    46  
    47     void va_copy( out va_list dest, va_list src ) 
     244    void va_arg()(va_list apx, TypeInfo ti, void* parmn) 
     245    { 
     246        __va_list* ap = cast(__va_list*)apx; 
     247        TypeInfo arg1, arg2; 
     248        if (!ti.argTypes(arg1, arg2)) 
     249        { 
     250            if (arg1 && arg1.tsize() <= 8) 
     251            { 
     252                // Arg is passed in one register 
     253                auto tsize = arg1.tsize(); 
     254                void* p; 
     255                auto s = arg1.toString(); 
     256                if (s == "double" || s == "float" || s == "idouble" || s == "ifloat") 
     257                {   // Passed in XMM register 
     258                    if (ap.offset_fpregs < (6 * 8 + 16 * 8)) 
     259                    { 
     260                        p = ap.reg_args + ap.offset_fpregs; 
     261                        ap.offset_fpregs += 16; 
     262                    } 
     263                    else 
     264                    { 
     265                        p = ap.stack_args; 
     266                        ap.stack_args += (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     267                    } 
     268                } 
     269                else 
     270                {   // Passed in regular register 
     271                    if (ap.offset_regs < 6 * 8) 
     272                    { 
     273                        p = ap.reg_args + ap.offset_regs; 
     274                        ap.offset_regs += 8; 
     275                    } 
     276                    else 
     277                    { 
     278                        p = ap.stack_args; 
     279                        ap.stack_args += 8; 
     280                    } 
     281                } 
     282                parmn[0..tsize] = p[0..tsize]; 
     283 
     284                if (arg2) 
     285                { 
     286                    parmn += 8; 
     287                    tsize = arg2.tsize(); 
     288                    s = arg2.toString(); 
     289                    if (s == "double" || s == "float" || s == "idouble" || s == "ifloat") 
     290                    {   // Passed in XMM register 
     291                        if (ap.offset_fpregs < (6 * 8 + 16 * 8)) 
     292                        { 
     293                            p = ap.reg_args + ap.offset_fpregs; 
     294                            ap.offset_fpregs += 16; 
     295                        } 
     296                        else 
     297                        { 
     298                            p = ap.stack_args; 
     299                            ap.stack_args += (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
     300                        } 
     301                    } 
     302                    else 
     303                    {   // Passed in regular register 
     304                        if (ap.offset_regs < 6 * 8) 
     305                        { 
     306                            p = ap.reg_args + ap.offset_regs; 
     307                            ap.offset_regs += 8; 
     308                        } 
     309                        else 
     310                        { 
     311                            p = ap.stack_args; 
     312                            ap.stack_args += 8; 
     313                        } 
     314                    } 
     315                    tsize = ti.tsize() - 8; 
     316                    parmn[0..tsize] = p[0..tsize]; 
     317                } 
     318            } 
     319            else 
     320            { 
     321                // Always passed in memory 
     322                // The arg may have more strict alignment than the stack 
     323                auto talign = ti.talign(); 
     324                auto tsize = ti.tsize(); 
     325 
     326 
     327                auto p = cast(void*)((cast(size_t)ap.stack_args + talign - 1) & ~(talign - 1)); 
     328                ap.stack_args = cast(void*)(cast(size_t)p + ((tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1))); 
     329                parmn[0..tsize] = p[0..tsize]; 
     330            } 
     331        } 
     332        else 
     333        { 
     334            assert(0, "not a valid argument type for va_arg"); 
     335        } 
     336    } 
     337 
     338    void va_end(va_list ap) 
     339    { 
     340    } 
     341 
     342    void va_copy(out va_list dest, va_list src) 
    48343    { 
    49344        dest = src; 
    50345    } 
    51346} 
     347else 
     348{ 
     349    static assert(0); 
     350} 
     351} 
  • trunk/tango/sys/HomeFolder.d

    r5618 r5652  
    4747} 
    4848 
    49 version (Posix)  
     49version (Posix) 
    5050{ 
    5151 
     
    7878        if it could not be expanded. 
    7979 
    80         Throws: OutOfMemoryException if there is not enough memory to  
     80        Throws: OutOfMemoryException if there is not enough memory to 
    8181                perform the database lookup for the <i>~user</i> syntax. 
    8282 
     
    125125 
    126126    private char[] expandFromEnvironment(char[] path) 
     127    in 
    127128    { 
    128129        assert(path.length >= 1); 
    129130        assert(path[0] == '~'); 
    130  
     131    } 
     132    body 
     133    { 
    131134        // Get HOME and use that to replace the tilde. 
    132135        char[] home = homeFolder; 
     
    134137            return path; 
    135138 
     139        if (home[$-1] == '/') 
     140            home = home[0..$-1]; 
     141 
    136142        return Path.join(home, path[1..$]); 
     143 
    137144    } 
    138145 
     
    154161 
    155162        if (last_char == path.length) 
    156            
     163       
    157164            username = path[1..$] ~ '\0'; 
    158            
     165       
    159166        else 
    160            
     167       
    161168            username = path[1..last_char] ~ '\0'; 
    162            
     169       
    163170 
    164171        assert(last_char > 1); 
    165   
     172 
    166173        // Reserve C memory for the getpwnam_r() function. 
    167174        passwd result; 
     
    169176        void* extra_memory; 
    170177 
     178        scope (exit) if(extra_memory) tango.stdc.stdlib.free(extra_memory); 
     179 
    171180        while (1) 
    172            
     181       
    173182            extra_memory = tango.stdc.stdlib.malloc(extra_memory_size); 
    174183            if (extra_memory is null) 
    175                 goto Lerror
     184                throw new OutOfMemoryException("Not enough memory for user lookup in tilde expansion.", __LINE__)
    176185 
    177186            // Obtain info from database. 
     
    180189            if (getpwnam_r(username.ptr, &result, cast(char*)extra_memory, extra_memory_size, 
    181190                &verify) == 0) 
     191            { 
     192                // Failure if verify doesn't point at result. 
     193                if (verify == &result) 
    182194                { 
    183                 // Failure if verify doesn't point at result. 
    184                 if (verify != &result) 
    185                 // username is not found, so return path[] 
    186                     goto Lnotfound; 
    187                 break; 
     195                    auto pwdirlen = strlen(result.pw_dir); 
     196 
     197                    path = Path.join(result.pw_dir[0..pwdirlen].dup, path[last_char..$]); 
    188198                } 
    189199 
     200                return path; 
     201            } 
     202 
    190203            if (tango.stdc.errno.errno() != ERANGE) 
    191                 goto Lerror
     204                throw new OutOfMemoryException("Not enough memory for user lookup in tilde expansion.", __LINE__)
    192205 
    193206            // extra_memory isn't large enough 
    194207            tango.stdc.stdlib.free(extra_memory); 
    195208            extra_memory_size *= 2; 
    196             } 
    197  
    198         auto pwdirlen = strlen(result.pw_dir); 
    199         path = Path.join(result.pw_dir[0..pwdirlen].dup, path[last_char..$]); 
    200  
    201         Lnotfound: 
    202             tango.stdc.stdlib.free(extra_memory); 
    203             return path; 
    204  
    205         Lerror: 
    206             // Errors are going to be caused by running out of memory 
    207             if (extra_memory) 
    208                 tango.stdc.stdlib.free(extra_memory); 
    209             throw new OutOfMemoryException("Not enough memory for user lookup in tilde expansion.", __LINE__); 
     209        } 
    210210    } 
    211211 
     
    243243        if it could not be expanded. 
    244244 
    245         Throws: OutOfMemoryException if there is not enough memory to  
     245        Throws: OutOfMemoryException if there is not enough memory to 
    246246                perform the database lookup for the <i>~user</i> syntax. 
    247247 
     
    309309 
    310310debug(UnitTest) { 
     311 
    311312unittest 
    312313{ 
     
    323324    // Testing when an environment variable is set. 
    324325    Environment.set("HOME", "tango/test"); 
     326    assert (Environment.get("HOME") == "tango/test"); 
     327 
    325328    assert(expandTilde("~/") == "tango/test/"); 
    326329    assert(expandTilde("~") == "tango/test"); 
  • trunk/tango/sys/Process.d

    r5618 r5652  
    3030        extern (C) char*** _NSGetEnviron(); 
    3131        private char** environ; 
    32          
     32 
    3333        static this () 
    3434        { 
     
    3636        } 
    3737    } 
    38      
     38 
    3939    else 
    4040        private extern (C) extern char** environ; 
     
    126126 * cannot call the wait() method. Once the kill() method returns the process 
    127127 * will be already dead. 
    128  *  
     128 * 
    129129 * After calling either wait() or kill(), and no more data is expected on the 
    130130 * pipes, you should call close() as this will clean the pipes. Not doing this 
     
    644644     * redirection from stdout to stderr and from stderr to stdout.  If both 
    645645     * of these are specified, an exception is thrown. 
    646      *  
     646     * 
    647647     * If redirected to a pipe, once the process is executed successfully, its 
    648648     * input and output can be manipulated through the stdin, stdout and 
     
    10161016                } 
    10171017            } 
    1018              
     1018 
    10191019            // close the unused end of the pipes on scope exit 
    10201020            scope(exit) 
     
    10321032            memset(_info, '\0', PROCESS_INFORMATION.sizeof); 
    10331033 
    1034            /*  
     1034           /* 
    10351035            * quotes and backslashes in the command line are handled very 
    10361036            * strangely by Windows.  Through trial and error, I believe that 
     
    11011101                // rule 1 and be halved. 
    11021102                // 
    1103                  
     1103 
    11041104                if(nextarg[$-1] == '\\') 
    11051105                { 
     
    12681268                    if(pin !is null) 
    12691269                    { 
    1270                         dup2(pin.source.fileHandle(), STDIN_FILENO); 
     1270                        if (dup2(pin.source.fileHandle(), STDIN_FILENO) < 0) 
     1271                            throw new Exception("dup2 < 0"); 
    12711272                        pin.sink().close(); 
    12721273                        pin.source.close(); 
     
    12761277                    if(pout !is null) 
    12771278                    { 
    1278                         dup2(pout.sink.fileHandle(), STDOUT_FILENO); 
     1279                        if (dup2(pout.sink.fileHandle(), STDOUT_FILENO) < 0) 
     1280                            throw new Exception("dup2 < 0"); 
    12791281                        pout.source.close(); 
    12801282                        pout.sink.close(); 
     
    12841286                    if(perr !is null) 
    12851287                    { 
    1286                         dup2(perr.sink.fileHandle(), STDERR_FILENO); 
     1288                        if (dup2(perr.sink.fileHandle(), STDERR_FILENO) < 0) 
     1289                            throw new Exception("dup2 < 0"); 
    12871290                        perr.source.close(); 
    12881291                        perr.sink.close(); 
     
    12931296                    if(_redirect & Redirect.OutputToError) 
    12941297                    { 
    1295                         dup2(STDERR_FILENO, STDOUT_FILENO); 
     1298                        if(dup2(STDERR_FILENO, STDOUT_FILENO) < 0) 
     1299                            throw new Exception("dup2 < 0"); 
    12961300                    } 
    12971301 
    12981302                    if(_redirect & Redirect.ErrorToOutput) 
    12991303                    { 
    1300                         dup2(STDOUT_FILENO, STDERR_FILENO); 
     1304                        if(dup2(STDOUT_FILENO, STDERR_FILENO) < 0) 
     1305                            throw new Exception("dup2 < 0"); 
    13011306                    } 
    13021307 
     
    13401345                            exit(errno); 
    13411346                        } 
     1347                        exit(errno); 
    13421348                    } 
    13431349                    else 
     
    15791585     * process may still want/need the remaining content. However, it is 
    15801586     * recommended to call close() on the process when it is no longer needed 
    1581      * as this will clean the pipes.  
     1587     * as this will clean the pipes. 
    15821588     */ 
    15831589    public void kill() 
     
    19271933                char[][] pathList = delimit(str[0 .. strlen(str)], ":"); 
    19281934 
     1935                char[] path_buf; 
     1936 
    19291937                foreach (path; pathList) 
    19301938                { 
    1931                     if (path[path.length - 1] != FileConst.PathSeparatorChar) 
    1932                     { 
    1933                         path ~= FileConst.PathSeparatorChar
    1934                     } 
    1935  
    1936                     debug (Process) 
    1937                         Stdout.formatln("Trying execution of '{0}' in directory '{1}'", 
    1938                                         filename, path)
    1939  
    1940                     path ~= filename; 
    1941                     path ~= '\0'; 
    1942  
    1943                     rc = execve(path.ptr, argv.ptr, (envp.length == 0 ? environ : envp.ptr)); 
     1939                    if (path[$-1] != FileConst.PathSeparatorChar) 
     1940                    { 
     1941                        path_buf.length = path.length + 1 + filename.length + 1
     1942                        path_buf[] = path ~ FileConst.PathSeparatorChar ~ filename ~ '\0'; 
     1943                    } 
     1944                    else 
     1945                    { 
     1946                        path_buf.length = path.length +filename.length + 1
     1947                        path_buf[] = path ~ filename ~ '\0'; 
     1948                    } 
     1949 
     1950                    rc = execve(path_buf.ptr, argv.ptr, (envp.length == 0 ? environ : envp.ptr)); 
     1951 
    19441952                    // If the process execution failed because of an error 
    19451953                    // other than ENOENT (No such file or directory) we 
    19461954                    // abort the loop. 
    1947                     if (rc == -1 && errno != ENOENT) 
     1955                    if (rc == -1 && SysError.lastCode !is ENOENT) 
    19481956                    { 
    19491957                        break; 
     
    20312039} 
    20322040 
    2033  
     2041extern (C) uint sleep (uint s); 
    20342042debug (UnitTest) 
    20352043{ 
     2044    import tango.io.Stdout; 
     2045    import tango.stdc.stdio : printf, fflush, stdout; 
     2046 
    20362047    unittest 
    20372048    { 
     
    20482059        { 
    20492060            auto p = new Process(command, null); 
    2050  
     2061            Stdout.flush; 
    20512062            p.execute(); 
    2052             char[1024] buffer; 
     2063            char[255] buffer; 
     2064 
    20532065            auto nread = p.stdout.read(buffer); 
     2066 
    20542067            assert(nread != p.stdout.Eof); 
     2068 
    20552069            version(Windows) 
    20562070                assert(buffer[0..nread] == message ~ "\r\n"); 
    20572071            else 
    20582072                assert(buffer[0..nread] == message ~ "\n"); 
     2073 
    20592074            nread = p.stdout.read(buffer); 
    20602075            assert(nread == p.stdout.Eof); 
  • trunk/tango/text/Regex.d

    r5544 r5652  
    933933    cc.negate; 
    934934    assert(cc.toString,  "[(12)-(13)'e'-(ff)]"); 
    935      
     935 
    936936    static CharClass!(char) cc2 = { parts: [] }; 
    937937    assert(cc.toString,  "[]"); 
     
    944944    cc2.negate; 
    945945    assert(cc.toString,  "[]"); 
    946      
     946 
    947947    static CharClass!(char) cc3 = { parts: [{l_:0,r_:100},{l_:200,r_:0xff},] }; 
    948948    assert(cc3.toString, "[(0)-'d'(c8)-(ff)]"); 
     
    951951    cc3.negate; 
    952952    assert(cc.toString,  "[(0)-'d'(c8)-(ff)]"); 
    953      
     953 
    954954    static CharClass!(char) cc4 = { parts: [{l_:0,r_:200},{l_:100,r_:0xff},] }; 
    955955    assert(cc.toString,  "[(0)-(c8)'d'-(ff)]"); 
    956956    cc4.optimize; 
    957957    assert(cc.toString,  "[(9)-(13)(20)-'~'(a0)-(ff)(100)-(17f)(180)-(24f)(20a3)-(20b5)]"); 
    958      
     958 
    959959    static CharClass!(dchar) cc5 = { parts: [{l_:0x9,r_:0x13},{0x20,r_:'~'},{l_:0xa0,r_:0xff},{l_:0x100,r_:0x17f},{l_:0x180,r_:0x24f},{l_:0x20a3,r_:0x20b5}] }; 
    960960    cc5.optimize; 
     
    12461246    /****************************************************************************** 
    12471247        Move through states only going via epsilon transitions, and only choosing 
    1248         the one with highest priority. If the highest priority transition from a  
    1249         state isn't an epsilon transition, false is returned.  
    1250         If the accepting NFA state can be reached in this manner, true is returned.  
     1248        the one with highest priority. If the highest priority transition from a 
     1249        state isn't an epsilon transition, false is returned. 
     1250        If the accepting NFA state can be reached in this manner, true is returned. 
    12511251 
    12521252        NOTE: This method does not look for cycles which should be kept in mind for 
     
    12641264            if (!(highestPriTrans.predicate.type == Predicate!(char_t).Type.epsilon)) 
    12651265                return false; 
    1266              
     1266 
    12671267            t = highestPriTrans.target; 
    12681268        } 
     
    34993499                // regressions have been discovered. larsivi 20090827 
    35003500                TNFATransition!(char_t) highestPriTrans; 
    3501                 foreach ( trans; sorted_elms[$-1].nfa_state.transitions ) { 
     3501                if (!(sorted_elms[$-1] && sorted_elms[$-1].nfa_state && 
     3502                            sorted_elms[$-1].nfa_state)) 
     3503                    throw new Exception ("Something is NULL that is expected to 
     3504                            be non-null", __FILE__, __LINE__); 
     3505 
     3506                foreach ( trans; sorted_elms[$-1].nfa_state.transitions ) 
     3507                { 
    35023508                    if (trans.canFinish()) { 
    35033509                        r.dfa_state.reluctant = true; 
     
    39353941                    goto Laccept; 
    39363942 
    3937                 // if all input was consumed and we do not already accept, try to  
     3943                // if all input was consumed and we do not already accept, try to 
    39383944                // add an explicit string/line end 
    39393945                if ( p >= inp.length ) 
     
    43614367 
    43624368    /********************************************************************************************* 
    4363         Get the pattern with which this regex was constructed.  
     4369        Get the pattern with which this regex was constructed. 
    43644370    **********************************************************************************************/ 
    4365     public char_t[] pattern()  
    4366     {  
    4367         return pattern_;  
     4371    public char_t[] pattern() 
     4372    { 
     4373        return pattern_; 
    43684374    } 
    43694375 
    43704376    /********************************************************************************************* 
    4371         Get the tag count of this regex, representing the number of sub-matches.  
     4377        Get the tag count of this regex, representing the number of sub-matches. 
    43724378 
    43734379        This value is the max valid value for match/opIndex. 
  • trunk/tango/text/Text.d

    r5499 r5652  
    126126                // reserve some space for inserts/additions 
    127127                Text reserve (int extra); 
    128          
     128 
    129129                // write content to stream 
    130130                Text write (OutputStream sink); 
     
    214214private import tango.stdc.string : memmove; 
    215215 
     216version(GNU) 
     217{ 
     218    private import tango.core.Vararg; 
     219} 
     220else version(DigitalMars) 
     221{ 
     222    private import tango.core.Vararg; 
     223    version(X86_64) version=DigitalMarsX64; 
     224} 
    216225 
    217226/******************************************************************************* 
     
    286295                bool next () 
    287296                { 
    288                         return locate (&engine.forward, text.slice,  
     297                        return locate (&engine.forward, text.slice, 
    289298                                        text.selectPoint + text.selectLength); 
    290299                } 
     
    292301                /*************************************************************** 
    293302 
    294                         Returns true if there is a match within the  
     303                        Returns true if there is a match within the 
    295304                        associated text 
    296305 
     
    298307 
    299308                bool within () 
    300                 {        
     309                { 
    301310                        return engine.within (text.slice); 
    302311                } 
    303312 
    304313                /*************************************************************** 
    305                  
     314 
    306315                        Returns number of matches within the associated 
    307316                        text 
     
    310319 
    311320                size_t count () 
    312                 {        
     321                { 
    313322                        return engine.count (text.slice); 
    314323                } 
     
    321330 
    322331                void replace (T chr) 
    323                 {      
    324                         replace ((&chr)[0..1]);   
     332                { 
     333                        replace ((&chr)[0..1]); 
    325334                } 
    326335 
     
    332341 
    333342                void replace (T[] sub = null) 
    334                 {   
     343                { 
    335344                        auto dst = new T[text.length]; 
    336345                        dst.length = 0; 
     
    340349                        text.set (dst, false); 
    341350                } 
    342   
     351 
    343352                /*************************************************************** 
    344353 
     
    380389                Note: A character like 'a' will be implicitly converted to 
    381390                uint and thus will be accepted for this constructor, making 
    382                 it appear like you can initialize a Text instance with a  
     391                it appear like you can initialize a Text instance with a 
    383392                single character, something which is not supported. 
    384393 
     
    432441                "temporarily" with a stack-based Text. 
    433442 
    434                 Also resets the curent selection to null            
     443                Also resets the curent selection to null 
    435444 
    436445        ***********************************************************************/ 
     
    457466                "temporarily" with a stack-based Text. 
    458467 
    459                 Also resets the curent selection to null            
     468                Also resets the curent selection to null 
    460469 
    461470        ***********************************************************************/ 
     
    531540 
    532541        /*********************************************************************** 
    533          
     542 
    534543                Return a search iterator for a given pattern. The iterator 
    535544                sets the current text selection as appropriate. For example: 
     
    686695                uint emit (T[] s) 
    687696                { 
    688                         append (s); 
    689                         return s.length; 
     697                    append (s); 
     698                    return s.length; 
    690699                } 
    691700 
    692                 LayoutT.instance.convert (&emit, _arguments, _argptr, format); 
     701                version (DigitalMarsX64) 
     702                { 
     703                    va_list ap; 
     704 
     705                    va_start(ap, __va_argsave); 
     706 
     707                    scope(exit) va_end(ap); 
     708 
     709                    LayoutT.instance.convert (&emit, _arguments, ap, format); 
     710                } 
     711                else 
     712                    LayoutT.instance.convert (&emit, _arguments, _argptr, format); 
     713 
    693714                return this; 
    694715        } 
     
    696717        /*********************************************************************** 
    697718 
    698                 Append text to this Text 
     719          Append text to this Text 
    699720 
    700721        ***********************************************************************/ 
     
    736757 
    737758        ***********************************************************************/ 
    738          
     759 
    739760        deprecated final Text append (int v, T[] fmt = null) 
    740761        { 
     
    781802        { 
    782803                T[8192/T.sizeof] tmp = void; 
    783                 while (true)  
     804                while (true) 
    784805                      { 
    785                       auto len = source.read (tmp);  
    786                       if (len is source.Eof)  
    787                           break;  
     806                      auto len = source.read (tmp); 
     807                      if (len is source.Eof) 
     808                          break; 
    788809 
    789810                      // check to ensure UTF conversion is ok 
     
    16361657 
    16371658debug (UnitTest) 
    1638 {        
     1659{ 
    16391660        import tango.io.device.Array; 
    16401661 
  • trunk/tango/text/convert/DateTime.d

    r5504 r5652  
    66 
    77        version:        Jan 2005: initial release 
    8                         Mar 2009: extracted from locale, and  
     8                        Mar 2009: extracted from locale, and 
    99                                  converted to a struct 
    1010 
     
    1212 
    1313        Support for formatting date/time values, in a locale-specific 
    14         manner. See DateTimeLocale.format() for a description on how  
     14        manner. See DateTimeLocale.format() for a description on how 
    1515        formatting is performed (below). 
    1616 
     
    4242 
    4343        O/S specifics 
    44                  
     44 
    4545******************************************************************************/ 
    4646 
     
    5656 
    5757        The default DateTimeLocale instance 
    58                  
     58 
    5959******************************************************************************/ 
    6060 
     
    6262 
    6363static this() 
    64 {        
     64{ 
    6565        DateTimeDefault = DateTimeLocale.create; 
    6666version (WithExtensions) 
     
    7979 
    8080struct DateTimeLocale 
    81 {        
     81{ 
    8282        static char[]   rfc1123Pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"; 
    8383        static char[]   sortableDateTimePattern = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"; 
     
    109109        /********************************************************************** 
    110110 
    111                 Format the given Time value into the provided output,  
     111                Format the given Time value into the provided output, 
    112112                using the specified layout. The layout can be a generic 
    113113                variant or a custom one, where generics are indicated 
    114114                via a single character: 
    115                  
     115 
    116116                <pre> 
    117117                "t" = 7:04 
    118                 "T" = 7:04:02 PM  
     118                "T" = 7:04:02 PM 
    119119                "d" = 3/30/2009 
    120120                "D" = Monday, March 30, 2009 
     
    130130                "u" = 2009-03-30 19:04:02Z 
    131131                </pre> 
    132          
    133                 For the US locale, these generic layouts are expanded in the  
     132 
     133                For the US locale, these generic layouts are expanded in the 
    134134                following manner: 
    135                  
     135 
    136136                <pre> 
    137                 "t" = "h:mm"  
     137                "t" = "h:mm" 
    138138                "T" = "h:mm:ss tt" 
    139                 "d" = "M/d/yyyy"   
    140                 "D" = "dddd, MMMM d, yyyy"  
     139                "d" = "M/d/yyyy" 
     140                "D" = "dddd, MMMM d, yyyy" 
    141141                "f" = "dddd, MMMM d, yyyy h:mm tt" 
    142142                "F" = "dddd, MMMM d, yyyy h:mm:ss tt" 
     
    144144                "G" = "M/d/yyyy h:mm:ss tt" 
    145145                "y" 
    146                 "Y" = "MMMM, yyyy"         
     146                "Y" = "MMMM, yyyy" 
    147147                "r" 
    148148                "R" = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'" 
    149                 "s" = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"       
    150                 "u" = "yyyy'-'MM'-'dd' 'HH':'mm':'ss'Z'"    
     149                "s" = "yyyy'-'MM'-'dd'T'HH':'mm':'ss" 
     150                "u" = "yyyy'-'MM'-'dd' 'HH':'mm':'ss'Z'" 
    151151                </pre> 
    152152 
    153                 Custom layouts are constructed using a combination of the  
    154                 character codes indicated on the right, above. For example,  
    155                 a layout of "dddd, dd MMM yyyy HH':'mm':'ss zzzz" will emit  
     153                Custom layouts are constructed using a combination of the 
     154                character codes indicated on the right, above. For example, 
     155                a layout of "dddd, dd MMM yyyy HH':'mm':'ss zzzz" will emit 
    156156                something like this: 
    157157                --- 
     
    182182                // default to general format 
    183183                if (layout.length is 0) 
    184                     layout = "G";  
     184                    layout = "G"; 
    185185 
    186186                // might be one of our shortcuts 
    187                 if (layout.length is 1)  
     187                if (layout.length is 1) 
    188188                    layout = expandKnownFormat (layout); 
    189                  
     189 
    190190                auto res=Result(output); 
    191191                return formatCustom (res, dateTime, layout); 
     
    235235        /********************************************************************** 
    236236 
    237                 Return a short day name  
     237                Return a short day name 
    238238 
    239239        **********************************************************************/ 
     
    254254                return dayNames [cast(int) dayOfWeek]; 
    255255        } 
    256                         
     256 
    257257        /********************************************************************** 
    258258 
     
    289289 
    290290        static DateTimeLocale create () 
    291         {        
     291        { 
    292292                static char[] toString (char[] dst, LCID id, LCTYPE type) 
    293293                { 
     
    299299                           GetLocaleInfoW (id, type, wide.ptr, wide.length); 
    300300                           len = WideCharToMultiByte (CP_UTF8, 0, wide.ptr, len-1, 
    301                                                       cast(PCHAR)dst.ptr, dst.length,  
     301                                                      cast(PCHAR)dst.ptr, dst.length, 
    302302                                                      null, null); 
    303303                           return dst [0..len].dup; 
     
    330330                dt.yearMonthPattern = toString (tmp, lcid, LOCALE_SYEARMONTH); 
    331331                dt.longTimePattern  = toString (tmp, lcid, LOCALE_STIMEFORMAT); 
    332                           
     332 
    333333                // synthesize a short time 
    334334                auto s = dt.shortTimePattern = dt.longTimePattern; 
     
    340340                        } 
    341341 
    342                 dt.fullDateTimePattern = dt.longDatePattern ~ " " ~  
     342                dt.fullDateTimePattern = dt.longDatePattern ~ " " ~ 
    343343                                         dt.longTimePattern; 
    344                 dt.generalLongTimePattern = dt.shortDatePattern ~ " " ~  
     344                dt.generalLongTimePattern = dt.shortDatePattern ~ " " ~ 
    345345                                            dt.longTimePattern; 
    346                 dt.generalShortTimePattern = dt.shortDatePattern ~ " " ~  
     346                dt.generalShortTimePattern = dt.shortDatePattern ~ " " ~ 
    347347                                             dt.shortTimePattern; 
    348348                return dt; 
     
    415415 
    416416                //extract shortTimePattern from longTimePattern 
    417                 for (auto i = dt.longTimePattern.length; i--;)  
     417                for (auto i = dt.longTimePattern.length; i--;) 
    418418                    { 
    419419                    if (dt.longTimePattern[i] == dt.timeSeparator[$-1]) 
     
    473473                    switch (c) 
    474474                           { 
    475                            case 'a': //locale's abbreviated weekday name.  
     475                           case 'a': //locale's abbreviated weekday name. 
    476476                                put("ddd"); //The abbreviated name of the day of the week, 
    477477                                break; 
     
    494494                                break; 
    495495 
    496                            case 'D': //same as %m/%d/%y.  
     496                           case 'D': //same as %m/%d/%y. 
    497497                                put("MM/dd/yy"); 
    498498                                break; 
     
    504504                                break; 
    505505 
    506                            case 'h': //same as %b.  
     506                           case 'h': //same as %b. 
    507507                                put("MMM"); 
    508508                                break; 
     
    567567                                //If the week containing 1 January has four or more days 
    568568                                //in the new year, then it is considered week 1. 
    569                                 //Otherwise, it is the last week of the previous year, and the next week is week 1.  
     569                                //Otherwise, it is the last week of the previous year, and the next week is week 1. 
    570570                           case 'w': //weekday as a decimal number [0,6], with 0 representing Sunday 
    571571                           case 'W': //week number of the year (Monday as the first day of the week) 
    572572                                //as a decimal number [00,53]. 
    573573                                //All days in a new year preceding the first Monday 
    574                                 //are considered to be in week 0.  
     574                                //are considered to be in week 0. 
    575575                           case 'x': //locale's appropriate date representation 
    576576                           case 'X': //locale's appropriate time representation 
     
    671671                                doy, 
    672672                                dow, 
    673                                 era;         
     673                                era; 
    674674                uint            day, 
    675675                                year, 
     
    686686                      { 
    687687                      char c = format[index]; 
    688                        
     688 
    689689                      switch (c) 
    690690                             { 
    691691                             // day 
    692                              case 'd':   
     692                             case 'd': 
    693693                                  len = parseRepeat (format, index, c); 
    694694                                  if (len <= 2) 
     
    705705                                { 
    706706                                    result ~= num; 
    707                                      
     707 
    708708                                    // append '0's 
    709709                                    static char[8] zeros = '0'; 
     
    730730 
    731731                             // month 
    732                              case 'M':   
     732                             case 'M': 
    733733                                  len = parseRepeat (format, index, c); 
    734734                                  if (len <= 2) 
     
    739739 
    740740                             // year 
    741                              case 'y':   
     741                             case 'y': 
    742742                                  len = parseRepeat (format, index, c); 
    743743 
     
    755755 
    756756                             // hour (12-hour clock) 
    757                              case 'h':   
     757                             case 'h': 
    758758                                  len = parseRepeat (format, index, c); 
    759759                                  int hour = time.hours % 12; 
     
    764764 
    765765                             // hour (24-hour clock) 
    766                              case 'H':   
     766                             case 'H': 
    767767                                  len = parseRepeat (format, index, c); 
    768768                                  result ~= formatInt (tmp, time.hours, len); 
     
    770770 
    771771                             // minute 
    772                              case 'm':   
     772                             case 'm': 
    773773                                  len = parseRepeat (format, index, c); 
    774774                                  result ~= formatInt (tmp, time.minutes, len); 
     
    776776 
    777777                             // second 
    778                              case 's':   
     778                             case 's': 
    779779                                  len = parseRepeat (format, index, c); 
    780780                                  result ~= formatInt (tmp, time.seconds, len); 
     
    782782 
    783783                             // AM/PM 
    784                              case 't':   
     784                             case 't': 
    785785                                  len = parseRepeat (format, index, c); 
    786786                                  if (len is 1) 
     
    802802 
    803803                             // timezone offset 
    804                              case 'z':   
     804                             case 'z': 
    805805                                  len = parseRepeat (format, index, c); 
    806806                                  auto minutes = cast(int) (WallClock.zone.minutes); 
     
    828828 
    829829                             // time separator 
    830                              case ':':   
     830                             case ':': 
    831831                                  len = 1; 
    832832                                  result ~= timeSeparator; 
     
    834834 
    835835                             // date separator 
    836                              case '/':   
     836                             case '/': 
    837837                                  len = 1; 
    838838                                  result ~= dateSeparator; 
     
    840840 
    841841                             // string literal 
    842                              case '\"':   
    843                              case '\'':   
     842                             case '\"': 
     843                             case '\'': 
    844844                                  len = parseQuote (result, format, index); 
    845845                                  break; 
     
    947947 
    948948/****************************************************************************** 
    949          
     949 
    950950        An english/usa locale 
    951951        Used as generic DateTimeLocale. 
     
    953953******************************************************************************/ 
    954954 
    955 private DateTimeLocale EngUS =  
     955private DateTimeLocale EngUS = 
    956956{ 
    957957        shortDatePattern                : "M/d/yyyy", 
    958         shortTimePattern                : "h:mm",        
     958        shortTimePattern                : "h:mm", 
    959959        longDatePattern                 : "dddd, MMMM d, yyyy", 
    960         longTimePattern                 : "h:mm:ss tt",         
     960        longTimePattern                 : "h:mm:ss tt", 
    961961        fullDateTimePattern             : "dddd, MMMM d, yyyy h:mm:ss tt", 
    962962        generalShortTimePattern         : "M/d/yyyy h:mm", 
     
    968968        timeSeparator                   : ":", 
    969969        dateSeparator                   : "/", 
    970         dayNames                        : ["Sunday", "Monday", "Tuesday", "Wednesday",  
     970        dayNames                        : ["Sunday", "Monday", "Tuesday", "Wednesday", 
    971971                                           "Thursday", "Friday", "Saturday"], 
    972         monthNames                      : ["January", "February", "March", "April",  
    973                                            "May", "June", "July", "August", "September",  
     972        monthNames                      : ["January", "February", "March", "April", 
     973                                           "May", "June", "July", "August", "September", 
    974974                                           "October" "November", "December"], 
    975         abbreviatedDayNames             : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],     
    976         abbreviatedMonthNames           : ["Jan", "Feb", "Mar", "Apr", "May", "Jun",  
     975        abbreviatedDayNames             : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], 
     976        abbreviatedMonthNames           : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 
    977977                                           "Jul", "Aug", "Sep", "Oct" "Nov", "Dec"], 
    978978}; 
  • trunk/tango/text/convert/Layout.d

    r5618 r5652  
    4646        private import tango.time.Time; 
    4747        private import tango.text.convert.DateTime; 
    48         }     
     48        } 
    4949 
    5050 
     
    6666        alias void* Arg; 
    6767        alias va_list ArgList; 
     68        } 
     69else version(DigitalMars) 
     70        { 
     71        private import tango.core.Vararg; 
     72        alias void* Arg; 
     73        alias va_list ArgList; 
     74 
     75        version(X86_64) version = DigitalMarsX64; 
    6876        } 
    6977     else 
     
    8492        public alias convert opCall; 
    8593        public alias uint delegate (T[]) Sink; 
    86         
     94 
    8795        static if (is (DateTimeLocale)) 
    8896                   private DateTimeLocale* dateTime = &DateTimeDefault; 
     
    9199 
    92100                Return shared instance 
    93                  
     101 
    94102                Note that this is not threadsafe, and that static-ctor 
    95103                usage doesn't get invoked appropriately (compiler bug) 
     
    112120        public final T[] sprint (T[] result, T[] formatStr, ...) 
    113121        { 
    114                 return vprint (result, formatStr, _arguments, _argptr); 
     122                version (DigitalMarsX64) 
     123                { 
     124                    va_list ap; 
     125 
     126                    va_start(ap, __va_argsave); 
     127 
     128                    scope(exit) va_end(ap); 
     129 
     130                    return vprint (result, formatStr, _arguments, ap); 
     131                } 
     132                else 
     133                    return vprint (result, formatStr, _arguments, _argptr); 
    115134        } 
    116135 
     
    176195        public final T[] convert (T[] formatStr, ...) 
    177196        { 
    178                 return convert (_arguments, _argptr, formatStr); 
     197                version (DigitalMarsX64) 
     198                { 
     199                    va_list ap; 
     200 
     201                    va_start(ap, __va_argsave); 
     202 
     203                    scope(exit) va_end(ap); 
     204 
     205                    return convert (_arguments, ap, formatStr); 
     206                } 
     207                else 
     208                    return convert (_arguments, _argptr, formatStr); 
    179209        } 
    180210 
     
    185215        public final uint convert (Sink sink, T[] formatStr, ...) 
    186216        { 
    187                 return convert (sink, _arguments, _argptr, formatStr); 
     217                version (DigitalMarsX64) 
     218                { 
     219                    va_list ap; 
     220 
     221                    va_start(ap, __va_argsave); 
     222 
     223                    scope(exit) va_end(ap); 
     224 
     225                    return convert (sink, _arguments, ap, formatStr); 
     226                } 
     227                else 
     228                    return convert (sink, _arguments, _argptr, formatStr); 
    188229        } 
    189230 
     
    204245                } 
    205246 
    206                 return convert (&sink, _arguments, _argptr, formatStr); 
     247 
     248                version (DigitalMarsX64) 
     249                { 
     250                    va_list ap; 
     251 
     252                    va_start(ap, __va_argsave); 
     253 
     254                    scope(exit) va_end(ap); 
     255 
     256                    return convert (&sink, _arguments, ap, formatStr); 
     257                } 
     258                else 
     259                    return convert (&sink, _arguments, _argptr, formatStr); 
    207260        } 
    208261 
     
    225278        } 
    226279 
    227 version (old) 
    228 
    229         /********************************************************************** 
    230  
    231         **********************************************************************/ 
    232  
    233         public final T[] convertOne (T[] result, TypeInfo ti, Arg arg) 
     280        /********************************************************************** 
     281 
     282        **********************************************************************/ 
     283 
     284        version (old) public final T[] convertOne (T[] result, TypeInfo ti, Arg arg) 
    234285        { 
    235286                return dispatch (result, null, ti, arg); 
    236287        } 
    237 
     288 
    238289        /********************************************************************** 
    239290 
     
    253304                        Arg[64] arglist = void; 
    254305                        ArgU[64] storedArgs = void; 
    255          
     306 
    256307                        foreach (i, arg; arguments) 
    257308                                { 
     
    272323                                            converted = true; 
    273324                                            break; 
    274                                          
     325 
    275326                                       case TypeCode.CFLOAT: 
    276327                                            storedArgs[i].cf = va_arg!(cfloat)(args); 
     
    278329                                            converted = true; 
    279330                                            break; 
    280          
     331 
    281332                                       case TypeCode.DOUBLE, TypeCode.IDOUBLE: 
    282333                                            storedArgs[i].d = va_arg!(double)(args); 
     
    284335                                            converted = true; 
    285336                                            break; 
    286                                          
     337 
    287338                                       case TypeCode.CDOUBLE: 
    288339                                            storedArgs[i].cd = va_arg!(cdouble)(args); 
     
    290341                                            converted = true; 
    291342                                            break; 
    292          
     343 
    293344                                       case TypeCode.REAL, TypeCode.IREAL: 
    294345                                            storedArgs[i].r = va_arg!(real)(args); 
     
    302353                                            converted = true; 
    303354                                            break; 
    304          
     355 
    305356                                       default: 
    306357                                            break; 
     
    337388                                } 
    338389                        } 
    339                      else 
     390                    else version(DigitalMarsX64) 
     391                    { 
     392                        Arg[64] arglist = void; 
     393                        void[] buffer; 
     394                        uint len = 0; 
     395 
     396                        foreach(i, argType; arguments) 
     397                            len +=  (argType.tsize + size_t.sizeof - 1) & ~ (size_t.sizeof - 1); 
     398 
     399                        buffer.length = len; 
     400                        len = 0; 
     401                        foreach(i, argType; arguments) 
    340402                        { 
     403                            //printf("type: %s\n", argType.classinfo.name.ptr); 
     404 
     405                            va_arg(args, argType, buffer.ptr+len); 
     406 
     407                            if(argType.classinfo.name.length != 25 && argType.classinfo.name[9] == TypeCode.ARRAY && 
     408                                (argType.classinfo.name[10] == TypeCode.USHORT || 
     409                                argType.classinfo.name[10] == TypeCode.SHORT)) 
     410                                { 
     411                                    printf("Warning: (u)short[] is broken for varargs in x86_64"); 
     412                                    // simply disable the array for now 
     413                                    (cast(short[]*) (buffer.ptr+len)).length = 0; 
     414                                } 
     415 
     416                            arglist[i] = &buffer[len]; 
     417 
     418                            len+= (argType.tsize + size_t.sizeof - 1) & ~ (size_t.sizeof - 1); 
     419                        } 
     420 
     421                        scope (exit) delete buffer; 
     422                    } 
     423                    else  
     424                    { 
    341425                        Arg[64] arglist = void; 
    342426                        foreach (i, arg; arguments) 
     
    345429                                args += (arg.tsize + size_t.sizeof - 1) & ~ (size_t.sizeof - 1); 
    346430                                } 
    347                        
     431                   
    348432                return parse (formatStr, arguments, arglist, sink); 
    349433        } 
     
    525609                                   length += sink ("]"); 
    526610                                   } 
    527                                 else  
     611                                else 
    528612                                if (_ti.classinfo.name.length is 25 && _ti.classinfo.name[9..$] == "AssociativeArray") 
    529613                                   { 
     
    531615                                   auto tiKey = tiAsso.key; 
    532616                                   auto tiVal = tiAsso.next(); 
     617 
    533618                                   // the knowledge of the internal k/v storage is used 
    534619                                   // so this might break if, that internal storage changes 
     
    539624                                   length += sink ("{"); 
    540625                                   bool first = true; 
    541                                    
    542                                    size_t roundUp (size_t sz
     626 
     627                                   size_t roundUp (size_t tsize
    543628                                   { 
    544                                         return (sz + (void*).sizeof -1) & ~((void*).sizeof - 1); 
     629                                        //return (sz + (void*).sizeof -1) & ~((void*).sizeof - 1); 
     630 
     631                                        version (X86_64) 
     632                                            // Size of key needed to align value on 16 bytes 
     633                                            return (tsize + 15) & ~(15); 
     634                                        else 
     635                                            return (tsize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
    545636                                   } 
    546637 
     
    561652                                   length += sink ("}"); 
    562653                                   } 
    563                                 else  
     654                                else 
    564655                                if (_ti.classinfo.name[9] is TypeCode.ARRAY) 
    565656                                   { 
     
    567658                                       emit (Utf.fromString8 (*cast(char[]*) _arg, result)); 
    568659                                   else 
    569                                    if (_ti is typeid(wchar[]))         
     660                                   if (_ti is typeid(wchar[])) 
    570661                                       emit (Utf.fromString16 (*cast(wchar[]*) _arg, result)); 
    571662                                   else 
     
    597688                      } 
    598689 
    599                        
     690 
    600691                      // process this argument 
    601692                      if (index >= ti.length) 
     
    692783                       case TypeCode.STRUCT: 
    693784                            auto s = cast(TypeInfo_Struct) type; 
    694                             if (s.xtoString)  
     785                            if (s.xtoString) 
    695786                               { 
    696787                               char[] delegate() toString; 
     
    735826                { 
    736827                result = Extensions!(T).run (type, result, p, format); 
    737                 return (result) ? result :  
     828                return (result) ? result : 
    738829                       "{unhandled argument type: " ~ Utf.fromString8 (type.toString, result) ~ "}"; 
    739830                } 
     
    809900                                 break; 
    810901                            } 
    811                  
     902 
    812903                return Float.format (output, v, dec, exp, pad); 
    813904        } 
     
    849940                return floatingTail (result, val.im, format, "*1i"); 
    850941        } 
    851          
     942 
    852943        /********************************************************************** 
    853944 
     
    860951                static bool signed (real x) 
    861952                { 
    862                         static if (real.sizeof is 4)  
     953                        static if (real.sizeof is 4) 
    863954                                   return ((*cast(uint *)&x) & 0x8000_0000) != 0; 
    864955                        else 
    865                         static if (real.sizeof is 8)  
     956                        static if (real.sizeof is 8) 
    866957                                   return ((*cast(ulong *)&x) & 0x8000_0000_0000_0000) != 0; 
    867958                               else 
     
    9361027        IFLOAT = 'o', 
    9371028        IDOUBLE = 'p', 
    938         IREAL = 'j'   
     1029        IREAL = 'j' 
    9391030} 
    9401031 
     
    9441035 
    9451036*******************************************************************************/ 
    946  
     1037import tango.stdc.stdio : printf; 
    9471038debug (UnitTest) 
    9481039{ 
     
    10871178        assert( Formatter( "{:f.}", 1.000 ) == "1" ); 
    10881179        assert( Formatter( "{:f2.}", 200.001 ) == "200"); 
    1089          
     1180 
    10901181        // array output 
    10911182        int[] a = [ 51, 52, 53, 54, 55 ]; 
     
    10971188        assert( Formatter( "{}", b ) == "[[51, 52], [53, 54, 55]]" ); 
    10981189 
    1099         ushort[3] c = [ cast(ushort)51, 52, 53 ]; 
    1100         assert( Formatter( "{}", c ) == "[51, 52, 53]" ); 
    1101  
    1102         // integer AA  
     1190        char[1024] static_buffer; 
     1191        static_buffer[0..10] = "1234567890"; 
     1192 
     1193        assert (Formatter( "{}", static_buffer[0..10]) == "1234567890"); 
     1194 
     1195        version(X86) 
     1196        { 
     1197            ushort[3] c = [ cast(ushort)51, 52, 53 ]; 
     1198            assert( Formatter( "{}", c ) == "[51, 52, 53]" ); 
     1199        } 
     1200 
     1201        // integer AA 
    11031202        ushort[long] d; 
    11041203        d[234] = 2; 
    11051204        d[345] = 3; 
     1205 
    11061206        assert( Formatter( "{}", d ) == "{234 => 2, 345 => 3}" || 
    11071207                Formatter( "{}", d ) == "{345 => 3, 234 => 2}"); 
    1108          
    1109         // bool/string AA  
     1208 
     1209        // bool/string AA 
    11101210        bool[char[]] e; 
    11111211        e[ "key".dup ] = true; 
     
    11141214                Formatter( "{}", e ) == "{value => false, key => true}"); 
    11151215 
    1116         // string/double AA  
     1216        // string/double AA 
    11171217        char[][ double ] f; 
    11181218        f[ 1.0 ] = "one".dup; 
     
    11591259                struct S 
    11601260                { 
    1161                    char[] toString () {return "foo";}       
     1261                   char[] toString () {return "foo";} 
    11621262                } 
    11631263 
  • trunk/tango/util/log/Log.d

    r5446 r5652  
    44 
    55        license:        BSD style: $(LICENSE) 
    6        
     6 
    77        version:        May 2004 : Initial release 
    88        version:        Oct 2004: Hierarchy moved due to circular dependencies 
     
    2121        Generic usage: 
    2222 
    23         Loggers are named entities, sometimes shared, sometimes specific to  
    24         a particular portion of code. The names are generally hierarchical in  
    25         nature, using dot notation (with '.') to separate each named section.  
     23        Loggers are named entities, sometimes shared, sometimes specific to 
     24        a particular portion of code. The names are generally hierarchical in 
     25        nature, using dot notation (with '.') to separate each named section. 
    2626        For example, a typical name might be something like "mail.send.writer" 
    2727        --- 
    2828        import tango.util.log.Log; 
    29          
     29 
    3030        auto log = Log.lookup ("mail.send.writer"); 
    3131 
     
    3535        etc ... 
    3636        --- 
    37          
    38         It is considered good form to pass a logger instance as a function or  
    39         class-ctor argument, or to assign a new logger instance during static  
    40         class construction. For example: if it were considered appropriate to  
     37 
     38        It is considered good form to pass a logger instance as a function or 
     39        class-ctor argument, or to assign a new logger instance during static 
     40        class construction. For example: if it were considered appropriate to 
    4141        have one logger instance per class, each might be constructed like so: 
    4242        --- 
    4343        private Logger log; 
    44          
     44 
    4545        static this() 
    4646        { 
     
    6464        --- 
    6565 
    66         To avoid overhead when constructing arguments passed to formatted  
     66        To avoid overhead when constructing arguments passed to formatted 
    6767        messages, you should check to see whether a logger is active or not: 
    6868        --- 
     
    7070            log.warn ("temperature is {} degrees!", complexFunction()); 
    7171        --- 
    72          
    73         tango.log closely follows both the API and the behaviour as documented  
    74         at the official Log4J site, where you'll find a good tutorial. Those  
    75         pages are hosted over  
     72 
     73        tango.log closely follows both the API and the behaviour as documented 
     74        at the official Log4J site, where you'll find a good tutorial. Those 
     75        pages are hosted over 
    7676        <A HREF="http://logging.apache.org/log4j/docs/documentation.html">here</A>. 
    7777 
     
    103103        alias void* Arg; 
    104104        alias va_list ArgList; 
     105        } 
     106else version (DigitalMars) 
     107        { 
     108        private import tango.core.Vararg; 
     109        alias void* Arg; 
     110        alias va_list ArgList; 
     111 
     112    version(X86_64)  version = DigitalMarsX64; 
     113 
    105114        } 
    106115     else 
     
    128137 
    129138/******************************************************************************* 
    130                          
     139 
    131140        These represent the standard LOG4J event levels. Note that 
    132141        Debug is called Trace here, because debug is a reserved word 
    133         in D  
     142        in D 
    134143 
    135144*******************************************************************************/ 
    136145 
    137 alias ILogger.Level Level;  
     146alias ILogger.Level Level; 
    138147 
    139148 
    140149/******************************************************************************* 
    141150 
    142         Manager for routing Logger calls to the default hierarchy. Note  
     151        Manager for routing Logger calls to the default hierarchy. Note 
    143152        that you may have multiple hierarchies per application, but must 
    144         access the hierarchy directly for root() and lookup() methods within  
     153        access the hierarchy directly for root() and lookup() methods within 
    145154        each additional instance. 
    146155 
     
    168177 
    169178        private static  Level [char[]] map; 
    170          
    171         private static  Pair[] Pairs =  
     179 
     180        private static  Pair[] Pairs = 
    172181                        [ 
    173182                        {"TRACE",  Level.Trace}, 
     
    192201 
    193202        // logging-level names 
    194         private static char[][] LevelNames =  
     203        private static char[][] LevelNames = 
    195204        [ 
    196205                "Trace", "Info", "Warn", "Error", "Fatal", "None" 
     
    198207 
    199208        /*********************************************************************** 
    200          
    201                 Initialize the base hierarchy            
    202                
     209 
     210                Initialize the base hierarchy 
     211 
    203212        ***********************************************************************/ 
    204213 
     
    210219                         map[p.name] = p.value; 
    211220 
    212                 version (Posix)        
     221                version (Posix) 
    213222                { 
    214223                        beginTime = Clock.now; 
     
    221230                        if (! QueryPerformanceFrequency (&freq)) 
    222231                              throw new PlatformException ("high-resolution timer is not available"); 
    223                          
     232 
    224233                        QueryPerformanceCounter (&timerStart); 
    225                         multiplier = cast(double) TimeSpan.TicksPerSecond / freq;        
     234                        multiplier = cast(double) TimeSpan.TicksPerSecond / freq; 
    226235                        beginTime = Clock.now; 
    227236                } 
     
    229238 
    230239        /*********************************************************************** 
    231          
     240 
    232241                Return the level of a given name 
    233242 
     
    243252 
    244253        /*********************************************************************** 
    245                  
     254 
    246255                Return the current time 
    247256 
     
    250259        static Time time () 
    251260        { 
    252                 version (Posix)        
     261                version (Posix) 
    253262                { 
    254263                        return Clock.now; 
     
    267276 
    268277                Return the root Logger instance. This is the ancestor of 
    269                 all loggers and, as such, can be used to manipulate the  
    270                 entire hierarchy. For instance, setting the root 'level'  
     278                all loggers and, as such, can be used to manipulate the 
     279                entire hierarchy. For instance, setting the root 'level' 
    271280                attribute will affect all other loggers in the tree. 
    272281 
     
    279288 
    280289        /*********************************************************************** 
    281          
     290 
    282291                Return an instance of the named logger. Names should be 
    283                 hierarchical in nature, using dot notation (with '.') to  
    284                 separate each name section. For example, a typical name  
     292                hierarchical in nature, using dot notation (with '.') to 
     293                separate each name section. For example, a typical name 
    285294                might be something like "tango.io.Stdout". 
    286295 
     
    298307 
    299308        /*********************************************************************** 
    300          
     309 
    301310                Return text name for a log level 
    302311 
     
    310319 
    311320        /*********************************************************************** 
    312          
     321 
    313322                Return the singleton hierarchy. 
    314323 
     
    321330 
    322331        /*********************************************************************** 
    323                  
     332 
    324333                Pedestrian usage support, as an alias for Log.root.info() 
    325334 
     
    328337        static void formatln (char[] fmt, ...) 
    329338        { 
     339            version (DigitalMarsX64) 
     340            { 
     341                va_list ap; 
     342 
     343                version(GNU) {} else va_start(ap, __va_argsave); 
     344 
     345                scope(exit) va_end(ap); 
     346 
     347                root.format (Level.Info, fmt, _arguments, ap); 
     348            } 
     349            else             
    330350                root.format (Level.Info, fmt, _arguments, _argptr); 
    331351        } 
     
    337357                Adds a StreamAppender to the root node, and sets 
    338358                the activity level to be everything enabled. 
    339                  
     359 
    340360        ***********************************************************************/ 
    341361 
     
    349369/******************************************************************************* 
    350370 
    351         Loggers are named entities, sometimes shared, sometimes specific to  
    352         a particular portion of code. The names are generally hierarchical in  
    353         nature, using dot notation (with '.') to separate each named section.  
     371        Loggers are named entities, sometimes shared, sometimes specific to 
     372        a particular portion of code. The names are generally hierarchical in 
     373        nature, using dot notation (with '.') to separate each named section. 
    354374        For example, a typical name might be something like "mail.send.writer" 
    355375        --- 
    356376        import tango.util.log.Log;format 
    357          
     377 
    358378        auto log = Log.lookup ("mail.send.writer"); 
    359379 
     
    363383        etc ... 
    364384        --- 
    365          
    366         It is considered good form to pass a logger instance as a function or  
    367         class-ctor argument, or to assign a new logger instance during static  
    368         class construction. For example: if it were considered appropriate to  
     385 
     386        It is considered good form to pass a logger instance as a function or 
     387        class-ctor argument, or to assign a new logger instance during static 
     388        class construction. For example: if it were considered appropriate to 
    369389        have one logger instance per class, each might be constructed like so: 
    370390        --- 
    371391        private Logger log; 
    372          
     392 
    373393        static this() 
    374394        { 
     
    392412        --- 
    393413 
    394         To avoid overhead when constructing argument passed to formatted  
     414        To avoid overhead when constructing argument passed to formatted 
    395415        messages, you should check to see whether a logger is active or not: 
    396416        --- 
     
    398418            log.warn ("temperature is {} degrees!", complexFunction()); 
    399419        --- 
    400          
    401         The above will be handled implicitly by the logging system when  
    402         macros are added to the language (used to be handled implicitly  
     420 
     421        The above will be handled implicitly by the logging system when 
     422        macros are added to the language (used to be handled implicitly 
    403423        via lazy delegates, but usage of those turned out to be awkward). 
    404424 
    405         tango.log closely follows both the API and the behaviour as documented  
    406         at the official Log4J site, where you'll find a good tutorial. Those  
    407         pages are hosted over  
     425        tango.log closely follows both the API and the behaviour as documented 
     426        at the official Log4J site, where you'll find a good tutorial. Those 
     427        pages are hosted over 
    408428        <A HREF="http://logging.apache.org/log4j/docs/documentation.html">here</A>. 
    409429 
     
    411431 
    412432public class Logger : ILogger 
    413 {      
    414          
    415         alias Level.Trace Trace;        // shortcut to Level values  
     433{ 
     434 
     435        alias Level.Trace Trace;        // shortcut to Level values 
    416436        alias Level.Info  Info;         // ... 
    417437        alias Level.Warn  Warn;         // ... 
     
    422442 
    423443        /*********************************************************************** 
    424                  
     444 
    425445                Context for a hierarchy, used for customizing behaviour 
    426446                of log hierarchies. You can use this to implement dynamic 
     
    433453                /// return a label for this context 
    434454                char[] label (); 
    435                  
     455 
    436456                /// first arg is the setting of the logger itself, and 
    437457                /// the second arg is what kind of message we're being 
     
    441461 
    442462        /*********************************************************************** 
    443                  
     463 
    444464        ***********************************************************************/ 
    445465 
     
    454474 
    455475        /*********************************************************************** 
    456          
    457                 Construct a LoggerInstance with the specified name for the  
     476 
     477                Construct a LoggerInstance with the specified name for the 
    458478                given hierarchy. By default, logger instances are additive 
    459479                and are set to emit all events. 
     
    470490 
    471491        /*********************************************************************** 
    472          
     492 
    473493                Is this logger enabed for the specified Level? 
    474494 
     
    499519        final void trace (char[] fmt, ...) 
    500520        { 
     521            version (DigitalMarsX64) 
     522            { 
     523                va_list ap; 
     524 
     525                va_start(ap, __va_argsave); 
     526 
     527                scope(exit) va_end(ap); 
     528 
     529                format (Level.Trace, fmt, _arguments, ap); 
     530            } 
     531            else             
    501532                format (Level.Trace, fmt, _arguments, _argptr); 
    502533        } 
     
    521552        final void info (char[] fmt, ...) 
    522553        { 
     554            version (DigitalMarsX64) 
     555            { 
     556                va_list ap; 
     557 
     558                va_start(ap, __va_argsave); 
     559 
     560                scope(exit) va_end(ap); 
     561 
     562                format (Level.Info, fmt, _arguments, ap); 
     563            } 
     564            else             
    523565                format (Level.Info, fmt, _arguments, _argptr); 
    524566        } 
     
    543585        final void warn (char[] fmt, ...) 
    544586        { 
     587            version (DigitalMarsX64) 
     588            { 
     589                va_list ap; 
     590 
     591                va_start(ap, __va_argsave); 
     592 
     593                scope(exit) va_end(ap); 
     594 
     595                format (Level.Warn, fmt, _arguments, ap); 
     596            } 
     597            else             
    545598                format (Level.Warn, fmt, _arguments, _argptr); 
    546599        } 
     
    565618        final void error (char[] fmt, ...) 
    566619        { 
     620            version (DigitalMarsX64) 
     621            { 
     622                va_list ap; 
     623 
     624                va_start(ap, __va_argsave); 
     625 
     626                scope(exit) va_end(ap); 
     627 
     628                format (Level.Error, fmt, _arguments, ap); 
     629            } 
     630            else             
    567631                format (Level.Error, fmt, _arguments, _argptr); 
    568632        } 
     
    587651        final void fatal (char[] fmt, ...) 
    588652        { 
     653            version (DigitalMarsX64) 
     654            { 
     655                va_list ap; 
     656 
     657                va_start(ap, __va_argsave); 
     658 
     659                scope(exit) va_end(ap); 
     660 
     661                format (Level.Fatal, fmt, _arguments, ap); 
     662            } 
     663            else             
    589664                format (Level.Fatal, fmt, _arguments, _argptr); 
    590665        } 
     
    593668 
    594669                Return the name of this Logger (sans the appended dot). 
    595         
     670 
    596671        ***********************************************************************/ 
    597672 
     
    601676                if (i > 0) 
    602677                    --i; 
    603                 return name_[0 .. i];      
    604         } 
    605  
    606         /*********************************************************************** 
    607          
     678                return name_[0 .. i]; 
     679        } 
     680 
     681        /*********************************************************************** 
     682 
    608683                Return the Level this logger is set to 
    609684 
     
    612687        final Level level () 
    613688        { 
    614                 return level_;      
    615         } 
    616  
    617         /*********************************************************************** 
    618          
     689                return level_; 
     690        } 
     691 
     692        /*********************************************************************** 
     693 
    619694                Set the current level for this logger (and only this logger). 
    620695 
     
    627702 
    628703        /*********************************************************************** 
    629          
     704 
    630705                Set the current level for this logger, and (optionally) all 
    631706                of its descendents. 
     
    635710        final Logger level (Level level, bool propagate) 
    636711        { 
    637                 level_ = level;  
    638                 if (propagate)     
     712                level_ = level; 
     713                if (propagate) 
    639714                    foreach (log; host_) 
    640715                             if (log.isChildOf (name_)) 
     
    644719 
    645720        /*********************************************************************** 
    646          
     721 
    647722                Is this logger additive? That is, should we walk ancestors 
    648723                looking for more appenders? 
     
    656731 
    657732        /*********************************************************************** 
    658          
     733 
    659734                Set the additive status of this logger. See bool additive(). 
    660735 
     
    663738        final Logger additive (bool enabled) 
    664739        { 
    665                 additive_ = enabled;      
     740                additive_ = enabled; 
    666741                return this; 
    667742        } 
    668743 
    669744        /*********************************************************************** 
    670          
     745 
    671746                Add (another) appender to this logger. Appenders are each 
    672747                invoked for log events as they are produced. At most, one 
     
    684759 
    685760        /*********************************************************************** 
    686          
     761 
    687762                Remove all appenders from this Logger 
    688763 
     
    691766        final Logger clear () 
    692767        { 
    693                 appender_ = null;      
     768                appender_ = null; 
    694769                return this; 
    695770        } 
    696771 
    697772        /*********************************************************************** 
    698          
     773 
    699774                Get time since this application started 
    700775 
     
    707782 
    708783        /*********************************************************************** 
    709          
     784 
    710785                Send a message to this logger via its appender list. 
    711786 
     
    726801 
    727802        /*********************************************************************** 
    728          
     803 
    729804                Send a message to this logger via its appender list. 
    730805 
     
    735810                // combine appenders from all ancestors 
    736811                auto links = this; 
    737                 Appender.Mask masks = 0;                  
     812                Appender.Mask masks = 0; 
    738813                do { 
    739814                   auto appender = links.appender_; 
     
    741816                   // this level have an appender? 
    742817                   while (appender) 
    743                          {  
     818                         { 
    744819                         auto mask = appender.mask; 
    745820 
     
    768843        final char[] format (char[] buffer, char[] formatStr, ...) 
    769844        { 
     845            version (DigitalMarsX64) 
     846            { 
     847                va_list ap; 
     848 
     849                va_start(ap, __va_argsave); 
     850 
     851                scope(exit) va_end(ap); 
     852 
     853                return Format.vprint (buffer, formatStr, _arguments, ap); 
     854            } 
     855            else 
    770856                return Format.vprint (buffer, formatStr, _arguments, _argptr); 
     857 
    771858        } 
    772859 
     
    778865 
    779866        final Logger format (Level level, char[] fmt, TypeInfo[] types, ArgList args) 
    780         {     
     867        { 
    781868                char[2048] tmp = void; 
    782   
     869 
    783870                if (types.length) 
    784871                    append (level, Format.vprint (tmp, fmt, types, args)); 
    785872                else 
    786                    append (level, fmt);                 
     873                   append (level, fmt); 
    787874                return this; 
    788875        } 
    789876 
    790877        /*********************************************************************** 
    791          
    792                 See if the provided Logger name is a parent of this one. Note  
    793                 that each Logger name has a '.' appended to the end, such that  
     878 
     879                See if the provided Logger name is a parent of this one. Note 
     880                that each Logger name has a '.' appended to the end, such that 
    794881                name segments will not partially match. 
    795882 
     
    802889                // possible parent if length is shorter 
    803890                if (len < name_.length) 
    804                     // does the prefix match? Note we append a "." to each  
     891                    // does the prefix match? Note we append a "." to each 
    805892                    // (the root is a parent of everything) 
    806                     return (len is 0 ||  
     893                    return (len is 0 || 
    807894                            memcmp (&candidate[0], &name_[0], len) is 0); 
    808895                return false; 
     
    810897 
    811898        /*********************************************************************** 
    812          
     899 
    813900                See if the provided Logger is a better match as a parent of 
    814901                this one. This is used to restructure the hierarchy when a 
     
    829916 
    830917/******************************************************************************* 
    831   
     918 
    832919        The Logger hierarchy implementation. We keep a reference to each 
    833920        logger in a hash-table for convenient lookup purposes, plus keep 
    834921        each logger linked to the others in an ordered group. Ordering 
    835         places shortest names at the head and longest ones at the tail,  
     922        places shortest names at the head and longest ones at the tail, 
    836923        making the job of identifying ancestors easier in an orderly 
    837924        fashion. For example, when propagating levels across descendents 
     
    845932        private Logger                  root_; 
    846933        private char[]                  name_, 
    847                                         address_;       
     934                                        address_; 
    848935        private Logger.Context          context_; 
    849936        private Logger[char[]]          loggers; 
     
    851938 
    852939        /*********************************************************************** 
    853          
     940 
    854941                Construct a hierarchy with the given name. 
    855942 
     
    874961                return ""; 
    875962        } 
    876                  
     963 
    877964        /********************************************************************** 
    878965 
     
    9331020        /********************************************************************** 
    9341021 
    935                 Return the diagnostic context.  Useful for setting an  
     1022                Return the diagnostic context.  Useful for setting an 
    9361023                override logging level. 
    9371024 
    9381025        **********************************************************************/ 
    939          
     1026 
    9401027        final Logger.Context context () 
    9411028        { 
    9421029            return context_; 
    9431030        } 
    944          
     1031 
    9451032        /********************************************************************** 
    9461033 
    947                 Set the diagnostic context.  Not usually necessary, as a  
    948                 default was created.  Useful when you need to provide a  
     1034                Set the diagnostic context.  Not usually necessary, as a 
     1035                default was created.  Useful when you need to provide a 
    9491036                different implementation, such as a ThreadLocal variant. 
    9501037 
    9511038        **********************************************************************/ 
    952          
     1039 
    9531040        final void context (Logger.Context context) 
    9541041        { 
    9551042            context_ = context; 
    9561043        } 
    957          
    958         /*********************************************************************** 
    959          
     1044 
     1045        /*********************************************************************** 
     1046 
    9601047                Return the root node. 
    9611048 
     
    9681055 
    9691056        /*********************************************************************** 
    970          
     1057 
    9711058                Return the instance of a Logger with the provided label. If 
    9721059                the instance does not exist, it is created at this time. 
     
    10021089 
    10031090        /*********************************************************************** 
    1004          
     1091 
    10051092                Return the instance of a Logger with the provided label. If 
    10061093                the instance does not exist, it is created at this time. 
     
    10221109                   insert (li); 
    10231110 
    1024                    // look for and adjust children. Don't force  
     1111                   // look for and adjust children. Don't force 
    10251112                   // property inheritance on existing loggers 
    10261113                   update (li); 
     
    10291116                   loggers [name] = li; 
    10301117                   } 
    1031                 
     1118 
    10321119                return *l; 
    10331120        } 
    10341121 
    10351122        /*********************************************************************** 
    1036          
    1037                 Loggers are maintained in a sorted linked-list. The order  
    1038                 is maintained such that the shortest name is at the root,  
     1123 
     1124                Loggers are maintained in a sorted linked-list. The order 
     1125                is maintained such that the shortest name is at the root, 
    10391126                and the longest at the tail. 
    10401127 
     
    10551142                          if (prev is null) 
    10561143                              throw new IllegalElementException ("invalid hierarchy"); 
    1057                           else                                  
     1144                          else 
    10581145                             { 
    10591146                             l.next = prev.next; 
     
    10671154 
    10681155                      // remember where insertion point should be 
    1069                       prev = curr;   
    1070                       curr = curr.next;   
     1156                      prev = curr; 
     1157                      curr = curr.next; 
    10711158                      } 
    10721159 
     
    10761163 
    10771164        /*********************************************************************** 
    1078          
    1079                 Propagate hierarchical changes across known loggers.  
     1165 
     1166                Propagate hierarchical changes across known loggers. 
    10801167                This includes changes in the hierarchy itself, and to 
    1081                 the various settings of child loggers with respect to  
    1082                 their parent(s).               
     1168                the various settings of child loggers with respect to 
     1169                their parent(s). 
    10831170 
    10841171        ***********************************************************************/ 
     
    10911178 
    10921179        /*********************************************************************** 
    1093          
     1180 
    10941181                Propagate changes in the hierarchy downward to child Loggers. 
    1095                 Note that while 'parent' is always changed, the adjustment of  
     1182                Note that while 'parent' is always changed, the adjustment of 
    10961183                'level' is selectable. 
    10971184 
     
    11371224 
    11381225        /*********************************************************************** 
    1139                  
     1226 
    11401227                Set the various attributes of this event. 
    11411228 
     
    11521239 
    11531240        /*********************************************************************** 
    1154                  
     1241 
    11551242                Return the message attached to this event. 
    11561243 
     
    11631250 
    11641251        /*********************************************************************** 
    1165                  
     1252 
    11661253                Return the name of the logger which produced this event 
    11671254 
     
    11741261 
    11751262        /*********************************************************************** 
    1176                  
     1263 
    11771264                Return the logger level of this event. 
    11781265 
     
    11851272 
    11861273        /*********************************************************************** 
    1187                  
     1274 
    11881275                Return the hierarchy where the event was produced from 
    11891276 
     
    11961283 
    11971284        /*********************************************************************** 
    1198                  
    1199                 Return the time this event was produced, relative to the  
     1285 
     1286                Return the time this event was produced, relative to the 
    12001287                start of this executable 
    12011288 
     
    12081295 
    12091296        /*********************************************************************** 
    1210                 
     1297 
    12111298                Return the time this event was produced relative to Epoch 
    12121299 
     
    12191306 
    12201307        /*********************************************************************** 
    1221                  
     1308 
    12221309                Return time when the executable started 
    12231310 
     
    12301317 
    12311318        /*********************************************************************** 
    1232                  
     1319 
    12331320                Return the logger level name of this event. 
    12341321 
     
    12411328 
    12421329        /*********************************************************************** 
    1243                  
     1330 
    12441331                Convert a time value (in milliseconds) to ascii 
    12451332 
     
    12561343                   ms /= 10; 
    12571344                   } while (ms && len); 
    1258                 return s[len..s.length];                 
     1345                return s[len..s.length]; 
    12591346        } 
    12601347} 
     
    12671354        than one appender attached to any logger. The actual message is 
    12681355        constructed by another class known as an EventLayout. 
    1269          
     1356 
    12701357*******************************************************************************/ 
    12711358 
     
    12831370                Interface for all logging layout instances 
    12841371 
    1285                 Implement this method to perform the formatting of   
     1372                Implement this method to perform the formatting of 
    12861373                message content. 
    12871374 
     
    12941381 
    12951382        /*********************************************************************** 
    1296                  
     1383 
    12971384                Return the mask used to identify this Appender. The mask 
    1298                 is used to figure out whether an appender has already been  
     1385                is used to figure out whether an appender has already been 
    12991386                invoked for a particular logger. 
    13001387 
     
    13041391 
    13051392        /*********************************************************************** 
    1306                  
     1393 
    13071394                Return the name of this Appender. 
    13081395 
     
    13101397 
    13111398        abstract char[] name (); 
    1312                  
    1313         /*********************************************************************** 
    1314                  
     1399 
     1400        /*********************************************************************** 
     1401 
    13151402                Append a message to the output. 
    13161403 
     
    13201407 
    13211408        /*********************************************************************** 
    1322                
    1323               Create an Appender and default its layout to LayoutSimple.   
     1409 
     1410              Create an Appender and default its layout to LayoutSimple. 
    13241411 
    13251412        ***********************************************************************/ 
     
    13311418 
    13321419        /*********************************************************************** 
    1333                
    1334               Create an Appender and default its layout to LayoutSimple.   
     1420 
     1421              Create an Appender and default its layout to LayoutSimple. 
    13351422 
    13361423        ***********************************************************************/ 
     
    13421429 
    13431430        /*********************************************************************** 
    1344                
     1431 
    13451432                Return the current Level setting 
    13461433 
     
    13531440 
    13541441        /*********************************************************************** 
    1355                
     1442 
    13561443                Return the current Level setting 
    13571444 
     
    13651452 
    13661453        /*********************************************************************** 
    1367                  
     1454 
    13681455                Static method to return a mask for identifying the Appender. 
    13691456                Each Appender class should have a unique fingerprint so that 
     
    13951482 
    13961483        /*********************************************************************** 
    1397                  
     1484 
    13981485                Set the current layout to be that of the argument, or the 
    13991486                generic layout where the argument is null 
     
    14071494 
    14081495        /*********************************************************************** 
    1409                  
     1496 
    14101497                Return the current Layout 
    14111498 
     
    14181505 
    14191506        /*********************************************************************** 
    1420                  
     1507 
    14211508                Attach another appender to this one 
    14221509 
     
    14291516 
    14301517        /*********************************************************************** 
    1431                  
     1518 
    14321519                Return the next appender in the list 
    14331520 
     
    14401527 
    14411528        /*********************************************************************** 
    1442                  
    1443                 Close this appender. This would be used for file, sockets,  
     1529 
     1530                Close this appender. This would be used for file, sockets, 
    14441531                and such like. 
    14451532 
     
    14641551 
    14651552        /*********************************************************************** 
    1466                  
     1553 
    14671554                Create with the given Layout 
    14681555 
     
    14761563 
    14771564        /*********************************************************************** 
    1478                  
     1565 
    14791566                Return the fingerprint for this class 
    14801567 
     
    14871574 
    14881575        /*********************************************************************** 
    1489                  
     1576 
    14901577                Return the name of this class 
    14911578 
     
    14961583                return this.classinfo.name; 
    14971584        } 
    1498                  
    1499         /*********************************************************************** 
    1500                  
     1585 
     1586        /*********************************************************************** 
     1587 
    15011588                Append an event to the output. 
    1502                   
     1589 
    15031590        ***********************************************************************/ 
    15041591 
     
    15231610 
    15241611        /*********************************************************************** 
    1525                  
     1612 
    15261613                Create with the given stream and layout 
    15271614 
     
    15391626 
    15401627        /*********************************************************************** 
    1541                  
     1628 
    15421629                Return the fingerprint for this class 
    15431630 
     
    15501637 
    15511638        /*********************************************************************** 
    1552                  
     1639 
    15531640                Return the name of this class 
    15541641 
     
    15591646                return this.classinfo.name; 
    15601647        } 
    1561                  
    1562         /*********************************************************************** 
    1563                 
     1648 
     1649        /*********************************************************************** 
     1650 
    15641651                Append an event to the output. 
    1565                   
     1652 
    15661653        ***********************************************************************/ 
    15671654 
     
    15921679{ 
    15931680        /*********************************************************************** 
    1594                  
     1681 
    15951682                Subclasses should implement this method to perform the 
    15961683                formatting of the actual message content. 
     
    16221709{ 
    16231710        import tango.io.Console; 
    1624   
     1711 
    16251712        void main() 
    16261713        {