@@ -842,7 +842,7 @@ static int DPEXRT_sycl_usm_ndarray_from_python(PyObject *obj,
842
842
}
843
843
844
844
if (!(arystruct -> meminfo = NRT_MemInfo_new_from_usmndarray (
845
- ( PyObject * ) arrayobj , data , nitems , itemsize , qref )))
845
+ obj , data , nitems , itemsize , qref )))
846
846
{
847
847
DPEXRT_DEBUG (drt_debug_print (
848
848
"DPEXRT-ERROR: NRT_MemInfo_new_from_usmndarray failed "
@@ -851,11 +851,14 @@ static int DPEXRT_sycl_usm_ndarray_from_python(PyObject *obj,
851
851
goto error ;
852
852
}
853
853
854
+ Py_XDECREF (arrayobj );
855
+ Py_IncRef (obj );
856
+
854
857
arystruct -> data = data ;
855
858
arystruct -> sycl_queue = qref ;
856
859
arystruct -> nitems = nitems ;
857
860
arystruct -> itemsize = itemsize ;
858
- arystruct -> parent = ( PyObject * ) arrayobj ;
861
+ arystruct -> parent = obj ;
859
862
860
863
p = arystruct -> shape_and_strides ;
861
864
@@ -939,26 +942,31 @@ static PyObject *box_from_arystruct_parent(usmarystruct_t *arystruct,
939
942
drt_debug_print ("DPEXRT-DEBUG: In box_from_arystruct_parent.\n" ));
940
943
941
944
if (!(arrayobj = PyUSMNdArray_ARRAYOBJ (arystruct -> parent ))) {
945
+ Py_XDECREF (arrayobj );
942
946
DPEXRT_DEBUG (
943
947
drt_debug_print ("DPEXRT-DEBUG: Arrayobj cannot be boxed from "
944
948
"parent as parent pointer is NULL.\n" ));
945
949
return NULL ;
946
950
}
947
951
948
952
if ((void * )UsmNDArray_GetData (arrayobj ) != arystruct -> data ) {
953
+ Py_XDECREF (arrayobj );
949
954
DPEXRT_DEBUG (drt_debug_print (
950
955
"DPEXRT-DEBUG: Arrayobj cannot be boxed "
951
956
"from parent as data pointer in the arystruct is not the same as "
952
957
"the data pointer in the parent object.\n" ));
953
958
return NULL ;
954
959
}
955
960
956
- if (UsmNDArray_GetNDim (arrayobj ) != ndim )
961
+ if (UsmNDArray_GetNDim (arrayobj ) != ndim ) {
962
+ Py_XDECREF (arrayobj );
957
963
return NULL ;
964
+ }
958
965
959
966
p = arystruct -> shape_and_strides ;
960
967
shape = UsmNDArray_GetShape (arrayobj );
961
968
strides = UsmNDArray_GetStrides (arrayobj );
969
+ Py_XDECREF (arrayobj );
962
970
963
971
// Ensure the shape of the array to be boxed matches the shape of the
964
972
// original parent.
0 commit comments