Support %zd in PyErr_Format and PyString_FromFormat.
This commit is contained in:
parent
26efe402c2
commit
2c95cc6d72
|
@ -243,14 +243,14 @@ buffer_repr(PyBufferObject *self)
|
||||||
const char *status = self->b_readonly ? "read-only" : "read-write";
|
const char *status = self->b_readonly ? "read-only" : "read-write";
|
||||||
|
|
||||||
if ( self->b_base == NULL )
|
if ( self->b_base == NULL )
|
||||||
return PyString_FromFormat("<%s buffer ptr %p, size %ld at %p>",
|
return PyString_FromFormat("<%s buffer ptr %p, size %zd at %p>",
|
||||||
status,
|
status,
|
||||||
self->b_ptr,
|
self->b_ptr,
|
||||||
(long)self->b_size,
|
(long)self->b_size,
|
||||||
self);
|
self);
|
||||||
else
|
else
|
||||||
return PyString_FromFormat(
|
return PyString_FromFormat(
|
||||||
"<%s buffer for %p, size %ld, offset %ld at %p>",
|
"<%s buffer for %p, size %zd, offset %zd at %p>",
|
||||||
status,
|
status,
|
||||||
self->b_base,
|
self->b_base,
|
||||||
(long)self->b_size,
|
(long)self->b_size,
|
||||||
|
|
|
@ -1148,7 +1148,7 @@ PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override)
|
||||||
if (n != 2) {
|
if (n != 2) {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"dictionary update sequence element #%d "
|
"dictionary update sequence element #%d "
|
||||||
"has length %ld; 2 is required",
|
"has length %zd; 2 is required",
|
||||||
i, (long)n);
|
i, (long)n);
|
||||||
goto Fail;
|
goto Fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,8 +248,8 @@ func_set_code(PyFunctionObject *op, PyObject *value)
|
||||||
PyTuple_GET_SIZE(op->func_closure));
|
PyTuple_GET_SIZE(op->func_closure));
|
||||||
if (nclosure != nfree) {
|
if (nclosure != nfree) {
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"%s() requires a code object with %ld free vars,"
|
"%s() requires a code object with %zd free vars,"
|
||||||
" not %ld",
|
" not %zd",
|
||||||
PyString_AsString(op->func_name),
|
PyString_AsString(op->func_name),
|
||||||
(long)nclosure, (long)nfree);
|
(long)nclosure, (long)nfree);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -401,7 +401,7 @@ func_new(PyTypeObject* type, PyObject* args, PyObject* kw)
|
||||||
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
|
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
|
||||||
if (nfree != nclosure)
|
if (nfree != nclosure)
|
||||||
return PyErr_Format(PyExc_ValueError,
|
return PyErr_Format(PyExc_ValueError,
|
||||||
"%s requires closure of length %ld, not %ld",
|
"%s requires closure of length %zd, not %zd",
|
||||||
PyString_AS_STRING(code->co_name),
|
PyString_AS_STRING(code->co_name),
|
||||||
(long)nfree, (long)nclosure);
|
(long)nfree, (long)nclosure);
|
||||||
if (nclosure) {
|
if (nclosure) {
|
||||||
|
|
|
@ -2598,9 +2598,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
|
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
|
||||||
/* XXX can we use %zd here? */
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
PyErr_Format(PyExc_ValueError,
|
||||||
"attempt to assign sequence of size %ld to extended slice of size %ld",
|
"attempt to assign sequence of size %zd to extended slice of size %zd",
|
||||||
(long)PySequence_Fast_GET_SIZE(seq),
|
(long)PySequence_Fast_GET_SIZE(seq),
|
||||||
(long)slicelength);
|
(long)slicelength);
|
||||||
Py_DECREF(seq);
|
Py_DECREF(seq);
|
||||||
|
|
|
@ -181,6 +181,9 @@ PyString_FromFormatV(const char *format, va_list vargs)
|
||||||
added */
|
added */
|
||||||
if (*f == 'l' && *(f+1) == 'd')
|
if (*f == 'l' && *(f+1) == 'd')
|
||||||
++f;
|
++f;
|
||||||
|
/* likewise for %zd */
|
||||||
|
if (*f == 'z' && *(f+1) == 'd')
|
||||||
|
++f;
|
||||||
|
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -237,6 +240,7 @@ PyString_FromFormatV(const char *format, va_list vargs)
|
||||||
const char* p = f++;
|
const char* p = f++;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
int longflag = 0;
|
int longflag = 0;
|
||||||
|
int size_tflag = 0;
|
||||||
/* parse the width.precision part (we're only
|
/* parse the width.precision part (we're only
|
||||||
interested in the precision value, if any) */
|
interested in the precision value, if any) */
|
||||||
n = 0;
|
n = 0;
|
||||||
|
@ -256,6 +260,11 @@ PyString_FromFormatV(const char *format, va_list vargs)
|
||||||
longflag = 1;
|
longflag = 1;
|
||||||
++f;
|
++f;
|
||||||
}
|
}
|
||||||
|
/* handle the size_t flag. */
|
||||||
|
if (*f == 'z' && *(f+1) == 'd') {
|
||||||
|
size_tflag = 1;
|
||||||
|
++f;
|
||||||
|
}
|
||||||
|
|
||||||
switch (*f) {
|
switch (*f) {
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -264,6 +273,18 @@ PyString_FromFormatV(const char *format, va_list vargs)
|
||||||
case 'd':
|
case 'd':
|
||||||
if (longflag)
|
if (longflag)
|
||||||
sprintf(s, "%ld", va_arg(vargs, long));
|
sprintf(s, "%ld", va_arg(vargs, long));
|
||||||
|
else if (size_tflag) {
|
||||||
|
/* Instead of checking whether the C
|
||||||
|
library supports %zd, handle the
|
||||||
|
common cases. */
|
||||||
|
#if SIZEOF_SIZE_T == SIZEOF_LONG
|
||||||
|
sprintf(s, "%ld", va_arg(vargs, long));
|
||||||
|
#elif defined(MS_WINDOWS)
|
||||||
|
sprintf(s, "%Id", va_arg(vargs, size_t));
|
||||||
|
#else
|
||||||
|
#error Cannot print size_t values
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else
|
else
|
||||||
sprintf(s, "%d", va_arg(vargs, int));
|
sprintf(s, "%d", va_arg(vargs, int));
|
||||||
s += strlen(s);
|
s += strlen(s);
|
||||||
|
|
|
@ -125,7 +125,7 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
if (min_len != max_len) {
|
if (min_len != max_len) {
|
||||||
if (len < min_len) {
|
if (len < min_len) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.500s() takes an at least %ld-sequence (%ld-sequence given)",
|
"%.500s() takes an at least %zd-sequence (%zd-sequence given)",
|
||||||
type->tp_name, (long)min_len, (long)len);
|
type->tp_name, (long)min_len, (long)len);
|
||||||
Py_DECREF(arg);
|
Py_DECREF(arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -133,7 +133,7 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
|
|
||||||
if (len > max_len) {
|
if (len > max_len) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.500s() takes an at most %ld-sequence (%ld-sequence given)",
|
"%.500s() takes an at most %zd-sequence (%zd-sequence given)",
|
||||||
type->tp_name, (long)max_len, (long)len);
|
type->tp_name, (long)max_len, (long)len);
|
||||||
Py_DECREF(arg);
|
Py_DECREF(arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -142,7 +142,7 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
else {
|
else {
|
||||||
if (len != min_len) {
|
if (len != min_len) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%.500s() takes a %ld-sequence (%ld-sequence given)",
|
"%.500s() takes a %zd-sequence (%zd-sequence given)",
|
||||||
type->tp_name, (long)min_len, (long)len);
|
type->tp_name, (long)min_len, (long)len);
|
||||||
Py_DECREF(arg);
|
Py_DECREF(arg);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -3372,10 +3372,9 @@ check_num_args(PyObject *ob, int n)
|
||||||
}
|
}
|
||||||
if (n == PyTuple_GET_SIZE(ob))
|
if (n == PyTuple_GET_SIZE(ob))
|
||||||
return 1;
|
return 1;
|
||||||
/* XXX %zd? */
|
|
||||||
PyErr_Format(
|
PyErr_Format(
|
||||||
PyExc_TypeError,
|
PyExc_TypeError,
|
||||||
"expected %d arguments, got %d", n, (int)PyTuple_GET_SIZE(ob));
|
"expected %d arguments, got %zd", n, PyTuple_GET_SIZE(ob));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -791,8 +791,7 @@ int unicode_decode_call_errorhandler(const char *errors, PyObject **errorHandler
|
||||||
if (newpos<0)
|
if (newpos<0)
|
||||||
newpos = insize+newpos;
|
newpos = insize+newpos;
|
||||||
if (newpos<0 || newpos>insize) {
|
if (newpos<0 || newpos>insize) {
|
||||||
/* XXX %zd? */
|
PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", newpos);
|
||||||
PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)newpos);
|
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2473,8 +2472,7 @@ static PyObject *unicode_encode_call_errorhandler(const char *errors,
|
||||||
if (*newpos<0)
|
if (*newpos<0)
|
||||||
*newpos = size+*newpos;
|
*newpos = size+*newpos;
|
||||||
if (*newpos<0 || *newpos>size) {
|
if (*newpos<0 || *newpos>size) {
|
||||||
/* XXX %zd? */
|
PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", *newpos);
|
||||||
PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
|
|
||||||
Py_DECREF(restuple);
|
Py_DECREF(restuple);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3373,8 +3371,7 @@ static PyObject *unicode_translate_call_errorhandler(const char *errors,
|
||||||
else
|
else
|
||||||
*newpos = i_newpos;
|
*newpos = i_newpos;
|
||||||
if (*newpos<0 || *newpos>size) {
|
if (*newpos<0 || *newpos>size) {
|
||||||
/* XXX %zd? */
|
PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", *newpos);
|
||||||
PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
|
|
||||||
Py_DECREF(restuple);
|
Py_DECREF(restuple);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue