mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-30 02:33:07 +03:00
Merge pull request #3098 from uploadcare/getlist-fixes
Raise error if it is occurred during conversion in getlist
This commit is contained in:
commit
9d404e9979
|
@ -66,6 +66,14 @@ class TestColorLut3DCoreAPI(PillowTestCase):
|
|||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, 0] * 9)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, "0"] * 8)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, 16)
|
||||
|
||||
def test_correct_args(self):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
n = PyObject_Length(arg);
|
||||
n = PySequence_Size(arg);
|
||||
if (length && wrong_length && n != *length) {
|
||||
PyErr_SetString(PyExc_ValueError, wrong_length);
|
||||
return NULL;
|
||||
|
@ -399,7 +399,6 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
seq = PySequence_Fast(arg, must_be_sequence);
|
||||
if ( ! seq) {
|
||||
free(list);
|
||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -427,12 +426,16 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
}
|
||||
}
|
||||
|
||||
Py_DECREF(seq);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (length)
|
||||
*length = n;
|
||||
|
||||
PyErr_Clear();
|
||||
Py_DECREF(seq);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user