Skip to content

Commit

Permalink
STYLE: Do not call PyBuffer_Release when PyObject_GetBuffer has failed
Browse files Browse the repository at this point in the history
`PyBuffer_Release` should only be called after a _successful_
`PyObject_GetBuffer` call. As specified at
https://docs.python.org/3.12/c-api/buffer.html#c.PyObject_GetBuffer
  • Loading branch information
N-Dekker committed Oct 4, 2024
1 parent dd7d0d6 commit d887443
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 4 deletions.
1 change: 0 additions & 1 deletion Modules/Bridge/NumPy/include/itkPyBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ PyBuffer<TImage>::_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObj
if (PyObject_GetBuffer(arr, &pyBuffer, PyBUF_ND | PyBUF_ANY_CONTIGUOUS) == -1)
{
PyErr_SetString(PyExc_RuntimeError, "Cannot get an instance of NumPy array.");
PyBuffer_Release(&pyBuffer);
return nullptr;
}

Expand Down
1 change: 0 additions & 1 deletion Modules/Bridge/NumPy/include/itkPyVectorContainer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ PyVectorContainer<TElementIdentifier, TElement>::_vector_container_from_array(Py
if (PyObject_GetBuffer(arr, &pyBuffer, PyBUF_CONTIG) == -1)
{
PyErr_SetString(PyExc_RuntimeError, "Cannot get an instance of NumPy array.");
PyBuffer_Release(&pyBuffer);
return nullptr;
}

Expand Down
2 changes: 0 additions & 2 deletions Modules/Bridge/NumPy/include/itkPyVnl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ PyVnl<TElement>::_GetVnlVectorFromArray(PyObject * arr, PyObject * shape) -> con
if (PyObject_GetBuffer(arr, &pyBuffer, PyBUF_CONTIG) == -1)
{
PyErr_SetString(PyExc_RuntimeError, "Cannot get an instance of NumPy array.");
PyBuffer_Release(&pyBuffer);
return VectorType();
}

Expand Down Expand Up @@ -125,7 +124,6 @@ PyVnl<TElement>::_GetVnlMatrixFromArray(PyObject * arr, PyObject * shape) -> con
if (PyObject_GetBuffer(arr, &pyBuffer, PyBUF_CONTIG) == -1)
{
PyErr_SetString(PyExc_RuntimeError, "Cannot get an instance of NumPy array.");
PyBuffer_Release(&pyBuffer);
return MatrixType();
}

Expand Down

0 comments on commit d887443

Please sign in to comment.