diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-08-25 03:02:28 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-08-25 03:02:28 (GMT) |
commit | 6af5bbb5653a9b77102369d60fb18d3bc896bf92 (patch) | |
tree | 6acf77178ee58c9e5e115a5363287dea94edf115 /Objects/stringobject.c | |
parent | ea46fa84946752513888996f0aabe1263a73164f (diff) | |
download | cpython-6af5bbb5653a9b77102369d60fb18d3bc896bf92.zip cpython-6af5bbb5653a9b77102369d60fb18d3bc896bf92.tar.gz cpython-6af5bbb5653a9b77102369d60fb18d3bc896bf92.tar.bz2 |
PyString_FromFormatV: Massage platform %p output to match what gcc does,
at least in the first two characters. %p is ill-defined, and people will
forever commit bad tests otherwise ("bad" in the sense that they fall
over (at least on Windows) for lack of a leading '0x'; 5 of the 7 tests
in test_repr.py failed on Windows for that reason this time around).
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 3acc69f..9ea32a2 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -269,6 +269,14 @@ PyString_FromFormatV(const char *format, va_list vargs) break; case 'p': sprintf(s, "%p", va_arg(vargs, void*)); + /* %p is ill-defined: ensure leading 0x. */ + if (s[1] == 'X') + s[1] = 'x'; + else if (s[1] != 'x') { + memmove(s+2, s, strlen(s)+1); + s[0] = '0'; + s[1] = 'x'; + } s += strlen(s); break; case '%': |