Changeset 279

Show
Ignore:
Timestamp:
05/24/07 23:06:22 (2 years ago)
Author:
pragma
Message:

Dirty Update Please use r278 for something stable.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/DDLError.d

    r143 r279  
    3434    un-recoverable. 
    3535*/ 
    36 class DDLError : Error{ 
     36class DDLError{ 
     37    char[] message; 
    3738    public this(char[] message){ 
    38         super( 
     39        this.message =  
    3940            "[Error] You have run into a condition not handled, or possibly incorrectly handled, by DDL.\n" ~ 
    4041            message ~ 
    4142            "\nPlease create a ticket (or look for similar ones) at http://trac.dsource.org/projects/ddl/newticket, explain the circumstances and paste this message into it. Also, if possible, please attach a minimal, reproducible testcase.\n - Thank You. -" 
    42         ); 
     43        ; 
     44    } 
     45     
     46    public char[] toUtf8(){ 
     47        return message; 
    4348    } 
    4449} 
  • trunk/ddl/DDLReader.d

    r271 r279  
    2424+/ 
    2525/** 
    26     Provides Mango binary Reader support, with a few enhancements 
     26    Provides Tango binary Reader support, with a few enhancements 
    2727     
    2828    Authors: Eric Anderton 
     
    3333 
    3434private import ddl.Utils; 
    35  
    36 private import mango.io.Reader; 
    37 private import mango.io.Buffer; 
    38 private import mango.io.model.IBuffer; 
    39 private import mango.io.model.IConduit; 
    40  
    41 debug private import mango.io.Stdout; 
     35private import ddl.FileBuffer; 
     36 
     37enum Anchor{ 
     38    None, 
     39    Begin, 
     40    End, 
     41    Current 
     42
    4243 
    4344/** 
    44     Mango IO Reader subclass. 
     45    Tango IO Reader subclass. 
    4546     
    4647    DDLReader provides a few key pieces of functionality that are used heavily within 
     
    5354    to subclass the reader, as to create a richer and more task-oriented feature set. 
    5455*/ 
    55 public class DDLReader : Reader{ 
    56     /** 
    57         Simple constructor.  Requires no IBuffer or IConduit instances. 
     56public class DDLReader{ 
     57    ubyte[] data; 
     58    size_t position; 
     59     
     60    /** 
     61        Simple constructor. 
    5862         
    5963        Params: 
     
    6165    */ 
    6266    public this(void[] data){ 
    63         super(new Buffer(data,data.length)); 
    64     } 
    65      
    66     /** 
    67         IBuffer style constructor. 
    68          
    69         Params: 
    70             buffer = buffer to read 
    71     */ 
    72     public this (IBuffer buffer){ 
    73         super(buffer); 
    74     } 
    75      
    76     /** 
    77         IConduit style constructor. 
    78          
    79         Params: 
    80             conduit = conduit to read 
    81     */ 
    82     public this (IConduit conduit){ 
    83         super(conduit); 
    84     } 
     67        this.data = cast(ubyte[])data; 
     68    } 
     69     
     70    public this(FileBuffer buffer){ 
     71        this.data = buffer.data; 
     72    }    
    8573     
    8674    /** 
     
    9280    */ 
    9381    public DDLReader peek(inout ubyte x){ 
    94         x = (cast(ubyte[])buffer.get(1,false))[0]; 
     82        assert(this.hasMore()); 
     83        x = data[position]; 
    9584        return this; 
    9685    }    
     
    10493            elements = (default: uint.max) the number of bytes to peek. 
    10594    */ 
    106     public DDLReader peek(inout ubyte[] x,uint elements = uint.max){ 
    107         if(elements == uint.max) 
    108            elements = buffer.readable
    109              
    110         assert(elements <= buffer.readable); 
    111          
    112         x = (cast(ubyte[])buffer.get(elements,false)); 
     95    public DDLReader peek(inout ubyte[] x,size_t elements = size_t.max){ 
     96        if(elements == size_t.max){ 
     97               x = data[position..$]
     98        } 
     99        else{ 
     100               x = data[position..position+elements]; 
     101        } 
    113102        return this; 
    114103    } 
     
    122111            x = (inout) will contain everything from the current read position to the end of the file. 
    123112    */ 
    124     DDLReader getAll(inout void[] x) 
     113    public DDLReader getAll(inout void[] x) 
    125114    {        
    126         //props to Kris for suggesting this method of getting 100% of the remaining data in a conduit 
    127         IConduit conduit = getBuffer.getConduit(); 
    128          
    129         x = getBuffer.get(getBuffer.readable); //exhaust the buffer 
    130          
    131         if(conduit){ 
    132             static const uint BUFFER_LEN = 8192; 
    133             void[] content = new void[BUFFER_LEN]; 
    134             uint filled = 0; 
     115        x = data[position..$]; 
     116        position = data.length;      
     117        return this; 
     118    } 
     119     
     120    public DDLReader _get(T)(inout T x) 
     121    { 
     122        //debug debugLog("reading element size: {0}",T.sizeof); 
     123        x = *(cast(T*)(data[position..position + T.sizeof].ptr)); 
     124        position += T.sizeof;        
     125        return this; 
     126    } 
     127 
     128    alias _get!(char) get; 
     129    alias _get!(wchar) get; 
     130    alias _get!(dchar) get; 
     131    alias _get!(byte) get; 
     132    alias _get!(ubyte) get; 
     133    alias _get!(short) get; 
     134    alias _get!(ushort) get;     
     135    alias _get!(int) get; 
     136    alias _get!(uint) get; 
     137    alias _get!(long) get; 
     138    alias _get!(ulong) get;  
     139     
     140    public DDLReader _getArray(T)(inout T[] x,size_t elements = size_t.max) 
     141    {        
     142        size_t end;  
     143        if(elements == size_t.max){ 
     144            //debug debugLog("reading max"); 
     145            end = data.length - (data.length % T.sizeof); 
     146            x = cast(T[])(data[position..end]); 
     147        } 
     148        else{ 
     149            //debug debugLog("size: {3} elements: {0} len: {1} pos: {2}",elements,data.length,position,T.sizeof); 
     150            end = position + (elements * T.sizeof); 
     151            x = cast(T[])(data[position..end]); 
     152        } 
     153        position = end; 
     154        return this; 
     155    } 
     156     
     157    alias _getArray!(char) get; 
     158    alias _getArray!(wchar) get; 
     159    alias _getArray!(dchar) get; 
     160    alias _getArray!(byte) get; 
     161    alias _getArray!(ubyte) get; 
     162    alias _getArray!(short) get; 
     163    alias _getArray!(ushort) get;    
     164    alias _getArray!(int) get; 
     165    alias _getArray!(uint) get; 
     166    alias _getArray!(long) get; 
     167    alias _getArray!(ulong) get;         
    135168             
    136             while(true){ 
    137                 uint chunk = conduit.read(content[filled..$]); 
    138                 if (chunk is conduit.Eof) 
    139                     break;       
    140                 filled += chunk; 
    141                 if (content.length - filled < 1024) 
    142                     content.length = content.length + BUFFER_LEN; 
    143             } 
    144             if(filled > 0){ 
    145                 x ~= content [0..filled]; // add on additional data 
    146             } 
    147         } 
    148          
    149         return this; 
    150     } 
    151      
    152169    /** 
    153170        Returns: (true/false) If the conduit has any more data to be read. 
    154171    */ 
    155172    bool hasMore(){ 
    156          
    157         //TODO: instead of try-catch, check for underflow instead 
    158         try{ 
    159             void[] result = getBuffer().get(1,false); 
    160             return result != null; 
    161         } 
    162         catch(Exception e){ 
    163             return false; 
    164         } 
     173        return position < data.length; 
    165174    } 
    166175     
     
    168177        Perform a seek relative to the current buffer position and status using the conduit. 
    169178         
    170         Some Mango conduits are seekable directly.  For all others, this method seeks by 
     179        Some Tango conduits are seekable directly.  For all others, this method seeks by 
    171180        manipulating the buffer and the current read position instead. 
    172181         
     
    179188            calculated (see: ISeekable.SeekAnchor for more info). 
    180189    */ 
    181     void seek(ulong offset, ISeekable.SeekAnchor anchor=ISeekable.SeekAnchor.Begin){ 
    182         IConduit conduit = getBuffer.getConduit(); 
    183          
    184         if(conduit){ 
    185             ISeekable seekableConduit = cast(ISeekable)(conduit); 
    186             assert(seekableConduit); 
    187              
    188             // seek and wipe out the buffer 
    189             switch(anchor){ 
    190             case ISeekable.SeekAnchor.Begin: 
    191             case ISeekable.SeekAnchor.End: 
    192                 seekableConduit.seek(offset,anchor); 
    193                 break; 
    194             case ISeekable.SeekAnchor.Current: 
    195                 seekableConduit.seek(offset - getBuffer.readable,anchor);        
    196                 break; 
    197             } 
    198             getBuffer.clear(); 
     190    DDLReader seek(ulong offset, Anchor anchor = Anchor.Begin){ 
     191        switch(anchor){ 
     192        case Anchor.Begin: 
     193            assert(offset < data.length); 
     194            position = offset; 
     195            break; 
     196        case Anchor.End: 
     197            assert(position + offset < data.length); 
     198            position = data.length + offset; 
     199            break; 
     200        default: 
     201        case Anchor.None: 
     202        case Anchor.Current: 
     203            assert(position + offset < data.length); 
     204            position += offset; 
     205            break; 
    199206        } 
    200         else{ // no conduit for buffer 
    201             switch(anchor){ 
    202             case ISeekable.SeekAnchor.Begin: 
    203                 getBuffer.skip(offset-getBuffer.getPosition); 
    204                 break; 
    205             case ISeekable.SeekAnchor.End: 
    206                 getBuffer.skip(getBuffer.readable-offset); 
    207                 break; 
    208             case ISeekable.SeekAnchor.Current: 
    209                 getBuffer.skip(offset); 
    210                 break; 
    211             }    
    212         } 
     207        return this; 
    213208    } 
    214209     
     
    216211        Returns: The position relative to the current buffer position. 
    217212    */ 
    218     ulong getPosition(){ 
    219         IConduit conduit = getBuffer.getConduit(); 
    220         if(conduit){ 
    221             ISeekable seekableConduit = cast(ISeekable)(conduit); 
    222             assert(seekableConduit);         
    223             return seekableConduit.getPosition() - getBuffer.readable;   
    224         } 
    225         else{ 
    226             return(getBuffer.getPosition); 
    227         } 
    228     } 
    229      
    230     // override to provide debug support 
    231     debug override protected uint read (void *dst, uint bytes, uint type){   
    232         try{ 
    233             return super.read(dst,bytes,type); 
    234         } 
    235         catch(Exception e){ 
    236             Stdout.println("Exception thrown while reading (%0.8X) %d bytes, type %d",dst,bytes,type); 
    237             throw e; 
    238         } 
    239         return 0; 
     213    size_t getPosition(){ 
     214        return position; 
     215    } 
     216     
     217    ubyte[] getData(){ 
     218        return data; 
    240219    } 
    241220} 
  • trunk/ddl/DDLWriter.d

    r271 r279  
    2424+/ 
    2525/** 
    26     Provides Mango binary Writer support, with a few enhancements 
     26    Provides Tango binary Writer support, with a few enhancements 
    2727     
    2828    Authors: Eric Anderton 
     
    3232module ddl.DDLWriter; 
    3333 
    34 private import mango.io.Writer; 
    35 private import mango.io.model.IBuffer; 
    36 private import mango.io.model.IConduit; 
     34private import ddl.Utils; 
     35private import ddl.FileBuffer; 
     36 
     37enum Anchor{ 
     38    None, 
     39    Begin, 
     40    End, 
     41    Current 
     42
    3743 
    3844/** 
    39     Mango IO Writer subclass. 
     45    Tango IO Writer subclass. 
    4046     
    4147    DDLWriter, apart from adding symmetry to DDLReader, provides seeking capability for  
    4248    random-access <i>output</i>. 
    4349*/ 
    44 public class DDLWriter : Writer{ 
     50public class DDLWriter{ 
     51    ubyte[] data; 
     52    uint position; 
     53     
    4554    /** 
    4655        IBuffer style constructor. 
     
    4958            buffer = buffer to read 
    5059    */ 
    51     public this (IBuffer buffer){ 
    52         super(buffer)
     60    public this (){ 
     61        position = 0
    5362    } 
    5463     
    55     /** 
    56         IConduit style constructor. 
    57          
    58         Params: 
    59             conduit = conduit to read 
    60     */   
    61     public this (IConduit conduit){ 
    62         super(conduit); 
     64    public this (ubyte[] data){ 
     65        this.data = data; 
     66        position = data.length; 
     67    }    
     68     
     69    public this(FileBuffer buffer){ 
     70        this.data = buffer.data; 
     71        position = 0; 
     72    }    
     73     
     74    DDLWriter putAll(void[] x){ 
     75        ubyte[] newData = cast(ubyte[])x; 
     76        if(position == data.length){ 
     77            data ~= newData; 
     78            position = data.length; 
     79        } 
     80        else{ 
     81            data[position..position+newData.length] = newData; 
     82        } 
     83        return this; 
    6384    } 
    6485     
    65      
     86    DDLWriter put(T)(T x){ 
     87        ubyte[] newData = (cast(ubyte*)(cast(void*)&x))[0..T.sizeof]; 
     88        if(position == data.length){ 
     89            data ~= newData; 
     90            position = data.length; 
     91        } 
     92        else{ 
     93            data[position..position+newData.length] = newData; 
     94            position += newData.length; 
     95        } 
     96        return this; 
     97    } 
     98         
    6699    /** 
    67100        Perform a seek relative to the current buffer position and status using the conduit. 
    68101         
    69         Some Mango conduits are seekable directly.  For all others, this method seeks by 
     102        Some Tango conduits are seekable directly.  For all others, this method seeks by 
    70103        manipulating the buffer and the current read position instead. 
    71104         
     
    78111            calculated (see: ISeekable.SeekAnchor for more info). 
    79112    */ 
    80     void seek(ulong offset, ISeekable.SeekAnchor anchor=ISeekable.SeekAnchor.Begin){ 
    81         IConduit conduit = getBuffer.getConduit(); 
    82          
    83         if(conduit){ 
    84             ISeekable seekableConduit = cast(ISeekable)(conduit); 
    85             assert(seekableConduit); 
    86              
    87             // seek and wipe out the buffer 
    88             ulong writable = getBuffer.readable; 
    89             getBuffer.flush(); 
    90                      
    91             switch(anchor){ 
    92             case ISeekable.SeekAnchor.Begin: 
    93             case ISeekable.SeekAnchor.End: 
    94                 seekableConduit.seek(offset,anchor); 
    95                 break; 
    96             case ISeekable.SeekAnchor.Current: 
    97                 seekableConduit.seek(offset - writable,anchor);      
    98                 break; 
    99             } 
     113    DDLWriter seek(ulong offset, Anchor anchor = Anchor.Begin){ 
     114        switch(anchor){ 
     115        case Anchor.Begin: 
     116            assert(offset < data.length); 
     117            position = offset; 
     118            break; 
     119        case Anchor.End: 
     120            assert(data.length + offset < data.length); 
     121            position = data.length + offset; 
     122            break; 
     123        default: 
     124        case Anchor.None: 
     125        case Anchor.Current: 
     126            assert(position + offset < data.length); 
     127            position += offset; 
     128            break; 
    100129        } 
    101         else{ // no conduit for buffer 
    102             switch(anchor){ 
    103             case ISeekable.SeekAnchor.Begin: 
    104                 getBuffer.skip(offset-getBuffer.getPosition); 
    105                 break; 
    106             case ISeekable.SeekAnchor.End: 
    107                 getBuffer.skip(getBuffer.readable-offset); 
    108                 break; 
    109             case ISeekable.SeekAnchor.Current: 
    110                 getBuffer.skip(offset); 
    111                 break; 
    112             }    
    113         }        
     130        return this; 
    114131    } 
    115132     
     
    117134        Returns: The position relative to the current buffer position. 
    118135    */ 
    119     ulong getPosition(){ 
    120         IConduit conduit = getBuffer.getConduit(); 
    121         if(conduit){ 
    122             ISeekable seekableConduit = cast(ISeekable)(conduit); 
    123             assert(seekableConduit);         
    124             return seekableConduit.getPosition() + getBuffer.readable;   
    125         } 
    126         else{ 
    127             return(getBuffer.getPosition); 
    128         } 
    129     }    
     136    size_t getPosition(){ 
     137        return position; 
     138    } 
     139     
     140    ubyte[] getData(){ 
     141        return data; 
     142    } 
    130143} 
  • trunk/ddl/Demangle.d

    r271 r279  
    3333module ddl.Demangle; 
    3434 
    35 private import std.demangle; 
     35private import etc.demangle; 
    3636 
    3737debug private import ddl.Utils; 
     
    4646    PublicSymbol, 
    4747    PublicDSymbol, 
    48     ClassDefinition, 
    49     Initalizer, 
    50     Vtable, 
    51     VarArguments, 
    52     PlatformHook, 
    53     DAssert, 
    54     DArray, 
    55     ModuleCtor, 
    56     ModuleDtor, 
    57     ModuleInfo, 
    58     Main, 
    59     WinMain, 
    60     Nullext 
     48    ModuleInfo 
    6149} 
    6250 
     
    7260*/ 
    7361public char[] demangleSymbol(char[] symbol){ 
    74     return std.demangle.demangle(symbol); 
     62    return demangle(symbol); 
    7563} 
    7664 
    7765bool startsWith(char[] value,char[] test){ 
    7866    return value.length >= test.length && value[0..test.length] == test; 
     67} 
     68 
     69bool endsWith(char[] value,char[] test){ 
     70    return value.length >= test.length && value[$-test.length .. $] == test; 
    7971} 
    8072 
     
    8981*/ 
    9082public DemangleType getDemangleType(char[] symbol){ 
    91     if(symbol.startsWith("_Class")){ 
    92         return DemangleType.ClassDefinition; 
    93     } 
    94     else if(symbol.startsWith("__init_")){ 
    95         return DemangleType.Initalizer; 
    96     } 
    97     else if(symbol.startsWith("__vtbl_")){ 
    98         return DemangleType.Vtable; 
    99     } 
    100     else if(symbol.startsWith("__arguments_")){ 
    101         return DemangleType.VarArguments; 
    102     } 
    103     else if(symbol.startsWith("__d")){ 
    104         return DemangleType.PlatformHook; 
    105     } 
    106     else if(symbol.startsWith("_assert_")){ 
    107         return DemangleType.DAssert; 
    108     } 
    109     else if(symbol.startsWith("_array_")){ 
    110         return DemangleType.DArray; 
    111     }    
    112     else if(symbol.startsWith("__modctor_")){ 
    113         return DemangleType.ModuleCtor; 
    114     } 
    115     else if(symbol.startsWith("__moddtor_")){ 
    116         return DemangleType.ModuleDtor; 
    117     } 
    118     else if(symbol.startsWith("__ModuleInfo_")){ 
     83    if (symbol.endsWith("__ModuleInfoZ")) { 
    11984        return DemangleType.ModuleInfo; 
    12085    } 
    121     else if(symbol.startsWith("__nullext")){ 
    122         return DemangleType.Nullext; 
    123     } 
    124     else if(symbol.startsWith("_Dmain")){ 
    125         return DemangleType.Main; 
    126     }    
    127     else if(symbol.startsWith("_DWinMain")){ 
    128         return DemangleType.WinMain; 
    129     }        
    13086    else if(symbol.startsWith("_D")){ 
    13187        return DemangleType.PublicDSymbol; 
     
    179135    return result; 
    180136} 
     137 
  • trunk/ddl/DynamicLibrary.d

    r271 r279  
    146146    template getClassInfo(char[] classname){ 
    147147        ClassInfo getClassInfo(){ 
    148             return cast(ClassInfo)getSymbol("__Class_" ~  mangleSymbolName!(classname)).address; 
     148            return cast(ClassInfo)getSymbol("_D" ~ mangleSymbolName!(classname) ~ "7__ClassZ").address; 
    149149        } 
    150150    }    
     
    240240      foreach (mod; getModules) { 
    241241         foreach (sym; mod.getSymbols) { 
    242             const char[] prefix = `__Class_`; 
     242            const char[] suffix = `7__ClassZ`; 
    243243             
    244             if (sym.name.length > prefix.length && sym.name[0 .. prefix.length] == prefix) { 
     244            if (sym.name.length > suffix.length && sym.name[$-suffix.length .. $] == suffix) { 
    245245               ClassInfo ci = cast(ClassInfo)getSymbol(sym.name).address; 
    246246               assert (ci !is null); 
     
    248248               uint dummy; 
    249249               if (T.classinfo !is ci && _d_isbaseof2(ci, T.classinfo, dummy)) { 
    250                   res ~= new ExportClass!(T)(ci, sym.name[prefix.length .. length], this); 
     250                  res ~= new ExportClass!(T)(ci, sym.name[0 .. $-suffix.length], this); 
    251251               } 
    252252            } 
  • trunk/ddl/DynamicLibraryLoader.d

    r195 r279  
    5353        Returns: true if the file can be loaded by this loader, false if it cannot. 
    5454    */ 
    55     public bit canLoadLibrary(FileBuffer file); 
     55    public bool canLoadLibrary(FileBuffer file); 
    5656     
    5757    /** 
  • trunk/ddl/ExportClass.d

    r271 r279  
    3030import ddl.DDLException; 
    3131 
    32 import std.regexp : RegExp
     32import tango.text.Regex
    3333 
    3434/** 
  • trunk/ddl/ExportSymbol.d

    r272 r279  
    7878    */ 
    7979    public char[] name; 
    80      
     80 
     81    /** 
     82        Line number of the symbol in the original sourcecode, or zero if debug information is not 
     83        available in the parent module. 
     84    */ 
     85    public ushort lineNumber; 
     86 
    8187    /**  
    8288        Returns the resolution status of this symbol. 
  • trunk/ddl/FileBuffer.d

    r271 r279  
    2525module ddl.FileBuffer; 
    2626 
    27 private import mango.io.Buffer
    28 private import mango.io.FileConduit; 
     27private import tango.io.File
     28private import tango.io.FileConduit; 
    2929 
    30 private import mango.io.model.IBuffer; 
    31 private import mango.io.model.IConduit; 
    32  
    33 /** 
    34     Gives the basic Mango buffer class some additional information about its origin. 
    35 */ 
    36 //TODO: should this pre-buffer the entire file into memory first? 
    37 class FileBuffer: Buffer{ 
     30struct FileBuffer{ 
    3831    FilePath path; 
    39      
    40     public this(char[] path, FileStyle.Bits style = FileStyle.ReadExisting){ 
    41         this.path = new FilePath(path); 
    42         super(new FileConduit(this.path,style)); 
     32    ubyte[] data; 
     33         
     34    static FileBuffer opCall(char[] path){ 
     35        FileBuffer _this; 
     36        _this.path = new FilePath(path);         
     37        _this.data = cast(ubyte[])(new File(_this.path)).read; 
     38        return _this; 
    4339    } 
    4440     
    45     public this(FilePath path, FileStyle.Bits style = FileStyle.ReadExisting){ 
    46         super(new FileConduit(path,style)); 
    47         this.path = path; 
     41    static FileBuffer opCall(FilePath path){ 
     42        FileBuffer _this; 
     43        _this.path = new FilePath(path.toUtf8);      
     44        _this.data = cast(ubyte[])(new File(_this.path)).read; 
     45        return _this; 
    4846    } 
    4947     
    50     public this(FilePath path,void[] data){ 
    51         super(data,data.length); 
    52         this.path = path; 
     48    static FileBuffer opCall(char[] path,ubyte[] data){ 
     49        FileBuffer _this; 
     50        _this.path = new FilePath(path);         
     51        _this.data = data; 
     52        return _this; 
     53    }    
     54     
     55    static FileBuffer opCall(FilePath path,ubyte[] data){ 
     56        FileBuffer _this; 
     57        _this.path = new FilePath(path.toUtf8);      
     58        _this.data = data; 
     59        return _this; 
    5360    } 
    5461     
    55     public this(char[] path,void[] data){ 
    56         super(data,data.length); 
    57         this.path = new FilePath(path); 
    58     }    
    59      
    60     public this(IConduit conduit,FilePath path){ 
    61         super(conduit); 
    62         this.path = path; 
    63     } 
    64      
    65     public this(FileConduit file){ 
    66         super(file); 
    67         this.path = file.getPath; 
    68     } 
    69      
    70     public FilePath getPath(){ 
     62    FilePath getPath(){ 
    7163        return path; 
    7264    } 
    7365     
    74     public IBuffer.Style getStyle(){ 
    75         return IBuffer.Mixed; 
    76     } 
    77      
    78     public void close(){ 
    79         this.flush(); 
    80         this.getConduit().close(); 
     66    void save(){ 
     67        (new File(this.path)).write(this.data); 
    8168    } 
    8269} 
  • trunk/ddl/Linker.d

    r273 r279  
    11/+ 
    2     Copyright (c) 2005-2006 Eric Anderton, Tomasz Stachowiak 
     2    Copyright (c) 2005-2007 Eric Anderton, Tomasz Stachowiak 
    33         
    44    Permission is hereby granted, free of charge, to any person 
     
    3737private import ddl.DDLException; 
    3838 
    39 private import std.moduleinit; // used for ModuleInfo type 
    40  
    4139debug private import ddl.Utils; 
    4240 
     41 
     42 
     43// for the phobos backtrace hack 
     44version(Stacktrace){ 
     45    extern(C) extern void regist_cb(char* name, void* fp); 
     46    extern(C) extern void addDebugLineInfo__(uint addr, ushort line, char* file); 
     47} 
    4348/** 
    4449    Exception class used exclusively by the Linker. 
     
    6368    */ 
    6469    public this(DynamicModule reason){ 
    65         super("LinkModuleException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toString()); 
     70        super("LinkModuleException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toUtf8()); 
     71        this.mod = reason; 
     72    } 
     73
     74 
     75class ModuleCtorError : Exception{ 
     76    ModuleInfo mod; 
     77     
     78    /** 
     79        Module that prompted the link exception. 
     80    */ 
     81    ModuleInfo reason(){ 
     82        return this.mod; 
     83    } 
     84     
     85    /** 
     86        Constructor. 
     87         
     88        Params: 
     89            reason = the module that prompts the exception 
     90    */ 
     91    public this(ModuleInfo reason){ 
     92        super("ModuleCtorError: cannot init '" ~ reason.name ~ "'\n"); 
    6693        this.mod = reason; 
    6794    } 
     
    119146        if (m.flags & MIctordone) return; 
    120147 
    121         debug debugLog("this module: %0.8X",cast(void*)m); 
    122         debug debugLog("(name: %0.8X %d)",m.name.ptr,m.name.length);       
    123         debug debugLog("(ctor: %0.8X)",cast(void*)(m.ctor)); 
    124         debug debugLog("(dtor: %0.8X)",cast(void*)(m.dtor)); 
    125         debug debugLog("Module: %s\n",m.name); 
     148        debug debugLog("this module: {0:X8}",cast(void*)m); 
     149        debug debugLog("(name: {0:X8} %d)",m.name.ptr,m.name.length);      
     150        debug debugLog("(ctor: {0:X8})",cast(void*)(m.ctor)); 
     151        debug debugLog("(dtor: {0:X8})",cast(void*)(m.dtor)); 
     152        debug debugLog("Module: {0}\n",m.name); 
    126153         
    127154        if (m.ctor || m.dtor) 
     
    130157            {   if (skip) 
    131158                return; 
    132             throw new ModuleCtorError(m); 
     159               throw new ModuleCtorError(m);                
    133160            } 
    134161             
    135162            m.flags |= MIctorstart; 
    136             debug debugLog("running imported modules (%d)...",m.importedModules.length); 
     163            debug debugLog("running imported modules ({0})...",m.importedModules.length); 
    137164            foreach(ModuleInfo imported; m.importedModules){ 
    138                 debug debugLog("running: [%0.8X]",cast(void*)imported); 
     165                debug debugLog("running: [{0:X8}]",cast(void*)imported); 
    139166                initModule(imported,0); 
    140167                debug debugLog("-done."); 
    141168            } 
    142             debug debugLog("running ctor [%0.8X]",cast(void*)m.ctor); 
     169            debug debugLog("running ctor [{0:X8}]",cast(void*)m.ctor); 
    143170            if (m.ctor) 
    144171            (*m.ctor)(); 
     
    152179        { 
    153180            m.flags |= MIctordone; 
    154             debug debugLog("running imported modules (%d)...",m.importedModules.length); 
     181            debug debugLog("running imported modules ({0})...",m.importedModules.length); 
    155182            foreach(ModuleInfo imported; m.importedModules){ 
    156                 debug debugLog("running: [%0.8X]",cast(void*)imported); 
     183                debug debugLog("running: [{0:X8}]",cast(void*)imported); 
    157184                initModule(imported,1); 
    158185                debug debugLog("-done."); 
     
    237264        auto allSymbols = mod.getSymbols(); 
    238265        foreach (symbol; allSymbols) { 
     266            version(Stacktrace){ 
     267                if (symbol.address !is null) { 
     268                    //printf("symbol %.*s line: %d\n", symbol.name, symbol.lineNumber); 
     269                    regist_cb((symbol.name ~ \0).ptr, symbol.address); 
     270                    addDebugLineInfo__(cast(uint)symbol.address, symbol.lineNumber, mod.getName); 
     271                } 
     272            } 
     273 
    239274            // symbol must be defined and be local only 
    240275            if (symbol.address is null || symbol.isExternal) continue; 
    241             if (symbol.name.length > `__ModuleInfo_`.length && symbol.name[0 .. `__ModuleInfo_`.length] == `__ModuleInfo_`) { 
     276            char[] suffix = `__ModuleInfoZ`; 
     277            if (symbol.name.length > suffix.length && symbol.name[$ - suffix.length .. $] == suffix) { 
    242278                debug debugLog("Found moduleinfo for %s at [%0.8X] %s",mod.getName,symbol.address,symbol.name); 
    243279                moduleSet[symbol.name] = cast(ModuleInfo)(symbol.address); 
  • trunk/ddl/LoaderRegistry.d

    r261 r279  
    11/+ 
    2     Copyright (c) 2005-2006 Eric Anderton 
     2    Copyright (c) 2005-2007 Eric Anderton 
    33         
    44    Permission is hereby granted, free of charge, to any person 
     
    2929private import ddl.FileBuffer; 
    3030 
    31 debug private import mango.io.Stdout; 
     31debug private import tango.io.Stdout; 
    3232 
    3333debug private import ddl.Utils; 
     
    144144        DynamicLibrary lib; 
    145145        foreach(DynamicLibraryLoader loader;loaders){ 
    146             debug debugLog("LoaderRegistry.load: trying %s loader",loader.getLibraryType); 
     146            debug debugLog("LoaderRegistry.load: trying {0} loader",loader.getLibraryType); 
    147147            if(loader.canLoadLibrary(buffer)){ 
    148148                lib = loader.load(this,buffer); 
     
    153153                        delete lib; // force collection on 'result' 
    154154                        lib = null; 
    155                         throw new LibraryVersionException(buffer.getPath.toString(),attrStdVersion,*libraryStdVersion); 
     155                        throw new LibraryVersionException(buffer.getPath.toUtf8(),attrStdVersion,*libraryStdVersion); 
    156156                    } 
    157157                } 
     
    178178    */ 
    179179    public DynamicLibrary load(char[] filename,char[] attrStdVersion = ""){ 
    180         return load(new FileBuffer(filename),attrStdVersion); 
     180        return load(FileBuffer(filename),attrStdVersion); 
    181181    } 
    182182     
     
    186186            file = the file to test.  The file is expected to already be loaded. 
    187187    */ 
    188     public bit canLoad(FileBuffer file){ 
     188    public bool canLoad(FileBuffer file){ 
    189189        foreach(DynamicLibraryLoader loader;loaders){ 
    190190            if(loader.canLoadLibrary(file)){ 
     
    200200            filename = name of the file to test. 
    201201    */ 
    202     public bit canLoad(char[] filename){