FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[DRAFT] gh-105059: In C++, Py_INCREF() uses a function call by vstinner · Pull Request #105764 · python/cpython · GitHub

Repository navigation

[DRAFT] gh-105059: In C++, Py_INCREF() uses a function call - #105764

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:incref_cpp
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:incref_cpp

Conversation

vstinner commented Jun 14, 2023 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

In C++, Py_INCREF() and Py_DECREF() are now implemented as function calls. Moreover, in C++, PyObject.ob_refcnt type is just Py_ssize_t: don't use an anonymous union to avoid compiler warnings (anonymous unions were added to C11).

In C++, Py_INCREF() and Py_DECREF() are now implemented as function
calls. Moreover, in C++, PyObject.ob_refcnt type is just Py_ssize_t:
don't use an anonymous union to avoid compiler warnings (anonymous
unions were added to C11).

Copy link
Copy Markdown
Member Author

In the issue #105387, I modified Py_INCREF() and Py_DECREF() to implement them as opaque function calls in the limited C API version 3.12 and newer (and when Python is built in debug mode): commit b542972

We can consider to do something similar in C++ and/or in C without anonymous union (ex: ISO C89). This PR implements this idea for C++: in C++, PyObject.ob_refcnt type is again the simple Py_ssize_t, and Py_INCREF() and Py_DECREF() are implemented as function calls.

Well, I wrote this PR to show that we now have this technical solution, but it has a cost on performance. I don't know if it's acceptable for Python 3.12. Alternatives are discussed in issue #105059 and PR #105275.

cc @eduardo-elizondo

Copy link
Copy Markdown
Member Author

C without anonymous union (ex: ISO C89)

C compiler configured for C99 in pedantic mode also emits a compiler warning (which may be treated as error) in Include/object.h because of the PyObject.ob_refcnt anonymous union: #105059 (comment)

Copy link
Copy Markdown
Member Author

Abandoned in favor of PR #105767. C++ is unaffected by the issue: #105059 (comment)

vstinner closed this Jun 14, 2023
vstinner deleted the incref_cpp branch June 14, 2023 02:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

1 participant


Back | FazBrowse Home | New Git URL