# HG changeset patch # User Frits van Bommel # Date 1237386799 -3600 # Node ID 899a2d90645ba9495a8d1fe5bdcc4b9dd86b77ae # Parent 8208374e5bedb73453b367a8edbbb5a9d8eaeb0c Fix some issues with fawzi's patch. - It now actually compiles: - import stdc.stdio for string formatting functions) - remove extra '{' - Use snprintf() instead of sprintf(). - Use return value from snprintf instead of strlen(). - Don't print the filename in Exception.writeOut() if it has zero length and the line number is 0 (It would previously only skip these if the filename was null, but not if it was a different empty string) - Ignore empty filename + line number 0 in FrameInfo.writeOut() as well. diff -r 8208374e5bed -r 899a2d90645b runtime/internal/genobj.d --- a/runtime/internal/genobj.d Wed Mar 18 15:20:07 2009 +0100 +++ b/runtime/internal/genobj.d Wed Mar 18 15:33:19 2009 +0100 @@ -45,7 +45,7 @@ import tango.stdc.string; // : memcmp, memcpy, memmove; import tango.stdc.stdlib; // : calloc, realloc, free; import util.string; - debug(PRINTF) import tango.stdc.stdio; // : printf; + import tango.stdc.stdio; // : printf, snprintf; extern (C) void onOutOfMemoryError(); extern (C) Object _d_allocclass(ClassInfo ci); @@ -915,13 +915,15 @@ void writeOut(void delegate(char[])sink){ char[25] buf; sink(func); - sprintf(buf.ptr,"@%zx ",address); - sink(buf[0..strlen(buf.ptr)]); - sprintf(buf.ptr," %+td ",address); - sink(buf[0..strlen(buf.ptr)]); - sink(file); - sprintf(buf.ptr,":%ld",line); - sink(buf[0..strlen(buf.ptr)]); + auto len = snprintf(buf.ptr,buf.length,"@%zx ",address); + sink(buf[0..len]); + len = snprintf(buf.ptr,buf.length," %+td ",address); + sink(buf[0..len]); + if (file.length != 0 || line) { + sink(file); + len = snprintf(buf.ptr,buf.length,":%ld",line); + sink(buf[0..len]); + } } } interface TraceInfo @@ -947,7 +949,7 @@ this( char[] msg, Exception next=null ) { - this(msg,"",0,next,rt_createTraceContext(null)); + this(msg,null,0,next,rt_createTraceContext(null)); } this( char[] msg, char[] file, long line, Exception next=null ) @@ -961,15 +963,15 @@ } void writeOut(void delegate(char[])sink){ - if (file) + if (file.length != 0 || line) { char[25]buf; sink(this.classinfo.name); sink("@"); sink(file); sink("("); - sprintf(buf.ptr,"%ld",line); - sink(buf[0..strlen(buf.ptr)]); + auto len = snprintf(buf.ptr,buf.length,"%ld",line); + sink(buf[0..len]); sink("): "); sink(toString()); sink("\n"); @@ -1027,7 +1029,7 @@ * An object describing the current calling context or null if no handler is * supplied. */ -extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){ +extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ) { if( traceHandler is null ) return null;