[Cython] [PATCH] Refcount error when transposing memoryview attribute of an extension class

Matěj Laitl matej at laitl.cz
Mon Apr 8 12:29:23 CEST 2013


Hi cython-devel and Mark,
I was getting
> Fatal Python error: Acquisition count is 0 (line XYZ)
when I was doing
> cdef class MemViewContainer:
>     cdef double[:, :] A
>     
>     cdef a_method(self):
>         self.A = np.eye(2)
>         some_function(self.A.T)
>         some_function(self.A.T)

I have found out that it is caused by the self.A.T expression - Cython emits 
__PYX_XDEC_MEMVIEW() after the call, but no __PYX_INC_MEMVIEW() before the 
call. This doesn't happen if the memoryview is a function-local variable.

Proper test case is in the pull request [1] along with an ad-hoc patch that 
fixes the problem here, but needs review whether it is actually correct. I'd be 
very grateful if a fix for this problem could get it into Cython 0.19.

Cython version: 0.19b1 3a6b9856187d7e490e08

[1] https://github.com/cython/cython/pull/201

Regards,
		Matěj


More information about the cython-devel mailing list