This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2021-04-01.06:47:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1617259651.04.0.276896882913.issue43688@roundup.psfhosted.org>
In-reply-to
Content
Currently, setup.py doesn't build xxlimited and xxlimited_35 extension modules with the limited C API if Python is built in debug mode. I only found two functions affected by Py_DEBUG macro in the limited C API: Py_INCREF() and Py_DECREF().

Example:
---
#if defined(Py_DEBUG) && !defined(Py_REF_DEBUG)
#define Py_REF_DEBUG
#endif

static inline void _Py_INCREF(PyObject *op)
{
#ifdef Py_REF_DEBUG
    _Py_RefTotal++;
#endif
    op->ob_refcnt++;
}
#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))
---

If Py_DEBUG is defined (Python built in debug mode), Py_INCREF() increments the private _Py_RefTotal variable.

The limited C API is supposed to provide a stable ABI, but Py_INCREF() leaks _Py_RefTotal implementation if Python is built in debug mode.

I propose to modify Py_INCREF() and Py_DECREF() of the limited C API to always declare them as opaque function calls. The regular (non limited) C API will continue to use the same static inline functions.

See also https://github.com/python/cpython/pull/25115 and bpo-41111 "[C API] Convert a few stdlib extensions to the limited C API (PEP 384)".

Note: Py_XINCREF() and Py_XDECREF() should be fine.
History
Date User Action Args
2021-04-01 06:47:31vstinnersetrecipients: + vstinner
2021-04-01 06:47:31vstinnersetmessageid: <1617259651.04.0.276896882913.issue43688@roundup.psfhosted.org>
2021-04-01 06:47:31vstinnerlinkissue43688 messages
2021-04-01 06:47:30vstinnercreate