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

bpo-39573: Py_TYPE becomes a static inline function #26493

Merged
merged 1 commit into from Jun 3, 2021

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jun 2, 2021

Convert the Py_TYPE() and Py_SIZE() macros to static inline
functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be
used to set an object type and size.

https://bugs.python.org/issue39573

Convert the Py_TYPE() and Py_SIZE() macros to static inline
functions. The Py_SET_TYPE() and Py_SET_SIZE() functions must now be
used to set an object type and size.
@vstinner
Copy link
Member Author

@vstinner vstinner commented Jun 2, 2021

One year ago, I already pushed the same change to Python 3.10, but it broke many projects and so had to be reverted, see: https://bugs.python.org/issue39573#msg370074

Multiple things changed since my latest attempt:

  • Major projects like Cython and numpy have been prepared for this incompatible change

  • I created the https://github.com/pythoncapi/pythoncapi_compat project which is made of two parts:

    • pythoncapi_compat.h header file provides Py_SET_TYPE() and Py_SET_TYPE() to old Python versions: it supports Python 2.7-3.11.
    • upgrade_pythoncapi.py script automates the migration of existing C extensions to the new API (Py_SET_TYPE, Py_SET_TYPE) without losing support with Python 2.7-3.8.
  • pythoncapi_compat.h header and upgrade_pythoncapi.py script have been used successfully on multiple projects (bitarray, immutables, Mercurial, python-zstandard). These projects now include a copy of pythoncapi_compat.h to support old Python versions.

Note: C extensions implemented with Cython only have to regenerate the C files using Cython, if it's not already done (Cython was fixed one year ago).

@vstinner
Copy link
Member Author

@vstinner vstinner commented Jun 2, 2021

More info about the pythoncapi_compat project: https://vstinner.github.io/pythoncapi_compat.html

@vstinner
Copy link
Member Author

@vstinner vstinner commented Jun 3, 2021

The previous attempt (reverted change) was: #20290

@vstinner vstinner merged commit f3fa63e into python:main Jun 3, 2021
12 checks passed
12 checks passed
@github-actions
Docs
Details
@github-actions
Check for source changes
Details
@github-actions
Check if generated files are up to date
Details
@github-actions
Windows (x86)
Details
@github-actions
Windows (x64)
Details
@github-actions
macOS
Details
@github-actions
Ubuntu
Details
@github-actions
Ubuntu SSL tests with OpenSSL
Details
Azure Pipelines PR #20210602.39 succeeded
Details
@travis-ci
Travis CI - Pull Request Build Passed
Details
@bedevere-bot
bedevere/issue-number Issue number 39573 found
Details
@bedevere-bot
bedevere/news News entry found in Misc/NEWS.d
@vstinner vstinner deleted the vstinner:py_type branch Jun 3, 2021
@vstinner
Copy link
Member Author

@vstinner vstinner commented Jun 3, 2021

I prefer to merge such incompatible change early in 3.11 dev cycle to give more test to users to test it. If things go wild again, we can consider to revert it a second time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants