digitalmars.D.bugs - [Patch] phobos: replaced printf with writef
- Thomas Kuehne (255/255) Oct 06 2004 Replaced printf with writef in the release code of phobos. Most unittest...
- Ben Hinkle (6/14) Oct 06 2004 shouldn't
- Stewart Gordon (5/21) Oct 06 2004 What's wrong with
- Ben Hinkle (6/32) Oct 06 2004 I haven't actually tried it but yeah that might work as long as there ar...
- Stewart Gordon (18/28) Oct 06 2004 Oops, that wasn't what I meant to say.
- Thomas Kuehne (3/15) Oct 07 2004 I forgot that :O
- Derek (9/35) Oct 06 2004 The first parameter is supposed to be a template or pattern, thus if 'ms...
Replaced printf with writef in the release code of phobos. Most unittests
still remain to be converted.
Note: if you haven't applied the patch from digitalmars.com
digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private"
keyword).
Thomas
begin 666 phobos__substitute_printf_with_writef.diff
M9&EF9B M=7( 9&UD+W-R8R]P:&]B;W,O:6YT97)N86PO9&UA:6XR+F0 9&UD
M+W-R8R]P:&]B;W-?;F5U+VEN=&5R;F%L+V1M86EN,BYD"BTM+2!D;60O<W)C
M.PT*+7!R:79A=&4 :6UP;W)T('-T9"YC+G-T9&EO.PT**W!R:79A=&4 :6UP
M;W)T('-T9"YS=&1I;SL-"B!P<FEV871E(&EM<&]R="!S=&0N8RYS=&1L:6([
M?0T*3G5R(&EN(&1M9"]S<F,O<&AO8F]S7VYE=2]I;G1E<FYA;#H 9&UA:6XR
M+F1^+ ID:69F("UU<B!D;60O<W)C+W!H;V)O<R]I;G1E<FYA;"]O8FIE8W0N
M9"!D;60O<W)C+W!H;V)O<U]N974O:6YT97)N86PO;V)J96-T+F0*+2TM(&1M
M:6YT97)N86PO;V)J96-T+F0),C P-"TQ,"TP-B P,CHR-3HQ,BXU-S(Q-3DY
M.PT*+2 ("!I;G0 =W!R:6YT9BAW8VAA<B J+" N+BXI.PT*+7T-"BMP<FEV
M(" >PT*+0EP<FEN=&8H(B4N*G-<;B(L('1O4W1R:6YG*"DI.PT**PEW<FET
M968H=&]3=')I;F<H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PT**PD (" =W)I=&5F*")I(#T (BP :2P (EQN(BD[
M;G8I('=R:71E9B B8V]N=BYT;U-H;W)T+G5N:71T97-T7&XB*3L-"B -"B
M>PT*( D (" :2 ]('1O4VAO<G0H97)R;W)S6VI=*3L-"BT)(" ('!R:6YT
M9B B:2 ]("5D7&XB+"!I*3L-"BL)(" ('=R:71E9B B:2 ]("5D7&XB+"!I
M*3L-"B )?0T*( EC871C:" H17)R;W( 92D-"B )>PT*0$ +38P."PW("LV
M,#DL-R
M('!R:6YT9B B:2 ]("5D7&XB+"!I*3L-"BL)(" ('=R:71E9B B:2 ]("5D
M7&XB+"!I*3L-"B )?0T*( EC871C:" H17)R;W( 92D-"B )>PT*0$ +38X
M."PW("LV.#DL-R
M;G8I('!R:6YT9B B8V]N=BYT;T)Y=&4N=6YI='1E<W1<;B(I.PT**R ("!D
M96)U9RAC;VYV*2!W<FET968H(F-O;G8N=&]">71E+G5N:71T97-T7&XB*3L-
M+" B7&XB*3L-"B )?0T*( EC871C:" H17)R;W( 92D-"B )>PT*0$ +3<W
M;G8I('!R:6YT9B B8V]N=BYT;U5B>71E+G5N:71T97-T7&XB*3L-"BL ("
M9&5B=6<H8V]N=BD =W)I=&5F*")C;VYV+G1O56)Y=&4N=6YI='1E<W1<;B(I
M.PT*( T*(" ("!U8GET92!I.PT*( T*0$ +3 Q.2PW("LX,C L-R! 0 H
M(" <')I;G1F*")I(#T )61<;B(L(&DI.PT**PD (" =W)I=&5F*")I(#T
M<U]N974O<W1D+VUD-2YD"BTM+2!D;60O<W)C+W!H;V)O<R]S=&0O;60U+F0)
M,C P-"TQ,"TP-B P,CHR,#HT-
M<F,O<&AO8F]S7VYE=2]S=&0O;60U+F0),C P-"TQ,"TP-B P,CHR-3HQ,BXU
M.PD)+R\ =6YC;VUM96YT('1O('1U<FX ;VX 9&5B=6=G:6YG('!R:6YT9B=S
M=$1I9V5S="AU8GET92!D:6=E<W1;,39=*0T*('L-"B (" 9F]R96%C:" H
M=6)Y=&4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0D)"2\O(&%D:0T*(" ("!A+G-O
M(&-R96%L(&, /2 S+C *R T+C!I.PT*(" ("!C(#T <W%R="AC*3L-"BT
M(" <')I;G1F*")R92 ]("5,9RP :6T /2 E3&=<;B(L(&,N<F4L(&,N:6TI
M.PT**R ("!W<FET968H(G)E(#T (BP 8RYR92P (BP :6T /2 B+"!C+FEM
M.PT*+2 ("!P<FEN=&8H(F%R9W,N;&5N9W1H(#T )61<;B(L(&%R9W,N;&5N
M:71E9B B87)G<RYL96YG=& /2 B+"!A<F=S+FQE;F=T:"PB7&XB*3L-"B
M<FEN=&8H(F%R9W-;)61=(#T )R5S)UQN(BP :2P 8V%S="AC:&%R("HI87)G
M(F%R9W-;(BQI+")=(#T (BQA<F=S6VE=+")<;B(I.PT**R ("!W<FET968H
F(E-U8V-E<W-<;B%<;B(I.PT*(" ("!R971U<FX ,#L-
`
end
Oct 06 2004
Thomas Kuehne wrote:Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). Thomasshouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.
Oct 06 2004
Ben Hinkle wrote:Thomas Kuehne wrote:What's wrong with writefln(msg); ? Stewart.Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). Thomasshouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.
Oct 06 2004
Stewart Gordon wrote:Ben Hinkle wrote:I haven't actually tried it but yeah that might work as long as there aren't any parameters. I don't know if writef errors when it sees writef("%s") with an error saying not enough parameters or if it prints the string "%s". To be consistent it should error but I don't know what it actually does. -BenThomas Kuehne wrote:What's wrong with writefln(msg); ? Stewart.Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). Thomasshouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.
Oct 06 2004
Stewart Gordon wrote: <snip>Oops, that wasn't what I meant to say. You misunderstand how writef works. Unlike printf, writef doesn't just take its first argument to be a format string. Instead, it takes the first string it encounters to be a format string. It then reads as many arguments as the format string specifies. After it has done this, it reads subsequent argument strings in the same way, which may include another format string. And so either writefln("", msg); or writefln(msg); will cause msg to be interpreted as a format string. OTOH, if you write writefln("%s", msg); then msg is a field of the format string "%s". Hence msg will not be parsed as a format string. Stewart.shouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.What's wrong with writefln(msg);
Oct 06 2004
Stewart Gordon schrieb:
Instead, it takes the first string it encounters to be a format string.
It then reads as many arguments as the format string specifies. After
it has done this, it reads subsequent argument strings in the same way,
which may include another format string.
And so either
writefln("", msg);
or
writefln(msg);
will cause msg to be interpreted as a format string. OTOH, if you write
writefln("%s", msg);
then msg is a field of the format string "%s". Hence msg will not be
parsed as a format string.
I forgot that :O
Thomas
Oct 07 2004
On Wed, 06 Oct 2004 13:08:48 +0100, Stewart Gordon wrote:Ben Hinkle wrote:The first parameter is supposed to be a template or pattern, thus if 'msg' just happens to contain formatting codes, the application may abort. It is safer to do ... writefln("%s", msg); I tested 'writefln("%s")' and I got the error message "Error: std.format". -- Derek Melbourne, AustraliaThomas Kuehne wrote:What's wrong with writefln(msg); ? Stewart.Replaced printf with writef in the release code of phobos. Most unittests still remain to be converted. Note: if you haven't applied the patch from digitalmars.com digitalmars.D.bugs:2025 you'll have to fix some chunks(missing "private" keyword). Thomasshouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.
Oct 06 2004









Ben Hinkle <bhinkle4 juno.com> 