8000 Don't use C++ exceptions in convert_trans_affine · matplotlib/matplotlib@8b6229c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b6229c

Browse files
committed
Don't use C++ exceptions in convert_trans_affine
1 parent 48b851f commit 8b6229c

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/py_converters.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,27 +327,26 @@ int convert_trans_affine(PyObject *obj, void *transp)
327327
return 1;
328328
}
329329

330-
try
331-
{
332-
numpy::array_view<const double, 2> matrix(obj);
330+
PyArrayObject *array = (PyArrayObject *)PyArray_ContiguousFromAny(obj, NPY_DOUBLE, 2, 2);
331+
if (array == NULL) {
332+
return 0;
333+
}
333334

334-
if (matrix.dim(0) == 3 && matrix.dim(1) == 3) {
335-
trans->sx = matrix(0, 0);
336-
trans->shx = matrix(0, 1);
337-
trans->tx = matrix(0, 2);
335+
if (PyArray_DIM(array, 0) == 3 && PyArray_DIM(array, 1) == 3) {
336+
double *buffer = (double *)PyArray_DATA(array);
337+
trans->sx = buffer[0];
338+
trans->shx = buffer[1];
339+
trans->tx = buffer[2];
338340

339-
trans->shy = matrix(1, 0);
340-
trans->sy = matrix(1, 1);
341-
trans->ty = matrix(1, 2);
341+
trans->shy = buffer[3];
342+
trans->sy = buffer[4];
343+
trans->ty = buffer[5];
342344

343-
return 1;
344-
}
345-
}
346-
catch (py::exception &)
347-
{
348-
return 0;
345+
Py_DECREF(array);
346+
return 1;
349347
}
350348

349+
Py_DECREF(array);
351350
PyErr_SetString(PyExc_ValueError, "Invalid affine transformation matrix");
352351
return 0;
353352
}

0 commit comments

Comments
 (0)
0