gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API by vstinner · Pull Request #111508 · python/cpython · GitHub
Skip to content

gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API - #111508

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:py_setrefcnt
Nov 3, 2023
Merged

gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API#111508
vstinner merged 1 commit into
python:mainfrom
vstinner:py_setrefcnt

Conversation

@vstinner

@vstinner vstinner commented Oct 30, 2023

Copy link
Copy Markdown
Member

In the limited C API version 3.13, Py_SET_REFCNT() function is now implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.

…ted C API

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
@vstinner
vstinner requested a review from a team as a code owner October 30, 2023 17:23
@encukou

encukou commented Oct 31, 2023

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
Member Author

Why is this particular function necessary?

It's needed to be able to remove non-portable assembly code from Include/*.h. I would prefer to keep these header files as simple C code, no inline assembly.

The code was just change for free threading. This change follows Py_INCREF/DECREF which already use an opaque function call in limited C API version 3.12.

@vstinner

Copy link
Copy Markdown
Member Author

I'd rather not commit to supporting setting the reference count to an arbitrary value in the long term.

I also have concerns about that. But this change is a practical change to make the situation less bad.

I plan to work on a whole PEP to disallow accessing directly PyObject.ob_refcnt and convert more functions to opaque function calls in the limited C API, as Sam describes in the issue.

@vstinner

vstinner commented Nov 3, 2023

Copy link
Copy Markdown
Member Author

@colesbury @serhiy-storchaka @erlend-aasland: Would you mind to review this change?

@erlend-aasland

Copy link
Copy Markdown
Contributor

I'll leave this to @colesbury.

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

I think this only improves our compatibility story going forward. We have already committed to this functionality as part of the API and ABI. Using an opaque function instead of an inline function does not change this.

@encukou

encukou commented Nov 3, 2023

Copy link
Copy Markdown
Member

+1 API-wise -- keeping it abi_only is the way to go.

@vstinner
vstinner merged commit 20cfab9 into python:main Nov 3, 2023
@vstinner
vstinner deleted the py_setrefcnt branch November 3, 2023 17:18
@vstinner

vstinner commented Nov 3, 2023

Copy link
Copy Markdown
Member Author

Merged, thanks for reviews.

@bedevere-bot

Copy link
Copy Markdown

aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…ted C API (python#111508)

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…ted C API (python#111508)

In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.

Add _Py_SetRefcnt() to the stable ABI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants