Skip to content
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

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

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 14, 2023

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).
@vstinner
Copy link
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

@vstinner
Copy link
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)

@vstinner
Copy link
Member Author

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

@vstinner vstinner closed this Jun 14, 2023
@vstinner vstinner deleted the incref_cpp branch June 14, 2023 02:35
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