Skip to content

[ENH] Use pythoncapi_compat.h in Cython? #3934

Closed
@vstinner

Description

@vstinner

Hi,

I created pythoncapi_compat.h header file to ease support multiple Python versions. In practice, it provides new functions of the Python C API to old Python versions (up to Python 2.7, including Python 3.5).

https://github.com/pythoncapi/pythoncapi_compat

Would it make sense to use it in Cython?

Cython/Utility/ModuleSetupCode.c contains code like:

#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)

#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif

pythoncapi_compat.h provides Py_SET_REFCNT(), Py_SET_SIZE() and Py_NewRef() on all Python versions (use existing functions if available). The advantage is use regular Py_xxx() functions rather than having to use custom __Pyx_xxx() functions.

The problem is that I don't understand Cython is implemented, and so I'm not sure how to include an header file in ModuleSetupCode.c for example.

Victor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions