Skip to content

Commit

Permalink
FIX: Handle long values in _imaging getink
Browse files Browse the repository at this point in the history
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.*.
  • Loading branch information
Brian Crowell authored and Brian Crowell committed Jan 10, 2013
1 parent 1978851 commit c8ce29c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions _imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c8ce29c

Please sign in to comment.