@@ -128,31 +128,32 @@ cdef class _HelperKernelParams:
128128
129129cdef class _HelperInputVoidPtr:
130130 def __cinit__(self, ptr):
131- self._pyobj_acquired = False
131+ self._cptr = _helper_input_void_ptr(ptr, &self._helper)
132+
133+ def __dealloc__(self):
134+ _helper_input_void_ptr_free(&self._helper)
135+
136+ @property
137+ def cptr(self):
138+ return <void_ptr>self._cptr
139+
140+
141+ cdef void * _helper_input_void_ptr(ptr, _HelperInputVoidPtrStruct *helper):
142+ helper[0]._pybuffer.buf = NULL
143+ try:
144+ return <void *><void_ptr>ptr
145+ except:
132146 if ptr is None:
133- self._cptr = NULL
134- elif isinstance(ptr, (int)):
135- # Easy run, user gave us an already configured void** address
136- self._cptr = <void*><void_ptr>ptr
137- elif isinstance(ptr, (_driver["CUdeviceptr"])):
138- self._cptr = <void*><void_ptr>int(ptr)
147+ return NULL
139148 elif PyObject_CheckBuffer(ptr):
140149 # Easy run, get address from Python Buffer Protocol
141- err_buffer = PyObject_GetBuffer(ptr, &self ._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
150+ err_buffer = PyObject_GetBuffer(ptr, &helper[0] ._pybuffer, PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
142151 if err_buffer == -1:
143152 raise RuntimeError("Failed to retrieve buffer through Buffer Protocol")
144- self._pyobj_acquired = True
145- self._cptr = <void*><void_ptr>self._pybuffer.buf
153+ return <void*><void_ptr>(helper[0]._pybuffer.buf)
146154 else:
147155 raise TypeError("Provided argument is of type {} but expected Type {}, {} or object with Buffer Protocol".format(type(ptr), type(None), type(int)))
148156
149- def __dealloc__(self):
150- if self._pyobj_acquired is True:
151- PyBuffer_Release(&self._pybuffer)
152-
153- @property
154- def cptr(self):
155- return <void_ptr>self._cptr
156157
157158{{if 'CUmemPool_attribute_enum' in found_types}}
158159
0 commit comments