Only call PyTuple_Check once in getink

This commit is contained in:
Andrew Murray 2023-03-31 21:59:06 +11:00
parent d84e227204
commit 59d67fa68a

View File

@ -502,13 +502,10 @@ getink(PyObject *color, Imaging im, char *ink) {
be cast to either UINT8 or INT32 */
int rIsInt = 0;
int tupleSize = 0;
if (PyTuple_Check(color)) {
tupleSize = PyTuple_GET_SIZE(color);
int tupleSize = PyTuple_Check(color) ? PyTuple_GET_SIZE(color) : -1;
if (tupleSize == 1) {
color = PyTuple_GetItem(color, 0);
}
}
if (im->type == IMAGING_TYPE_UINT8 || im->type == IMAGING_TYPE_INT32 ||
im->type == IMAGING_TYPE_SPECIAL) {
if (PyLong_Check(color)) {
@ -521,7 +518,7 @@ getink(PyObject *color, Imaging im, char *ink) {
PyErr_SetString(
PyExc_TypeError, "color must be int or single-element tuple");
return NULL;
} else if (!PyTuple_Check(color)) {
} else if (tupleSize == -1) {
PyErr_SetString(PyExc_TypeError, "color must be int or tuple");
return NULL;
}