[cython/cython] [BUG] classmethods don't compile using the limited api (Issue #5797)

0 views
Skip to first unread message

Andreas Poehlmann

unread,
Nov 5, 2023, 4:58:45 AM11/5/23
to cython/cython, Subscribed

Describe the bug

Hello everyone,

When compiling a class with a classmethod using the limited API I get the following error:

clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DCYTHON_LIMITED_API=1 -DPy_LIMITED_API=0x030B0000 -I/private/var/folders/l4/gpyzwv455hzbmbv78x05555h0000gn/T/build-env-ok8opy1u/include -I/opt/homebrew/opt/pyt...@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c limited_classmethod.cpp -o build/temp.macosx-14-arm64-cpython-311/limited_classmethod.o
limited_classmethod.cpp:6876:5: error: no matching function for call to 'Py_TYPE'
    __Pyx_PyHeapTypeObject_GC_Del(m);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
limited_classmethod.cpp:971:26: note: expanded from macro '__Pyx_PyHeapTypeObject_GC_Del'
    PyTypeObject *type = Py_TYPE(obj);\
                         ^~~~~~~
/opt/homebrew/opt/pyt...@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/object.h:132:29: note: candidate function not viable: no known conversion from '__pyx_CyFunctionObject *' to 'PyObject *' (aka '_object *') for 1st argument
static inline PyTypeObject* Py_TYPE(PyObject *ob) {
                            ^
limited_classmethod.cpp:7396:9: error: use of undeclared identifier 'PyMethodDescrObject'; did you mean 'PyMethodDescr_Type'?
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
        ^~~~~~~~~~~~~~~~~~~
        PyMethodDescr_Type
/opt/homebrew/opt/pyt...@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/descrobject.h:22:26: note: 'PyMethodDescr_Type' declared here
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
                         ^
limited_classmethod.cpp:7396:39: error: use of undeclared identifier 'PyMethodDescrObject'; did you mean 'PyMethodDescr_Type'?
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
                                      ^~~~~~~~~~~~~~~~~~~
                                      PyMethodDescr_Type
/opt/homebrew/opt/pyt...@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11/descrobject.h:22:26: note: 'PyMethodDescr_Type' declared here
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
                         ^
limited_classmethod.cpp:7396:60: error: expected expression
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
                                                           ^
limited_classmethod.cpp:7396:30: error: use of undeclared identifier 'descr'
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
                             ^
limited_classmethod.cpp:7400:32: error: use of undeclared identifier 'descr'
        PyTypeObject *d_type = descr->d_common.d_type;
                               ^
limited_classmethod.cpp:7402:47: error: use of undeclared identifier 'descr'
        return PyDescr_NewClassMethod(d_type, descr->d_method);
                                              ^
limited_classmethod.cpp:7405:14: error: use of undeclared identifier 'PyMethod_Check'
    else if (PyMethod_Check(method)) {
             ^
limited_classmethod.cpp:7406:34: error: use of undeclared identifier 'PyMethod_GET_FUNCTION'
        return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
                                 ^
limited_classmethod.cpp:7409:16: error: use of undeclared identifier 'PyClassMethod_New'
        return PyClassMethod_New(method);
               ^
10 errors generated.

Code to reproduce the behaviour:

# limited_classmethod.pyx

cdef class A:
    @classmethod
    def method(cls):
        pass

Expected behaviour

It should compile.

OS

No response

Python version

No response

Cython version

No response

Additional context

classmethod implementation: https://github.com/cython/cython/blob/0f2a0d38b60e10e401aa1435801b2b8975083c7b/Cython/Utility/CythonFunction.c#L1754-L1804


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <cython/cython/issues/5797@github.com>

da-woods

unread,
May 16, 2024, 3:52:06 AM5/16/24
to cython/cython, Subscribed

Closed #5797 as completed via d9dde8b.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <cython/cython/issue/5797/issue_event/12828634689@github.com>

da-woods

unread,
May 16, 2024, 3:52:07 AM5/16/24
to cython/cython, Subscribed

Closed #5797 as completed via #5800.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <cython/cython/issue/5797/issue_event/12828634684@github.com>

Reply all
Reply to author
Forward
0 new messages