@@ -130,30 +130,32 @@ cdef class _HelperKernelParams:
130130cdef class _HelperInputVoidPtr:
131131 def __cinit__(self, ptr):
132132 self._pyobj_acquired = False
133+ self._cptr = _helper_input_void_ptr(ptr, &self._helper)
134+
135+ def __dealloc__(self):
136+ _helper_input_void_ptr_free(&self._helper)
137+
138+ @property
139+ def cptr(self):
140+ return <void_ptr>self._cptr
141+
142+
143+ cdef void * _helper_input_void_ptr(ptr, _HelperInputVoidPtrStruct *helper):
144+ helper[0]._pybuffer.buf = NULL
145+ try:
146+ return <void *><void_ptr>ptr
147+ except:
133148 if ptr is None:
134- self._cptr = NULL
135- elif isinstance(ptr, (int)):
136- # Easy run, user gave us an already configured void** address
137- self._cptr = <void*><void_ptr>ptr
138- elif isinstance(ptr, (_driver.CUdeviceptr)):
139- self._cptr = <void*><void_ptr>int(ptr)
149+ return NULL
140150 elif PyObject_CheckBuffer(ptr):
141151 # Easy run, get address from Python Buffer Protocol
142- err_buffer = PyObject_GetBuffer(ptr, &self ._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
152+ err_buffer = PyObject_GetBuffer(ptr, &helper[0] ._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
143153 if err_buffer == -1:
144154 raise RuntimeError("Failed to retrieve buffer through Buffer Protocol")
145- self._pyobj_acquired = True
146- self._cptr = <void*><void_ptr>self._pybuffer.buf
155+ return <void*><void_ptr>(helper[0]._pybuffer.buf)
147156 else:
148157 raise TypeError("Provided argument is of type {} but expected Type {}, {} or object with Buffer Protocol".format(type(ptr), type(None), type(int)))
149158
150- def __dealloc__(self):
151- if self._pyobj_acquired is True:
152- PyBuffer_Release(&self._pybuffer)
153-
154- @property
155- def cptr(self):
156- return <void_ptr>self._cptr
157159
158160{{if 'CUmemPool_attribute_enum' in found_types}}
159161
0 commit comments