Skip to content

Cython incompatible with Python 3.7 #1978

@warsaw

Description

@warsaw

I think Cython is no longer compatible with Python 3.7 because the generated code reaches inside the PyThreadState structure and tries to access non-public structure members that no longer exist. I found this problem when trying to build lxml's git master HEAD using Python 3.7's git master HEAD in a virtual environment. Here's an example of the error:

    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DCYTHON_CLINE_IN_TRACEBACK=1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2 -Isrc -Isrc/lxml/includes -I/tmp/py37/include -I/usr/local/include/python3.7m -c src/lxml/etree.c -o build/temp.macosx-10.12-x86_64-3.7/src/lxml/etree.o -w -flat_namespace
    src/lxml/etree.c:257734:21: error: no member named 'exc_type' in 'struct _ts'
        *type = tstate->exc_type;
                ~~~~~~  ^
    src/lxml/etree.c:257735:22: error: no member named 'exc_value' in 'struct _ts'; did you mean 'curexc_value'?
        *value = tstate->exc_value;
                         ^~~~~~~~~
                         curexc_value
    /usr/local/include/python3.7m/pystate.h:169:15: note: 'curexc_value' declared here
        PyObject *curexc_value;
                  ^
    src/lxml/etree.c:257736:19: error: no member named 'exc_traceback' in 'struct _ts'; did you mean 'curexc_traceback'?
        *tb = tstate->exc_traceback;
                      ^~~~~~~~~~~~~
                      curexc_traceback
    /usr/local/include/python3.7m/pystate.h:170:15: note: 'curexc_traceback' declared here
        PyObject *curexc_traceback;
                  ^

Looking an example of the generated code:

/* SaveResetException */
  #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);

and indeed exc_type, exc_value and exc_traceback do not exist in Python 3.7.

The generated code should probably be using PyErr_Fetch() instead. https://docs.python.org/3.7/c-api/exceptions.html#c.PyErr_Fetch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions