[Cython] view[0].methodcall() produces invalid C when view is memoryview of extension type

Matěj Laitl matej at laitl.cz
Sat Mar 23 23:57:51 CET 2013


Hi,
following test code produces C code that fails to compile:
> cdef class ExtensionType(object):
>     cdef public int dummy
>     
>     def __init__(self, n):
>         self.dummy = n
>     
>     cdef cfoo(self):
>         print self.dummy
> 
> items = [ExtensionType(1), ExtensionType(2)]
> cdef ExtensionType[:] view = np.array(items, dtype=ExtensionType)
> view[0].cfoo()

with gcc error and relevant C file lines:
extension_type_memoryview.c:2604:94: error: ‘PyObject’ has no member named 
‘__pyx_vtab’

2570:  PyObject *__pyx_t_1 = NULL;
(...)
2601:  __pyx_t_1 = (PyObject *) *((struct 
    :__pyx_obj_25extension_type_memoryview_ExtensionType * *) ( /* dim=0 */
    : (__pyx_v_25extension_type_memoryview_view.data + __pyx_t_2 *
    : __pyx_v_25extension_type_memoryview_view.strides[0]) ));
2602:  __Pyx_INCREF((PyObject*)__pyx_t_1);
2603:  /* __pyx_t_4 allocated */
2604:  __pyx_t_4 = ((struct
    : __pyx_vtabstruct_25extension_type_memoryview_ExtensionType *)__pyx_t_1
    :->__pyx_vtab)->cfoo(__pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename
    : = __pyx_f[0]; __pyx_lineno = 69;

It seems that generic PyObject* temporary for __pyx_t_1 is used here while 
typed ExtensionType* temporary should have been used instead (as suggested by 
excess casting on line 2601).

I have the above test-case (and a bit more) prepared as a patch that I'll 
pull-request one this seemingly trivial bug is fixed in git.

Regards,
		Matěj


More information about the cython-devel mailing list