1- # Copyright (c) 2020-2024 , NVIDIA CORPORATION. All rights reserved.
1+ # Copyright (c) 2020-2025 , NVIDIA CORPORATION. All rights reserved.
22# See file LICENSE for terms.
33
44# cython: language_level=3
55
66
7- from cpython.buffer cimport PyBuffer_IsContiguous
7+ from cpython.buffer cimport (
8+ PyBUF_FULL_RO,
9+ PyBuffer_IsContiguous,
10+ PyBuffer_Release,
11+ PyObject_GetBuffer,
12+ )
813from cpython.mem cimport PyMem_Free, PyMem_Malloc
9- from cpython.memoryview cimport PyMemoryView_FromObject, PyMemoryView_GET_BUFFER
1014from cpython.ref cimport Py_INCREF
11- from cpython.tuple cimport PyTuple_New, PyTuple_SET_ITEM
15+ from cpython.tuple cimport PyTuple_New, PyTuple_SetItem
1216from cython cimport auto_pickle, boundscheck, initializedcheck, nonecheck, wraparound
1317from cython.view cimport array
1418from libc.stdint cimport uintptr_t
@@ -75,7 +79,7 @@ cdef class Array:
7579 def __cinit__ (self , obj ):
7680 cdef dict iface = getattr (obj, " __cuda_array_interface__" , None )
7781 self .cuda = (iface is not None )
78- cdef const Py_buffer* pybuf
82+ cdef Py_buffer* pybuf
7983 cdef str typestr
8084 cdef tuple data, shape, strides
8185 cdef Py_ssize_t i
@@ -125,8 +129,7 @@ cdef class Array:
125129 self .shape_mv = None
126130 self .strides_mv = None
127131 else :
128- mv = PyMemoryView_FromObject(obj)
129- pybuf = PyMemoryView_GET_BUFFER(mv)
132+ PyObject_GetBuffer(obj, & pybuf, PyBUF_FULL_RO)
130133
131134 if pybuf.suboffsets != NULL :
132135 raise NotImplementedError (" Suboffsets are not supported" )
@@ -156,6 +159,7 @@ cdef class Array:
156159 else :
157160 self .shape_mv = None
158161 self .strides_mv = None
162+ PyBuffer_Release(pybuf)
159163
160164 cpdef bint _c_contiguous(self ):
161165 return _c_contiguous(
@@ -203,7 +207,7 @@ cdef class Array:
203207 for i in range (self .ndim):
204208 o = self .shape_mv[i]
205209 Py_INCREF(o)
206- PyTuple_SET_ITEM (shape, i, o)
210+ PyTuple_SetItem (shape, i, o)
207211 return shape
208212
209213 @property
@@ -219,13 +223,13 @@ cdef class Array:
219223 for i from self .ndim > i >= 0 by 1 :
220224 o = self .strides_mv[i]
221225 Py_INCREF(o)
222- PyTuple_SET_ITEM (strides, i, o)
226+ PyTuple_SetItem (strides, i, o)
223227 else :
224228 s = self .itemsize
225229 for i from self .ndim > i >= 0 by 1 :
226230 o = s
227231 Py_INCREF(o)
228- PyTuple_SET_ITEM (strides, i, o)
232+ PyTuple_SetItem (strides, i, o)
229233 s *= self .shape_mv[i]
230234 return strides
231235
0 commit comments