Skip to content

Commit 0c4232c

Browse files
authored
Merge pull request #5505 from thewtex/pysequence-getitem-itk-6
COMP: Avoid PySequence_Fast_GET_ITEM - ITK 6
2 parents a4ae00e + dd843f4 commit 0c4232c

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Modules/Bridge/NumPy/include/itkPyBuffer.hxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ PyBuffer<TImage>::_get_image_view_from_contiguous_array(PyObject * arr, PyObject
7878

7979
for (unsigned int i = 0; i < dimension; ++i)
8080
{
81-
PyObject * const item = PySequence_Fast_GET_ITEM(shapeseq, i);
81+
PyObject * const item = PySequence_GetItem(shapeseq, i);
8282
size[i] = static_cast<SizeValueType>(PyInt_AsLong(item));
83+
Py_DECREF(item);
8384
}
8485

8586
const SizeValueType numberOfPixels = size.CalculateProductOfElements();

Modules/Bridge/NumPy/include/itkPyVectorContainer.hxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ PyVectorContainer<TElementIdentifier, TElement>::_vector_container_from_array(Py
6666
PyObject * const shapeseq = PySequence_Fast(shape, "expected sequence");
6767
const unsigned int dimension = PySequence_Size(shape);
6868

69-
PyObject * item = PySequence_Fast_GET_ITEM(shapeseq, 0); // Only one dimension
69+
PyObject * item = PySequence_GetItem(shapeseq, 0); // Only one dimension
7070
const size_t numberOfElements = static_cast<size_t>(PyInt_AsLong(item));
71+
Py_DECREF(item);
7172

7273
const size_t len = numberOfElements * sizeof(DataType);
7374
if (bufferLength < 0 || static_cast<size_t>(bufferLength) != len)

Modules/Bridge/NumPy/include/itkPyVnl.hxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ PyVnl<TElement>::_GetVnlVectorFromArray(PyObject * arr, PyObject * const shape)
6565
PyObject * const shapeseq = PySequence_Fast(shape, "expected sequence");
6666
const unsigned int dimension = PySequence_Size(shape);
6767

68-
PyObject * const item = PySequence_Fast_GET_ITEM(shapeseq, 0); // Only one dimension
68+
PyObject * const item = PySequence_GetItem(shapeseq, 0); // Only one dimension
6969
const size_t numberOfElements = static_cast<size_t>(PyInt_AsLong(item));
70+
Py_DECREF(item);
7071

7172
const size_t len = numberOfElements * sizeof(DataType);
7273
if (bufferLength < 0 || static_cast<size_t>(bufferLength) != len)
@@ -125,8 +126,9 @@ PyVnl<TElement>::_GetVnlMatrixFromArray(PyObject * arr, PyObject * const shape)
125126

126127
for (unsigned int i = 0; i < 2; ++i)
127128
{
128-
PyObject * const item = PySequence_Fast_GET_ITEM(shapeseq, i);
129+
PyObject * const item = PySequence_GetItem(shapeseq, i);
129130
size[i] = static_cast<unsigned int>(PyInt_AsLong(item));
131+
Py_DECREF(item);
130132
numberOfElements *= size[i];
131133
}
132134

0 commit comments

Comments
 (0)