Mercurial > projects > ldc
comparison runtime/internal/genobj.d @ 1126:899a2d90645b
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.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 18 Mar 2009 15:33:19 +0100 |
parents | 8208374e5bed |
children | 30663babccff |
comparison
equal
deleted
inserted
replaced
1125:8208374e5bed | 1126:899a2d90645b |
---|---|
43 private | 43 private |
44 { | 44 { |
45 import tango.stdc.string; // : memcmp, memcpy, memmove; | 45 import tango.stdc.string; // : memcmp, memcpy, memmove; |
46 import tango.stdc.stdlib; // : calloc, realloc, free; | 46 import tango.stdc.stdlib; // : calloc, realloc, free; |
47 import util.string; | 47 import util.string; |
48 debug(PRINTF) import tango.stdc.stdio; // : printf; | 48 import tango.stdc.stdio; // : printf, snprintf; |
49 | 49 |
50 extern (C) void onOutOfMemoryError(); | 50 extern (C) void onOutOfMemoryError(); |
51 extern (C) Object _d_allocclass(ClassInfo ci); | 51 extern (C) Object _d_allocclass(ClassInfo ci); |
52 } | 52 } |
53 | 53 |
913 char[] func; | 913 char[] func; |
914 char[256] charBuf; | 914 char[256] charBuf; |
915 void writeOut(void delegate(char[])sink){ | 915 void writeOut(void delegate(char[])sink){ |
916 char[25] buf; | 916 char[25] buf; |
917 sink(func); | 917 sink(func); |
918 sprintf(buf.ptr,"@%zx ",address); | 918 auto len = snprintf(buf.ptr,buf.length,"@%zx ",address); |
919 sink(buf[0..strlen(buf.ptr)]); | 919 sink(buf[0..len]); |
920 sprintf(buf.ptr," %+td ",address); | 920 len = snprintf(buf.ptr,buf.length," %+td ",address); |
921 sink(buf[0..strlen(buf.ptr)]); | 921 sink(buf[0..len]); |
922 sink(file); | 922 if (file.length != 0 || line) { |
923 sprintf(buf.ptr,":%ld",line); | 923 sink(file); |
924 sink(buf[0..strlen(buf.ptr)]); | 924 len = snprintf(buf.ptr,buf.length,":%ld",line); |
925 sink(buf[0..len]); | |
926 } | |
925 } | 927 } |
926 } | 928 } |
927 interface TraceInfo | 929 interface TraceInfo |
928 { | 930 { |
929 int opApply( int delegate( ref FrameInfo fInfo ) ); | 931 int opApply( int delegate( ref FrameInfo fInfo ) ); |
945 this.info = info; | 947 this.info = info; |
946 } | 948 } |
947 | 949 |
948 this( char[] msg, Exception next=null ) | 950 this( char[] msg, Exception next=null ) |
949 { | 951 { |
950 this(msg,"",0,next,rt_createTraceContext(null)); | 952 this(msg,null,0,next,rt_createTraceContext(null)); |
951 } | 953 } |
952 | 954 |
953 this( char[] msg, char[] file, long line, Exception next=null ) | 955 this( char[] msg, char[] file, long line, Exception next=null ) |
954 { | 956 { |
955 this(msg,file,line,next,rt_createTraceContext(null)); | 957 this(msg,file,line,next,rt_createTraceContext(null)); |
959 { | 961 { |
960 return msg; | 962 return msg; |
961 } | 963 } |
962 | 964 |
963 void writeOut(void delegate(char[])sink){ | 965 void writeOut(void delegate(char[])sink){ |
964 if (file) | 966 if (file.length != 0 || line) |
965 { | 967 { |
966 char[25]buf; | 968 char[25]buf; |
967 sink(this.classinfo.name); | 969 sink(this.classinfo.name); |
968 sink("@"); | 970 sink("@"); |
969 sink(file); | 971 sink(file); |
970 sink("("); | 972 sink("("); |
971 sprintf(buf.ptr,"%ld",line); | 973 auto len = snprintf(buf.ptr,buf.length,"%ld",line); |
972 sink(buf[0..strlen(buf.ptr)]); | 974 sink(buf[0..len]); |
973 sink("): "); | 975 sink("): "); |
974 sink(toString()); | 976 sink(toString()); |
975 sink("\n"); | 977 sink("\n"); |
976 } | 978 } |
977 else | 979 else |
1025 * | 1027 * |
1026 * Returns: | 1028 * Returns: |
1027 * An object describing the current calling context or null if no handler is | 1029 * An object describing the current calling context or null if no handler is |
1028 * supplied. | 1030 * supplied. |
1029 */ | 1031 */ |
1030 extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){ | 1032 extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ) |
1031 { | 1033 { |
1032 if( traceHandler is null ) | 1034 if( traceHandler is null ) |
1033 return null; | 1035 return null; |
1034 return traceHandler( ptr ); | 1036 return traceHandler( ptr ); |
1035 } | 1037 } |