const char *status = self->b_readonly ? "read-only" : "read-write";
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,
self->b_ptr,
(long)self->b_size,
self);
else
return PyString_FromFormat(
- "<%s buffer for %p, size %ld, offset %ld at %p>",
+ "<%s buffer for %p, size %zd, offset %zd at %p>",
status,
self->b_base,
(long)self->b_size,
if (n != 2) {
PyErr_Format(PyExc_ValueError,
"dictionary update sequence element #%d "
- "has length %ld; 2 is required",
+ "has length %zd; 2 is required",
i, (long)n);
goto Fail;
}
PyTuple_GET_SIZE(op->func_closure));
if (nclosure != nfree) {
PyErr_Format(PyExc_ValueError,
- "%s() requires a code object with %ld free vars,"
- " not %ld",
+ "%s() requires a code object with %zd free vars,"
+ " not %zd",
PyString_AsString(op->func_name),
(long)nclosure, (long)nfree);
return -1;
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
if (nfree != nclosure)
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),
(long)nfree, (long)nclosure);
if (nclosure) {
}
if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
- /* XXX can we use %zd here? */
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)slicelength);
Py_DECREF(seq);
added */
if (*f == 'l' && *(f+1) == 'd')
++f;
+ /* likewise for %zd */
+ if (*f == 'z' && *(f+1) == 'd')
+ ++f;
switch (*f) {
case 'c':
const char* p = f++;
Py_ssize_t i;
int longflag = 0;
+ int size_tflag = 0;
/* parse the width.precision part (we're only
interested in the precision value, if any) */
n = 0;
longflag = 1;
++f;
}
+ /* handle the size_t flag. */
+ if (*f == 'z' && *(f+1) == 'd') {
+ size_tflag = 1;
+ ++f;
+ }
switch (*f) {
case 'c':
case 'd':
if (longflag)
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
sprintf(s, "%d", va_arg(vargs, int));
s += strlen(s);
if (min_len != max_len) {
if (len < min_len) {
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);
Py_DECREF(arg);
return NULL;
if (len > max_len) {
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);
Py_DECREF(arg);
return NULL;
else {
if (len != min_len) {
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);
Py_DECREF(arg);
return NULL;
}
if (n == PyTuple_GET_SIZE(ob))
return 1;
- /* XXX %zd? */
PyErr_Format(
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;
}
if (newpos<0)
newpos = insize+newpos;
if (newpos<0 || newpos>insize) {
- /* XXX %zd? */
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)newpos);
+ PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", newpos);
goto onError;
}
if (*newpos<0)
*newpos = size+*newpos;
if (*newpos<0 || *newpos>size) {
- /* XXX %zd? */
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
+ PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", *newpos);
Py_DECREF(restuple);
return NULL;
}
else
*newpos = i_newpos;
if (*newpos<0 || *newpos>size) {
- /* XXX %zd? */
- PyErr_Format(PyExc_IndexError, "position %d from error handler out of bounds", (int)*newpos);
+ PyErr_Format(PyExc_IndexError, "position %zd from error handler out of bounds", *newpos);
Py_DECREF(restuple);
return NULL;
}