-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-43688: Support the limited C API in debug mode #25131
Conversation
Include/object.h
Outdated
static inline void _Py_INCREF(PyObject *op) | ||
{ | ||
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030A0000 || defined(Py_REF_DEBUG)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to make Py_INCREF() opaque for Python 3.9 and older, but we cannot magically add _Py_IncRef() to old Python versions :-(
cc @encukou |
I merged the uncontroversial part in separated commits in https://bugs.python.org/issue43688 I rebased my PR on top on merged changes. |
self.add(Extension('xxlimited', ['xxlimited.c'], | ||
define_macros=[('Py_LIMITED_API', '0x030a0000')])) | ||
self.add(Extension('xxlimited_35', ['xxlimited_35.c'], | ||
define_macros=[('Py_LIMITED_API', '0x03050000')])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I found Py_LIMITED_API=0x03060000
in https://github.com/python/cpython/blob/master/PCbuild/xxlimited_35.vcxproj#L97.
I am not sure which one is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module name says "35": Python 3.5. See the C file header:
/* This module is compiled using limited API from Python 3.5,
* making sure that it works as expected.
*
* See the xxlimited module for an extension module template.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's a good reason to put the define into the C file directly, rather than putting it in the recipe to build the file :-D
The limited C API is now supported if Python is built in debug mode (if the Py_DEBUG macro is defined). In the limited C API, the Py_INCREF() and Py_DECREF() functions are now implemented as opaque function calls, rather than accessing directly the PyObject.ob_refcnt member, if Python is built in debug mode and the Py_LIMITED_API macro targets Python 3.10 or newer. It became possible to support the limited C API in debug mode because the PyObject structure is the same in release and debug mode since Python 3.8 (see bpo-36465). The limited C API is still not supported in the --with-trace-refs special build (Py_TRACE_REFS macro).
Windows x86: test_asyncio failed. |
I re-run the CI jobs. |
The limited C API is now supported if Python is built in debug mode
(if the Py_DEBUG macro is defined). In the limited C API, the
Py_INCREF() and Py_DECREF() functions are now implemented as opaque
function calls, rather than accessing directly the PyObject.ob_refcnt
member, if Python is built in debug mode and the Py_LIMITED_API macro
targets Python 3.10 or newer. It became possible to support the
limited C API in debug mode because the PyObject structure is the
same in release and debug mode since Python 3.8 (see bpo-36465).
The limited C API is still not supported in the --with-trace-refs
special build (Py_TRACE_REFS macro).
https://bugs.python.org/issue43688