Commit ab9ca875 authored by scoder's avatar scoder

Merge pull request #147 from cgohlke/patch-1

Fix "PyErr_Format + PY_FORMAT_SSIZE_T likely broken in Win64"
parents dfdfe69a 0a5cec7c
...@@ -3547,7 +3547,7 @@ class SliceIndexNode(ExprNode): ...@@ -3547,7 +3547,7 @@ class SliceIndexNode(ExprNode):
check = stop check = stop
if check: if check:
code.putln("if (unlikely((%s) != %d)) {" % (check, target_size)) code.putln("if (unlikely((%s) != %d)) {" % (check, target_size))
code.putln('PyErr_Format(PyExc_ValueError, "Assignment to slice of wrong length, expected %%" PY_FORMAT_SIZE_T "d, got %%" PY_FORMAT_SIZE_T "d", (Py_ssize_t)%d, (Py_ssize_t)(%s));' % ( code.putln('PyErr_Format(PyExc_ValueError, "Assignment to slice of wrong length, expected %%" CYTHON_FORMAT_SSIZE_T "d, got %%" CYTHON_FORMAT_SSIZE_T "d", (Py_ssize_t)%d, (Py_ssize_t)(%s));' % (
target_size, check)) target_size, check))
code.putln(code.error_goto(self.pos)) code.putln(code.error_goto(self.pos))
code.putln("}") code.putln("}")
......
...@@ -1596,7 +1596,7 @@ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject* x) { ...@@ -1596,7 +1596,7 @@ static CYTHON_INLINE Py_UCS4 __Pyx_PyObject_AsPy_UCS4(PyObject* x) {
#endif #endif
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"only single character unicode strings can be converted to Py_UCS4, " "only single character unicode strings can be converted to Py_UCS4, "
"got length %" PY_FORMAT_SIZE_T "d", length); "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
return (Py_UCS4)-1; return (Py_UCS4)-1;
} }
ival = __Pyx_PyInt_AsLong(x); ival = __Pyx_PyInt_AsLong(x);
...@@ -1651,7 +1651,7 @@ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) { ...@@ -1651,7 +1651,7 @@ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) {
if (unlikely(__Pyx_PyUnicode_GET_LENGTH(x) != 1)) { if (unlikely(__Pyx_PyUnicode_GET_LENGTH(x) != 1)) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"only single character unicode strings can be converted to Py_UNICODE, " "only single character unicode strings can be converted to Py_UNICODE, "
"got length %" PY_FORMAT_SIZE_T "d", __Pyx_PyUnicode_GET_LENGTH(x)); "got length %" CYTHON_FORMAT_SSIZE_T "d", __Pyx_PyUnicode_GET_LENGTH(x));
return (Py_UNICODE)-1; return (Py_UNICODE)-1;
} }
#if CYTHON_PEP393_ENABLED #if CYTHON_PEP393_ENABLED
......
...@@ -544,7 +544,7 @@ static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) { ...@@ -544,7 +544,7 @@ static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
offset = ctx->head->parent_offset + field->offset; offset = ctx->head->parent_offset + field->offset;
if (ctx->fmt_offset != offset) { if (ctx->fmt_offset != offset) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Buffer dtype mismatch; next field is at offset %" PY_FORMAT_SIZE_T "d but %" PY_FORMAT_SIZE_T "d expected", "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
(Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset); (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
return -1; return -1;
} }
...@@ -809,7 +809,7 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate( ...@@ -809,7 +809,7 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
} }
if ((unsigned)buf->itemsize != dtype->size) { if ((unsigned)buf->itemsize != dtype->size) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Item size of buffer (%" PY_FORMAT_SIZE_T "d byte%s) does not match size of '%s' (%" PY_FORMAT_SIZE_T "d byte%s)", "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
buf->itemsize, (buf->itemsize > 1) ? "s" : "", buf->itemsize, (buf->itemsize > 1) ? "s" : "",
dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : ""); dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
goto fail; goto fail;
......
//////////////////// ArgTypeTest.proto //////////////////// //////////////////// ArgTypeTest.proto ////////////////////
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
...@@ -58,7 +57,7 @@ static void __Pyx_RaiseArgtupleInvalid( ...@@ -58,7 +57,7 @@ static void __Pyx_RaiseArgtupleInvalid(
more_or_less = "exactly"; more_or_less = "exactly";
} }
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"%s() takes %s %" PY_FORMAT_SIZE_T "d positional argument%s (%" PY_FORMAT_SIZE_T "d given)", "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
func_name, more_or_less, num_expected, func_name, more_or_less, num_expected,
(num_expected == 1) ? "" : "s", num_found); (num_expected == 1) ? "" : "s", num_found);
} }
......
...@@ -197,8 +197,8 @@ static int __Pyx_ValidateAndInit_memviewslice( ...@@ -197,8 +197,8 @@ static int __Pyx_ValidateAndInit_memviewslice(
if ((unsigned)buf->itemsize != dtype->size) { if ((unsigned)buf->itemsize != dtype->size) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"Item size of buffer (%" PY_FORMAT_SIZE_T "u byte%s) " "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "u byte%s) "
"does not match size of '%s' (%" PY_FORMAT_SIZE_T "u byte%s)", "does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "u byte%s)",
buf->itemsize, buf->itemsize,
(buf->itemsize > 1) ? "s" : "", (buf->itemsize > 1) ? "s" : "",
dtype->name, dtype->name,
......
...@@ -244,6 +244,12 @@ ...@@ -244,6 +244,12 @@
#define __Pyx_DOCSTR(n) (n) #define __Pyx_DOCSTR(n) (n)
#endif #endif
#if defined(_WIN64) && defined(_MSC_VER)
#define CYTHON_FORMAT_SSIZE_T "z"
#else
#define CYTHON_FORMAT_SSIZE_T PY_FORMAT_SIZE_T
#endif
/////////////// ForceInitThreads.proto /////////////// /////////////// ForceInitThreads.proto ///////////////
#ifndef __PYX_FORCE_INIT_THREADS #ifndef __PYX_FORCE_INIT_THREADS
......
...@@ -16,7 +16,7 @@ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected); ...@@ -16,7 +16,7 @@ static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"too many values to unpack (expected %" PY_FORMAT_SIZE_T "d)", expected); "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
} }
/////////////// RaiseNeedMoreValuesToUnpack.proto /////////////// /////////////// RaiseNeedMoreValuesToUnpack.proto ///////////////
...@@ -27,7 +27,7 @@ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index); ...@@ -27,7 +27,7 @@ static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) { static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"need more than %" PY_FORMAT_SIZE_T "d value%s to unpack", "need more than %" CYTHON_FORMAT_SSIZE_T "d value%s to unpack",
index, (index == 1) ? "" : "s"); index, (index == 1) ? "" : "s");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment