GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [DRAFT] gh-105059: In C++, Py_INCREF() uses a function call by vstinner · Pull Request #105764 · python/cpython

Conversation

@vstinner

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

Uh oh!

There was an error while loading. Please reload this page.

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).

  • Issue: object.h uses an anonymous union in a struct (older C incompatible) #105059

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot mentioned this pull request Jun 14, 2023
object.h uses an anonymous union in a struct (older C incompatible) #105059
Closed
@vstinner
pythongh-105059: In C++, Py_INCREF() uses a function call
2d6d57a
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
vstinner force-pushed the incref_cpp branch from 7cb779e to 2d6d57a Compare June 14, 2023 00:55
@vstinner

vstinner commented Jun 14, 2023

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 14, 2023

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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Jun 14, 2023

Copy link
Copy Markdown
Member Author

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

eduardo-elizondo reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.