Hi,

I have a problem with a method in a subclass that overrides the parent
method. The setup is basically as follows:

-------------------------------
# base class:
cdef class _BaseContext:
    cdef xpath.xmlXPathContext* _xpathCtxt
    cdef _Document _doc
    cdef dict _extensions
    ... # other attributes here

    cdef _BaseContext _copy(self):
        cdef _BaseContext context
        if self._namespaces is not None:
            namespaces = self._namespaces[:]
        context = self.__class__(namespaces, None, False,
                                 self._build_smart_strings)
        if self._extensions is not None:
            context._extensions = self._extensions.copy()
        return context

# subclass:
cdef class _XSLTContext(_BaseContext):
    cdef xslt.xsltTransformContext* _xsltCtxt
    cdef _ReadOnlyElementProxy _extension_element_proxy
    cdef dict _extension_elements
    ...
    cdef _BaseContext _copy(self):
        cdef _XSLTContext context
        context = <_XSLTContext>_BaseContext._copy(self)
        context._extension_elements = self._extension_elements
        return context

# using class:
cdef class XSLT:
    cdef _XSLTContext _context
    cdef xslt.xsltStylesheet* _c_style
    ... # other attributes here
    def __call__(self, _input, *, profile_run=False, **kw):
        ...
        try:
            self._error_log.connect()
            context = self._context._copy()
            context.register_context(transform_ctxt, input_doc)
-------------------------------

For the method call to ._copy(), Cython generates this code:

-------------------------------
    /* __pyx_t_1 allocated */
    __pyx_t_1 = ((PyObject *)((struct
__pyx_vtabstruct_4lxml_5etree__XSLTContext *)((struct
__pyx_obj_4lxml_5etree_XSLT
*)__pyx_v_self)->_context->__pyx_base.__pyx_vtab)->__pyx_base._copy(((struct
__pyx_obj_4lxml_5etree__BaseContext *)((struct __pyx_obj_4lxml_5etree_XSLT
*)__pyx_v_self)->_context))); if (unlikely(!__pyx_t_1)) /* ... */

    __Pyx_GOTREF(__pyx_t_1);

    if (!(__Pyx_TypeTest(__pyx_t_1,
__pyx_ptype_4lxml_5etree__XSLTContext))) /* ... */

    __Pyx_DECREF(((PyObject *)__pyx_v_context));

    __pyx_v_context = ((struct __pyx_obj_4lxml_5etree__XSLTContext
*)__pyx_t_1);

    __pyx_t_1 = 0;
    /* __pyx_t_1 released */
-------------------------------

The problem with this is that gcc 4.3.2(-1ubuntu12) generates a call to the
baseclass's _copy() method instead of the one in _XSLTContext, which
prevents the "_extension_elements" field from being set. I can fix this by
passing "-fno-strict-aliasing" to gcc. However, I thought this was fixed in
Py3, where I also get the above problem.

Does anyone have an idea if there is anything we can do in Cython to fix
this? Or does anyone see anything in the code that might trigger this?

Thanks for any hints!

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to