-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Inspect arg as Python object, instead of using PyErr_Clear() #9726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5f80642
d3b91de
a5a7a18
a99854d
9197939
47f1a4a
b846010
a1115c8
ce207da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1059,8 +1059,15 @@ static PyObject * | |
| _convert_matrix(ImagingObject *self, PyObject *args) { | ||
| char *mode_name; | ||
| float m[12]; | ||
| if (!PyArg_ParseTuple(args, "s(ffff)", &mode_name, m + 0, m + 1, m + 2, m + 3)) { | ||
| PyErr_Clear(); | ||
| PyObject *matrix; | ||
| if (!PyArg_ParseTuple(args, "sO", &mode_name, &matrix)) { | ||
| return NULL; | ||
| } | ||
| Py_ssize_t size = PySequence_Size(matrix); | ||
| if (size == -1) { | ||
| return NULL; | ||
| } | ||
| if (size == 12) { | ||
| if (!PyArg_ParseTuple( | ||
| args, | ||
| "s(ffffffffffff)", | ||
|
|
@@ -1078,30 +1085,42 @@ _convert_matrix(ImagingObject *self, PyObject *args) { | |
| m + 10, | ||
| m + 11 | ||
| )) { | ||
| PyErr_SetString(PyExc_TypeError, "matrix must be tuple of length 4 or 12"); | ||
| return NULL; | ||
| } | ||
| } else if (size == 4) { | ||
| if (!PyArg_ParseTuple( | ||
| args, "s(ffff)", &mode_name, m + 0, m + 1, m + 2, m + 3 | ||
| )) { | ||
| return NULL; | ||
| } | ||
| } else { | ||
| PyErr_SetString(PyExc_TypeError, "matrix must be tuple of length 4 or 12"); | ||
| return NULL; | ||
| } | ||
|
|
||
| const ModeID mode = findModeID(mode_name); | ||
|
|
||
| return PyImagingNew(ImagingConvertMatrix(self->image, mode, m)); | ||
| } | ||
|
|
||
| static PyObject * | ||
| _convert_transparent(ImagingObject *self, PyObject *args) { | ||
| char *mode_name; | ||
| int r, g, b; | ||
| if (PyArg_ParseTuple(args, "s(iii)", &mode_name, &r, &g, &b)) { | ||
| const ModeID mode = findModeID(mode_name); | ||
| return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, g, b)); | ||
| int r, g = 0, b = 0; | ||
| PyObject *transparency; | ||
| if (!PyArg_ParseTuple(args, "sO", &mode_name, &transparency)) { | ||
| return NULL; | ||
| } | ||
| PyErr_Clear(); | ||
| if (PyArg_ParseTuple(args, "si", &mode_name, &r)) { | ||
| const ModeID mode = findModeID(mode_name); | ||
| return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, 0, 0)); | ||
|
|
||
| if (PySequence_Check(transparency)) { | ||
| if (!PyArg_ParseTuple(args, "s(iii)", &mode_name, &r, &g, &b)) { | ||
| return NULL; | ||
| } | ||
| } else if (!PyArg_ParseTuple(args, "si", &mode_name, &r)) { | ||
| return NULL; | ||
| } | ||
| return NULL; | ||
|
Comment on lines
+1114
to
-1104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comment as above about confusing error messages stands here (the allowed values are either a single integer, or a 3-sequence of integers), but it's much harder to reach from userland, since you'd either need to call |
||
|
|
||
| const ModeID mode = findModeID(mode_name); | ||
| return PyImagingNew(ImagingConvertTransparent(self->image, mode, r, g, b)); | ||
| } | ||
|
|
||
| static PyObject * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review note to self: it's OK to not decref
matrix, since"O"inParseTupledoesn't create a strong reference.