www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Patch] phobos: replaced printf with writef

reply "Thomas Kuehne" <eisvogel users.sourceforge.net> writes:
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
Oct 06 2004
parent reply Ben Hinkle <bhinkle4 juno.com> writes:
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).
 
 Thomas

shouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.
Oct 06 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ben Hinkle wrote:

 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).
 
 Thomas

shouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.

What's wrong with writefln(msg); ? Stewart.
Oct 06 2004
next sibling parent Ben Hinkle <bhinkle4 juno.com> writes:
Stewart Gordon wrote:

 Ben Hinkle wrote:
 
 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).
 
 Thomas

shouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.

What's wrong with writefln(msg); ? Stewart.

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. -Ben
Oct 06 2004
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Stewart Gordon wrote:

<snip>
 shouldn't
  writef(msg,"\n");
 be
  writefln("",msg);
 otherwise the msg gets parsed as a format string.

What's wrong with writefln(msg);

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.
Oct 06 2004
parent "Thomas Kuehne" <eisvogel users.sourceforge.net> writes:
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
prev sibling parent Derek <derek psyc.ward> writes:
On Wed, 06 Oct 2004 13:08:48 +0100, Stewart Gordon wrote:

 Ben Hinkle wrote:
 
 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).
 
 Thomas

shouldn't writef(msg,"\n"); be writefln("",msg); otherwise the msg gets parsed as a format string.

What's wrong with writefln(msg); ? Stewart.

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, Australia
Oct 06 2004