Skip to content

Commit 7780226

Browse files
author
amaury.forgeotdarc
committed
#3743: PY_FORMAT_SIZE_T is designed for the OS "printf" functions, not for
PyString_FromFormat which has an independent implementation, and uses "%zd". This makes a difference on win64, where printf needs "%Id" to display 64bit values. For example, queue.__repr__ was incorrect. Reviewed by Martin von Loewis. git-svn-id: http://svn.python.org/projects/python/trunk@66377 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent fd4e602 commit 7780226

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ What's New in Python 2.6 release candidate 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #3743: In a few places, PY_FORMAT_SIZE_T was incorrectly used with
16+
PyString_FromFormat or PyErr_Format to display size_t values. The macro
17+
PY_FORMAT_SIZE_T is designed to select the correct format for the OS
18+
``printf`` function, whereas PyString_FromFormat has an independent
19+
implementation and uses "%zd" on all platforms for size_t values.
20+
This makes a difference on win64, where ``printf`` needs "%Id" to display
21+
64bit values.
22+
1523
- Issue #3634: _weakref.ref(Exception).__init__() gave invalid return value on
1624
error.
1725

Modules/_collectionsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ deque_repr(PyObject *deque)
670670
return NULL;
671671
}
672672
if (((dequeobject *)deque)->maxlen != -1)
673-
fmt = PyString_FromFormat("deque(%%r, maxlen=%" PY_FORMAT_SIZE_T "d)",
673+
fmt = PyString_FromFormat("deque(%%r, maxlen=%zd)",
674674
((dequeobject *)deque)->maxlen);
675675
else
676676
fmt = PyString_FromString("deque(%r)");

Modules/_multiprocessing/connection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ connection_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
4747
return NULL;
4848

4949
if (handle == INVALID_HANDLE_VALUE || (Py_ssize_t)handle < 0) {
50-
PyErr_Format(PyExc_IOError, "invalid handle %"
51-
PY_FORMAT_SIZE_T "d", (Py_ssize_t)handle);
50+
PyErr_Format(PyExc_IOError, "invalid handle %zd",
51+
(Py_ssize_t)handle);
5252
return NULL;
5353
}
5454

@@ -396,7 +396,7 @@ connection_repr(ConnectionObject *self)
396396
static char *conn_type[] = {"read-only", "write-only", "read-write"};
397397

398398
assert(self->flags >= 1 && self->flags <= 3);
399-
return FROM_FORMAT("<%s %s, handle %" PY_FORMAT_SIZE_T "d>",
399+
return FROM_FORMAT("<%s %s, handle %zd>",
400400
conn_type[self->flags - 1],
401401
CONNECTION_NAME, (Py_ssize_t)self->handle);
402402
}

Modules/_multiprocessing/multiprocessing.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
# define PY_SSIZE_T_MAX INT_MAX
5757
# define PY_SSIZE_T_MIN INT_MIN
5858
# define F_PY_SSIZE_T "i"
59-
# define PY_FORMAT_SIZE_T ""
6059
# define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
6160
#else
6261
# define F_PY_SSIZE_T "n"

Python/Python-ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
387387
if (PyTuple_GET_SIZE(args) > 0) {
388388
if (numfields != PyTuple_GET_SIZE(args)) {
389389
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
390-
"%" PY_FORMAT_SIZE_T "d positional argument%s",
390+
"%zd positional argument%s",
391391
Py_TYPE(self)->tp_name,
392392
numfields == 0 ? "" : "either 0 or ",
393393
numfields, numfields == 1 ? "" : "s");

0 commit comments

Comments
 (0)