#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.
This commit is contained in:
parent
4dd3a50ca4
commit
05e344954d
|
@ -12,6 +12,14 @@ What's New in Python 2.6 release candidate 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #3743: In a few places, PY_FORMAT_SIZE_T was incorrectly used with
|
||||||
|
PyString_FromFormat or PyErr_Format to display size_t values. The macro
|
||||||
|
PY_FORMAT_SIZE_T is designed to select the correct format for the OS
|
||||||
|
``printf`` function, whereas PyString_FromFormat has an independent
|
||||||
|
implementation and uses "%zd" on all platforms for size_t values.
|
||||||
|
This makes a difference on win64, where ``printf`` needs "%Id" to display
|
||||||
|
64bit values.
|
||||||
|
|
||||||
- Issue #3634: _weakref.ref(Exception).__init__() gave invalid return value on
|
- Issue #3634: _weakref.ref(Exception).__init__() gave invalid return value on
|
||||||
error.
|
error.
|
||||||
|
|
||||||
|
|
|
@ -670,7 +670,7 @@ deque_repr(PyObject *deque)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (((dequeobject *)deque)->maxlen != -1)
|
if (((dequeobject *)deque)->maxlen != -1)
|
||||||
fmt = PyString_FromFormat("deque(%%r, maxlen=%" PY_FORMAT_SIZE_T "d)",
|
fmt = PyString_FromFormat("deque(%%r, maxlen=%zd)",
|
||||||
((dequeobject *)deque)->maxlen);
|
((dequeobject *)deque)->maxlen);
|
||||||
else
|
else
|
||||||
fmt = PyString_FromString("deque(%r)");
|
fmt = PyString_FromString("deque(%r)");
|
||||||
|
|
|
@ -47,8 +47,8 @@ connection_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (handle == INVALID_HANDLE_VALUE || (Py_ssize_t)handle < 0) {
|
if (handle == INVALID_HANDLE_VALUE || (Py_ssize_t)handle < 0) {
|
||||||
PyErr_Format(PyExc_IOError, "invalid handle %"
|
PyErr_Format(PyExc_IOError, "invalid handle %zd",
|
||||||
PY_FORMAT_SIZE_T "d", (Py_ssize_t)handle);
|
(Py_ssize_t)handle);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ connection_repr(ConnectionObject *self)
|
||||||
static char *conn_type[] = {"read-only", "write-only", "read-write"};
|
static char *conn_type[] = {"read-only", "write-only", "read-write"};
|
||||||
|
|
||||||
assert(self->flags >= 1 && self->flags <= 3);
|
assert(self->flags >= 1 && self->flags <= 3);
|
||||||
return FROM_FORMAT("<%s %s, handle %" PY_FORMAT_SIZE_T "d>",
|
return FROM_FORMAT("<%s %s, handle %zd>",
|
||||||
conn_type[self->flags - 1],
|
conn_type[self->flags - 1],
|
||||||
CONNECTION_NAME, (Py_ssize_t)self->handle);
|
CONNECTION_NAME, (Py_ssize_t)self->handle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@
|
||||||
# define PY_SSIZE_T_MAX INT_MAX
|
# define PY_SSIZE_T_MAX INT_MAX
|
||||||
# define PY_SSIZE_T_MIN INT_MIN
|
# define PY_SSIZE_T_MIN INT_MIN
|
||||||
# define F_PY_SSIZE_T "i"
|
# define F_PY_SSIZE_T "i"
|
||||||
# define PY_FORMAT_SIZE_T ""
|
|
||||||
# define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
|
# define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
|
||||||
#else
|
#else
|
||||||
# define F_PY_SSIZE_T "n"
|
# define F_PY_SSIZE_T "n"
|
||||||
|
|
|
@ -387,7 +387,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
|
||||||
if (PyTuple_GET_SIZE(args) > 0) {
|
if (PyTuple_GET_SIZE(args) > 0) {
|
||||||
if (numfields != PyTuple_GET_SIZE(args)) {
|
if (numfields != PyTuple_GET_SIZE(args)) {
|
||||||
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
|
PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s"
|
||||||
"%" PY_FORMAT_SIZE_T "d positional argument%s",
|
"%zd positional argument%s",
|
||||||
Py_TYPE(self)->tp_name,
|
Py_TYPE(self)->tp_name,
|
||||||
numfields == 0 ? "" : "either 0 or ",
|
numfields == 0 ? "" : "either 0 or ",
|
||||||
numfields, numfields == 1 ? "" : "s");
|
numfields, numfields == 1 ? "" : "s");
|
||||||
|
|
Loading…
Reference in New Issue