Skip to content

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

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

Merged
merged 1 commit into from
Jun 3, 2021
Merged

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

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 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 commented Jun 2, 2021

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

@vstinner
Copy link
Member Author

vstinner commented Jun 3, 2021

The previous attempt (reverted change) was: #20290

@vstinner vstinner merged commit f3fa63e into python:main Jun 3, 2021
@vstinner vstinner deleted the py_type branch June 3, 2021 16:43
@vstinner
Copy link
Member Author

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.

pablogsal added a commit to pablogsal/cpython that referenced this pull request Jun 8, 2021
pythonGH-26493)"

This reverts commit f3fa63e as is
causing crashes in some Windows tests in the buildbots.
pablogsal added a commit that referenced this pull request Jun 8, 2021
GH-26493)" (GH-26596)

This reverts commit f3fa63e as is
causing crashes in some Windows tests in the buildbots.
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.

3 participants