Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-43688: Support the limited C API in debug mode#25131

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:masterfromvstinner:ref_debug
Apr 2, 2021
Merged

bpo-43688: Support the limited C API in debug mode#25131

vstinner merged 1 commit intopython:masterfromvstinner:ref_debug
Apr 2, 2021

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedApr 1, 2021
edited by bedevere-bot
Loading

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 (seebpo-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

static inline void _Py_INCREF(PyObject *op)
{
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030A0000 || defined(Py_REF_DEBUG))
Copy link
MemberAuthor

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 :-(

shihai1991 reacted with laugh emoji
@vstinner
Copy link
MemberAuthor

cc@encukou

@vstinner
Copy link
MemberAuthor

I merged the uncontroversial part in separated commits inhttps://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')]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hm, I foundPy_LIMITED_API=0x03060000 inhttps://github.com/python/cpython/blob/master/PCbuild/xxlimited_35.vcxproj#L97.

I am not sure which one is right.

Copy link
MemberAuthor

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. */

Copy link
MemberAuthor

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

shihai1991 reacted with laugh emoji
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, thePy_INCREF() and Py_DECREF() functions are now implemented as opaquefunction calls, rather than accessing directly the PyObject.ob_refcntmember, if Python is built in debug mode and the Py_LIMITED_API macrotargets Python 3.10 or newer. It became possible to support thelimited C API in debug mode because the PyObject structure is thesame in release and debug mode since Python 3.8 (seebpo-36465).The limited C API is still not supported in the --with-trace-refsspecial build (Py_TRACE_REFS macro).
@vstinner
Copy link
MemberAuthor

Windows x86: test_asyncio failed.

@vstinner
Copy link
MemberAuthor

I re-run the CI jobs.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@shihai1991shihai1991shihai1991 left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@vstinner@shihai1991@the-knights-who-say-ni@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp