Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #235: obj.patch

File obj.patch, 4.8 kB (added by fawzi, 3 years ago)

updated patch

  • a/runtime/internal/dmain2.d

    old new  
    230230            } 
    231231            catch (Exception e) 
    232232            { 
    233                 while (e) 
    234                 { 
    235                     if (e.file) 
    236                     { 
    237                        // fprintf(stderr, "%.*s(%u): %.*s\n", e.file, e.line, e.msg); 
    238                        console (e.classinfo.name)("@")(e.file)("(")(e.line)("): ")(e.toString)("\n"); 
    239                     } 
    240                     else 
    241                     { 
    242                        // fprintf(stderr, "%.*s\n", e.toString()); 
    243                        console (e.classinfo.name)(": ")(e.toString)("\n"); 
    244                     } 
    245                     if (e.info) 
    246                     { 
    247                         console ("----------------\n"); 
    248                         foreach (t; e.info) 
    249                             console (t)("\n"); 
    250                     } 
    251                     if (e.next) 
    252                         console ("\n"); 
    253                     e = e.next; 
    254                 } 
     233                e.writeOut(delegate void(char[]s){ console(s); }); 
    255234                result = EXIT_FAILURE; 
    256235            } 
    257236            catch (Object o) 
  • a/runtime/internal/genobj.d

    old new  
    4949 
    5050    extern (C) void onOutOfMemoryError(); 
    5151    extern (C) Object _d_allocclass(ClassInfo ci); 
     52    extern (C) int snprintf(char * s, size_t n, char * format, ...); 
    5253} 
    5354 
    5455// NOTE: For some reason, this declaration method doesn't work 
     
    902903// Exception 
    903904//////////////////////////////////////////////////////////////////////////////// 
    904905 
    905  
    906906class Exception : Object 
    907907{ 
     908    struct FrameInfo{ 
     909        long line; 
     910        ptrdiff_t offset; 
     911        size_t address; 
     912        char[] file; 
     913        char[] func; 
     914        char[256] charBuf; 
     915        void writeOut(void delegate(char[])sink){ 
     916            char[25] buf; 
     917            sink(func); 
     918            auto len=snprintf(buf.ptr,buf.length,"@%zx ",address); 
     919            assert(len>=0); 
     920            sink(buf[0..len]); 
     921            len=snprintf(buf.ptr,buf.length," %+td ",address); 
     922            assert(len>=0); 
     923            sink(buf[0..len]); 
     924            sink(file); 
     925            len=snprintf(buf.ptr,buf.length,":%ld",line); 
     926            assert(len>=0); 
     927            sink(buf[0..len]); 
     928        } 
     929    } 
    908930    interface TraceInfo 
    909931    { 
    910         int opApply( int delegate( inout char[] ) ); 
     932        int opApply( int delegate( ref FrameInfo fInfo ) ); 
    911933    } 
    912934 
    913935    char[]      msg; 
     
    916938    TraceInfo   info; 
    917939    Exception   next; 
    918940 
    919     this( char[] msg, Exception next = null
     941    this( char[] msg, char[] file, long line, Exception next, TraceInfo info
    920942    { 
     943        // main constructor, breakpoint this if you want... 
    921944        this.msg = msg; 
    922945        this.next = next; 
    923         this.info = traceContext(); 
     946        this.file = file; 
     947        this.line = cast(size_t)line; 
     948        this.info = info; 
    924949    } 
    925950 
    926     this( char[] msg, char[] file, size_t line, Exception next = null ) 
     951    this( char[] msg, Exception next=null ) 
    927952    { 
    928         this(msg, next); 
    929         this.file = file; 
    930         this.line = line; 
    931         this.info = traceContext(); 
     953        this(msg,"",0,next,rt_createTraceContext(null)); 
     954    } 
     955 
     956    this( char[] msg, char[] file, long line, Exception next=null ) 
     957    { 
     958        this(msg,file,line,next,rt_createTraceContext(null)); 
    932959    } 
    933960 
    934961    char[] toString() 
    935962    { 
    936963        return msg; 
     964    } 
     965     
     966    void writeOut(void delegate(char[])sink){ 
     967        if (file) 
     968        { 
     969            char[25]buf; 
     970            sink(this.classinfo.name); 
     971            sink("@"); 
     972            sink(file); 
     973            sink("("); 
     974            auto len=snprintf(buf.ptr,buf.length,"%ld",line); 
     975            assert(len>=0); 
     976            sink(buf[0..len]); 
     977            sink("): "); 
     978            sink(toString()); 
     979            sink("\n"); 
     980        } 
     981        else 
     982        { 
     983           sink(this.classinfo.name); 
     984           sink(": "); 
     985           sink(toString); 
     986           sink("\n"); 
     987        } 
     988        if (info) 
     989        { 
     990            sink("----------------\n"); 
     991            foreach (ref t; info){ 
     992                t.writeOut(sink); 
     993                sink("\n"); 
     994            } 
     995        } 
     996        if (next){ 
     997            sink("\n"); 
     998            next.writeOut(sink); 
     999        } 
    9371000    } 
    9381001} 
    9391002 
     
    9681031 *  An object describing the current calling context or null if no handler is 
    9691032 *  supplied. 
    9701033 */ 
    971 Exception.TraceInfo traceContext( void* ptr = null ) 
    972 
     1034extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){ 
    9731035    if( traceHandler is null ) 
    9741036        return null; 
    9751037    return traceHandler( ptr ); 
Copyright © 2008, LDC Development Team.