xslt.pxi: calls to _copyXSLT() cast to the wrong type - lxml fails to build with GCC 14

Bug #2051243 reported by Victor Stinner
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
New
Undecided
Unassigned

Bug Description

lxml fails to build with GCC 14. Apparently, GCC 14 switched -Wincompatible-pointer-types warning into an error by default.

xslt.pki:

    new_xslt._context = stylesheet._context._copy()

this code generates:

  __pyx_t_2 = ((PyObject *)__pyx_f_4lxml_5etree_12_XSLTContext__copy(((struct __pyx_obj_4lxml_5etree__BaseContext *)__pyx_v_stylesheet->_context))); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 684, __pyx_L1_error)

It casts the first argument to the type: "struct __pyx_obj_4lxml_5etree__BaseContext*".

The _copy() function is defined xslt.pki by:

    cdef _BaseContext _copy(self):
        cdef _XSLTContext context
        context = <_XSLTContext>_BaseContext._copy(self)
        context._extension_elements = self._extension_elements
        return context

Cython generates the prototype:

static struct __pyx_obj_4lxml_5etree__BaseContext *__pyx_f_4lxml_5etree_12_XSLTContext__copy(struct __pyx_obj_4lxml_5etree__XSLTContext *__pyx_v_self) { ... }

The first parameter type (self) is: "struct __pyx_obj_4lxml_5etree__XSLTContext*".

XSLT._context is defined in xslt.pki with:

    @cython.no_gc_clear
    cdef class XSLT:
        cdef _XSLTContext _context

Well, I see different options:

* Change XSLT._context type to type expected by _copy(): _BaseContext
* Cast XSLT._context to _BaseContext somehow
* Change _copy() parameter type to _XSLTContext?

Extract of GCC 13 compiler warnings if I pass manually -Wincompatible-pointer-types flag:
---
$ gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -I/usr/include/libxml2 -Isrc -Isrc/lxml/includes -I/tmp/build-env-9r2e6zhz/include -I/usr/include/python3.12 -c src/lxml/etree.c -o etree.o -Wincompatible-pointer-types

(...)

src/lxml/etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_16__call__':
src/lxml/etree.c:225042:73: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [-Wincompatible-pointer-types]
225042 | __pyx_t_2 = ((PyObject *)__pyx_f_4lxml_5etree_12_XSLTContext__copy(((struct __pyx_obj_4lxml_5etree__BaseContext *)__pyx_v_self->_context))); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 543, __pyx_L9_error)
       | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       | |
       | struct __pyx_obj_4lxml_5etree__BaseContext *
src/lxml/etree.c:222496:138: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
222496 | static struct __pyx_obj_4lxml_5etree__BaseContext *__pyx_f_4lxml_5etree_12_XSLTContext__copy(struct __pyx_obj_4lxml_5etree__XSLTContext *__pyx_v_self) {
       | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

src/lxml/etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':
src/lxml/etree.c:226859:71: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [-Wincompatible-pointer-types]
226859 | __pyx_t_2 = ((PyObject *)__pyx_f_4lxml_5etree_12_XSLTContext__copy(((struct __pyx_obj_4lxml_5etree__BaseContext *)__pyx_v_stylesheet->_context))); if (unlikely(!__pyx_t_2)) __PYX_ERR(5, 684, __pyx_L1_error)
       | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       | |
       | struct __pyx_obj_4lxml_5etree__BaseContext *
src/lxml/etree.c:222496:138: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
222496 | static struct __pyx_obj_4lxml_5etree__BaseContext *__pyx_f_4lxml_5etree_12_XSLTContext__copy(struct __pyx_obj_4lxml_5etree__XSLTContext *__pyx_v_self) {
       | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
---

I attach the full output as attached warnings.log.

Revision history for this message
Victor Stinner (vstinner) wrote :
summary: - xslt.pxi: calls to _copyXSLT() cast to the wrong type
+ xslt.pxi: calls to _copyXSLT() cast to the wrong type - lxml fails to
+ build with GCC 14
Revision history for this message
Victor Stinner (vstinner) wrote :

Example of commands to get the warnings (tested on Fedora with GCC 13):

$ git clean -fdx

$ CFLAGS="-Wincompatible-pointer-types" python3 setup.py build_ext --warnings 2>&1|tee build.log

$ grep copy build.log
(...)
src/lxml/etree.c:225039:73: warning: passing argument 1 of ‘__pyx_f_4lxml_5etree_12_XSLTContext__copy’ from incompatible pointer type [-Wincompatible-pointer-types]
(...)

Revision history for this message
Miro Hrončok (churchyard) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.