From c8ce29c23903b5145ed0e1a23804e7e99faa5eb8 Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Mon, 15 Oct 2012 15:03:09 -0500 Subject: [PATCH] FIX: Handle long values in _imaging getink This gets the putdata test case to run correctly under 2.6/2.7. It fixes an issue where the value 0xFFFFFFFF (which is long in old Python) isn't recognized and putdata tries to parse it as a tuple. The original fix comes from Christoph Gohlke. It was adapted to work in both 2.* and 3.*. --- _imaging.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/_imaging.c b/_imaging.c index 6276bc67884..59b045abfae 100644 --- a/_imaging.c +++ b/_imaging.c @@ -510,8 +510,17 @@ getink(PyObject* color, Imaging im, char* ink) ink[1] = ink[2] = ink[3] = 0; } else { a = 255; - if (PyInt_Check(color)) { - r = PyInt_AS_LONG(color); +#if PY_VERSION_HEX >= 0x03000000 + if (PyLong_Check(color)) { + r = (int) PyLong_AsLong(color); +#else + if (PyInt_Check(color) || PyLong_Check(color)) { + if (PyInt_Check(color)) + r = PyInt_AS_LONG(color); + else + r = (int) PyLong_AsLong(color); +#endif + /* compatibility: ABGR */ a = (UINT8) (r >> 24); b = (UINT8) (r >> 16); @@ -1205,8 +1214,9 @@ _putdata(ImagingObject* self, PyObject* args) PyObject* data; double scale = 1.0; double offset = 0.0; + if (!PyArg_ParseTuple(args, "O|dd", &data, &scale, &offset)) - return NULL; + return NULL; if (!PySequence_Check(data)) { PyErr_SetString(PyExc_TypeError, must_be_sequence);