Commit a3a3a030 authored by Tim Peters's avatar Tim Peters

Fox for SF bug #123859: %[duxXo] long formats inconsistent.

parent 469d5bb0
......@@ -63,11 +63,6 @@ testboth("%o", 100000000000L, "1351035564000")
testboth("%d", 10L, "10")
testboth("%d", 100000000000L, "100000000000")
# Make sure big is too big to fit in a 64-bit int, else the unbounded
# int formatting will be sidestepped on some machines. That's vital,
# because bitwise (x, X, o) formats of regular Python ints never
# produce a sign ("+" or "-").
big = 123456789012345678901234567890L
testboth("%d", big, "123456789012345678901234567890")
testboth("%d", -big, "-123456789012345678901234567890")
......@@ -163,3 +158,19 @@ testboth("%#.32o", big, "012345670123456701234567012345670")
testboth("%034.33o", big, "0012345670123456701234567012345670")
# base marker shouldn't change that
testboth("%0#34.33o", big, "0012345670123456701234567012345670")
# Some small ints, in both Python int and long flavors).
testboth("%d", 42, "42")
testboth("%d", -42, "-42")
testboth("%d", 42L, "42")
testboth("%d", -42L, "-42")
testboth("%x", 0x42, "42")
# testboth("%x", -0x42, "ffffffbe") # Alas, that's specific to 32-bit machines
testboth("%x", 0x42L, "42")
testboth("%x", -0x42L, "-42")
testboth("%o", 042, "42")
# testboth("%o", -042, "37777777736") # Alas, that's specific to 32-bit machines
testboth("%o", 042L, "42")
testboth("%o", -042L, "-42")
What's New in Python 2.1 alpha 1?
=================================
Core language, builtins, and interpreter
- %[duxXo] formats of negative Python longs now produce a sign
character. In 1.6 and earlier, they never produced a sign,
and raised an error if the value of the long was too large
to fit in a Python int. In 2.0, they produced a sign if and
only if too large to fit in an int. This was inconsistent
across platforms (because the size of an int varies across
platforms), and inconsistent with hex() and oct(). Example:
>>> "%x" % -0x42L
'-42' # in 2.1
'ffffffbe' # in 2.0 and before, on 32-bit machines
>>> hex(-0x42L)
'-0x42L' # in all versions of Python
What's New in Python 2.0?
=========================
......
......@@ -2897,10 +2897,7 @@ PyString_Format(PyObject *format, PyObject *args)
case 'X':
if (c == 'i')
c = 'd';
if (PyLong_Check(v) && PyLong_AsLong(v) == -1
&& PyErr_Occurred()) {
/* Too big for a C long. */
PyErr_Clear();
if (PyLong_Check(v)) {
temp = _PyString_FormatLong(v, flags,
prec, c, &pbuf, &len);
if (!temp)
......
......@@ -5020,9 +5020,7 @@ PyObject *PyUnicode_Format(PyObject *format,
case 'X':
if (c == 'i')
c = 'd';
if (PyLong_Check(v) && PyLong_AsLong(v) == -1
&& PyErr_Occurred()) {
PyErr_Clear();
if (PyLong_Check(v)) {
temp = formatlong(v, flags, prec, c);
if (!temp)
goto onError;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment