mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fox for SF bug #123859: %[duxXo] long formats inconsistent.
This commit is contained in:
parent
469d5bb0b4
commit
a3a3a030af
4 changed files with 50 additions and 24 deletions
|
@ -63,11 +63,6 @@ testboth("%o", 100000000000L, "1351035564000")
|
||||||
testboth("%d", 10L, "10")
|
testboth("%d", 10L, "10")
|
||||||
testboth("%d", 100000000000L, "100000000000")
|
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
|
big = 123456789012345678901234567890L
|
||||||
testboth("%d", big, "123456789012345678901234567890")
|
testboth("%d", big, "123456789012345678901234567890")
|
||||||
testboth("%d", -big, "-123456789012345678901234567890")
|
testboth("%d", -big, "-123456789012345678901234567890")
|
||||||
|
@ -163,3 +158,19 @@ testboth("%#.32o", big, "012345670123456701234567012345670")
|
||||||
testboth("%034.33o", big, "0012345670123456701234567012345670")
|
testboth("%034.33o", big, "0012345670123456701234567012345670")
|
||||||
# base marker shouldn't change that
|
# base marker shouldn't change that
|
||||||
testboth("%0#34.33o", big, "0012345670123456701234567012345670")
|
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")
|
||||||
|
|
44
Misc/NEWS
44
Misc/NEWS
|
@ -1,3 +1,23 @@
|
||||||
|
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?
|
What's New in Python 2.0?
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
|
@ -79,7 +99,7 @@ Build issues
|
||||||
--with-pydebug flag. The expected warning is for getopt() in
|
--with-pydebug flag. The expected warning is for getopt() in
|
||||||
Modules/main.c. This warning will be fixed for Python 2.1.
|
Modules/main.c. This warning will be fixed for Python 2.1.
|
||||||
|
|
||||||
- Fixed configure to add -threads argument during linking on OSF1.
|
- Fixed configure to add -threads argument during linking on OSF1.
|
||||||
|
|
||||||
Tools and other miscellany
|
Tools and other miscellany
|
||||||
|
|
||||||
|
@ -88,7 +108,7 @@ Tools and other miscellany
|
||||||
comprehensions, and augmented assignments. The new compiler should
|
comprehensions, and augmented assignments. The new compiler should
|
||||||
also be backwards compatible with Python 1.5.2; the compiler will
|
also be backwards compatible with Python 1.5.2; the compiler will
|
||||||
always generate code for the version of the interpreter it runs
|
always generate code for the version of the interpreter it runs
|
||||||
under.
|
under.
|
||||||
|
|
||||||
What's new in 2.0 release candidate 1 (since beta 2)?
|
What's new in 2.0 release candidate 1 (since beta 2)?
|
||||||
=====================================================
|
=====================================================
|
||||||
|
@ -143,15 +163,15 @@ Standard library
|
||||||
the file-like object interface and with StringIO. If operations are
|
the file-like object interface and with StringIO. If operations are
|
||||||
performed on a closed object, an exception is raised. The truncate
|
performed on a closed object, an exception is raised. The truncate
|
||||||
method now accepts a position argument and readline accepts a size
|
method now accepts a position argument and readline accepts a size
|
||||||
argument.
|
argument.
|
||||||
|
|
||||||
- There were many changes made to the linuxaudiodev module and its
|
- There were many changes made to the linuxaudiodev module and its
|
||||||
test suite; as a result, a short, unexpected audio sample should now
|
test suite; as a result, a short, unexpected audio sample should now
|
||||||
play when the regression test is run.
|
play when the regression test is run.
|
||||||
|
|
||||||
Note that this module is named poorly, because it should work
|
Note that this module is named poorly, because it should work
|
||||||
correctly on any platform that supports the Open Sound System
|
correctly on any platform that supports the Open Sound System
|
||||||
(OSS).
|
(OSS).
|
||||||
|
|
||||||
The module now raises exceptions when errors occur instead of
|
The module now raises exceptions when errors occur instead of
|
||||||
crashing. It also defines the AFMT_A_LAW format (logarithmic A-law
|
crashing. It also defines the AFMT_A_LAW format (logarithmic A-law
|
||||||
|
@ -200,7 +220,7 @@ Build issues
|
||||||
|
|
||||||
- configure now accepts a --with-suffix option that specifies the
|
- configure now accepts a --with-suffix option that specifies the
|
||||||
executable suffix. This is useful for builds on Cygwin and Mac OS
|
executable suffix. This is useful for builds on Cygwin and Mac OS
|
||||||
X, for example.
|
X, for example.
|
||||||
|
|
||||||
- The mmap.PAGESIZE constant is now initialized using sysconf when
|
- The mmap.PAGESIZE constant is now initialized using sysconf when
|
||||||
possible, which eliminates a dependency on -lucb for Reliant UNIX.
|
possible, which eliminates a dependency on -lucb for Reliant UNIX.
|
||||||
|
@ -211,7 +231,7 @@ Build issues
|
||||||
POLLRDNORM and related constants.
|
POLLRDNORM and related constants.
|
||||||
|
|
||||||
- Darwin (Mac OS X): Initial support for static builds on this
|
- Darwin (Mac OS X): Initial support for static builds on this
|
||||||
platform.
|
platform.
|
||||||
|
|
||||||
- BeOS: A number of changes were made to the build and installation
|
- BeOS: A number of changes were made to the build and installation
|
||||||
process. ar-fake now operates on a directory of object files.
|
process. ar-fake now operates on a directory of object files.
|
||||||
|
@ -254,7 +274,7 @@ Core language, builtins, and interpreter
|
||||||
string is too long."
|
string is too long."
|
||||||
|
|
||||||
- Better error message when continue is found in try statement in a
|
- Better error message when continue is found in try statement in a
|
||||||
loop.
|
loop.
|
||||||
|
|
||||||
|
|
||||||
Standard library and extensions
|
Standard library and extensions
|
||||||
|
@ -345,7 +365,7 @@ Standard library and extensions
|
||||||
use buffer interface on Unicode strings. Does not hang if group id
|
use buffer interface on Unicode strings. Does not hang if group id
|
||||||
is followed by whitespace.
|
is followed by whitespace.
|
||||||
|
|
||||||
- StringIO: Size hint in readlines() is now supported as documented.
|
- StringIO: Size hint in readlines() is now supported as documented.
|
||||||
|
|
||||||
- struct: Check ranges for bytes and shorts.
|
- struct: Check ranges for bytes and shorts.
|
||||||
|
|
||||||
|
@ -419,7 +439,7 @@ C API
|
||||||
PyArg_ParseTupleAndKeywords() now accepts "es#" and "es".
|
PyArg_ParseTupleAndKeywords() now accepts "es#" and "es".
|
||||||
PyArg_Parse() special cases "s#" for Unicode objects; it returns a
|
PyArg_Parse() special cases "s#" for Unicode objects; it returns a
|
||||||
pointer to the default encoded string data instead of to the raw
|
pointer to the default encoded string data instead of to the raw
|
||||||
UTF-16.
|
UTF-16.
|
||||||
|
|
||||||
- Py_BuildValue accepts B format (for bgen-generated code).
|
- Py_BuildValue accepts B format (for bgen-generated code).
|
||||||
|
|
||||||
|
@ -448,7 +468,7 @@ Internals
|
||||||
registry key.
|
registry key.
|
||||||
|
|
||||||
- On Unix, create .pyc/.pyo files with O_EXCL flag to avoid a race
|
- On Unix, create .pyc/.pyo files with O_EXCL flag to avoid a race
|
||||||
condition.
|
condition.
|
||||||
|
|
||||||
|
|
||||||
Build and platform-specific issues
|
Build and platform-specific issues
|
||||||
|
@ -475,7 +495,7 @@ Tools and other miscellany
|
||||||
|
|
||||||
- freeze: The modulefinder now works with 2.0 opcodes.
|
- freeze: The modulefinder now works with 2.0 opcodes.
|
||||||
|
|
||||||
- IDLE:
|
- IDLE:
|
||||||
Move hackery of sys.argv until after the Tk instance has been
|
Move hackery of sys.argv until after the Tk instance has been
|
||||||
created, which allows the application-specific Tkinter
|
created, which allows the application-specific Tkinter
|
||||||
initialization to be executed if present; also pass an explicit
|
initialization to be executed if present; also pass an explicit
|
||||||
|
|
|
@ -2897,10 +2897,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
case 'X':
|
case 'X':
|
||||||
if (c == 'i')
|
if (c == 'i')
|
||||||
c = 'd';
|
c = 'd';
|
||||||
if (PyLong_Check(v) && PyLong_AsLong(v) == -1
|
if (PyLong_Check(v)) {
|
||||||
&& PyErr_Occurred()) {
|
|
||||||
/* Too big for a C long. */
|
|
||||||
PyErr_Clear();
|
|
||||||
temp = _PyString_FormatLong(v, flags,
|
temp = _PyString_FormatLong(v, flags,
|
||||||
prec, c, &pbuf, &len);
|
prec, c, &pbuf, &len);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
|
|
|
@ -5020,9 +5020,7 @@ PyObject *PyUnicode_Format(PyObject *format,
|
||||||
case 'X':
|
case 'X':
|
||||||
if (c == 'i')
|
if (c == 'i')
|
||||||
c = 'd';
|
c = 'd';
|
||||||
if (PyLong_Check(v) && PyLong_AsLong(v) == -1
|
if (PyLong_Check(v)) {
|
||||||
&& PyErr_Occurred()) {
|
|
||||||
PyErr_Clear();
|
|
||||||
temp = formatlong(v, flags, prec, c);
|
temp = formatlong(v, flags, prec, c);
|
||||||
if (!temp)
|
if (!temp)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue