mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-29 02:03:25 +03:00
Added specific error if coordinate type is incorrect
This commit is contained in:
parent
7191555d89
commit
2d9dfefe6e
|
@ -70,9 +70,11 @@ def test_invalid_coords():
|
||||||
coords = ["a", "b"]
|
coords = ["a", "b"]
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
with pytest.raises(SystemError):
|
with pytest.raises(ValueError) as e:
|
||||||
ImagePath.Path(coords)
|
ImagePath.Path(coords)
|
||||||
|
|
||||||
|
assert str(e.value) == "incorrect coordinate type"
|
||||||
|
|
||||||
|
|
||||||
def test_path_odd_number_of_coordinates():
|
def test_path_odd_number_of_coordinates():
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
62
src/path.c
62
src/path.c
|
@ -162,42 +162,37 @@ PyPath_Flatten(PyObject *data, double **pxy) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define assign_item_to_array(op, decref) \
|
||||||
|
if (PyFloat_Check(op)) { \
|
||||||
|
xy[j++] = PyFloat_AS_DOUBLE(op); \
|
||||||
|
} else if (PyLong_Check(op)) { \
|
||||||
|
xy[j++] = (float)PyLong_AS_LONG(op); \
|
||||||
|
} else if (PyNumber_Check(op)) { \
|
||||||
|
xy[j++] = PyFloat_AsDouble(op); \
|
||||||
|
} else if (PyArg_ParseTuple(op, "dd", &x, &y)) { \
|
||||||
|
xy[j++] = x; \
|
||||||
|
xy[j++] = y; \
|
||||||
|
} else { \
|
||||||
|
PyErr_SetString(PyExc_ValueError, "incorrect coordinate type"); \
|
||||||
|
if (decref) { \
|
||||||
|
Py_DECREF(op); \
|
||||||
|
} \
|
||||||
|
free(xy); \
|
||||||
|
return -1; \
|
||||||
|
}
|
||||||
|
|
||||||
/* Copy table to path array */
|
/* Copy table to path array */
|
||||||
if (PyList_Check(data)) {
|
if (PyList_Check(data)) {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
double x, y;
|
double x, y;
|
||||||
PyObject *op = PyList_GET_ITEM(data, i);
|
PyObject *op = PyList_GET_ITEM(data, i);
|
||||||
if (PyFloat_Check(op)) {
|
assign_item_to_array(op, 0);
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
|
||||||
} else if (PyLong_Check(op)) {
|
|
||||||
xy[j++] = (float)PyLong_AS_LONG(op);
|
|
||||||
} else if (PyNumber_Check(op)) {
|
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
|
||||||
} else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
|
||||||
xy[j++] = x;
|
|
||||||
xy[j++] = y;
|
|
||||||
} else {
|
|
||||||
free(xy);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (PyTuple_Check(data)) {
|
} else if (PyTuple_Check(data)) {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
double x, y;
|
double x, y;
|
||||||
PyObject *op = PyTuple_GET_ITEM(data, i);
|
PyObject *op = PyTuple_GET_ITEM(data, i);
|
||||||
if (PyFloat_Check(op)) {
|
assign_item_to_array(op, 0);
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
|
||||||
} else if (PyLong_Check(op)) {
|
|
||||||
xy[j++] = (float)PyLong_AS_LONG(op);
|
|
||||||
} else if (PyNumber_Check(op)) {
|
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
|
||||||
} else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
|
||||||
xy[j++] = x;
|
|
||||||
xy[j++] = y;
|
|
||||||
} else {
|
|
||||||
free(xy);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
@ -213,20 +208,7 @@ PyPath_Flatten(PyObject *data, double **pxy) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PyFloat_Check(op)) {
|
assign_item_to_array(op, 1);
|
||||||
xy[j++] = PyFloat_AS_DOUBLE(op);
|
|
||||||
} else if (PyLong_Check(op)) {
|
|
||||||
xy[j++] = (float)PyLong_AS_LONG(op);
|
|
||||||
} else if (PyNumber_Check(op)) {
|
|
||||||
xy[j++] = PyFloat_AsDouble(op);
|
|
||||||
} else if (PyArg_ParseTuple(op, "dd", &x, &y)) {
|
|
||||||
xy[j++] = x;
|
|
||||||
xy[j++] = y;
|
|
||||||
} else {
|
|
||||||
Py_DECREF(op);
|
|
||||||
free(xy);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Py_DECREF(op);
|
Py_DECREF(op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user