Raise an error when importing modules compiled for an older Python#139
Open
befeleme wants to merge 1 commit intofedora-python:fedora-3.14from
Open
Raise an error when importing modules compiled for an older Python#139befeleme wants to merge 1 commit intofedora-python:fedora-3.14from
befeleme wants to merge 1 commit intofedora-python:fedora-3.14from
Conversation
28a5464 to
9dc0ede
Compare
hroncok
reviewed
Feb 6, 2026
hroncok
reviewed
Feb 6, 2026
hroncok
reviewed
Feb 6, 2026
Member
|
This is a downstream workaround "implementing" python#137212 - the mechanism for the check exists in Python 3.15+, where it needs to be added to the standard library modules. In Fedora, we need it also in previous Python versions, as we experience segmentation fault when importing stdlib modules after update while Python is running. _tkinter, _tracemalloc and readline are not calling PyModuleDef_Init, which is modified with this patch, hence they need a direct call to the check function.
9dc0ede to
0505ac8
Compare
Author
|
TODO: patch for 3.13 |
vstinner
reviewed
Feb 6, 2026
Include/moduleobject.h
Outdated
Comment on lines
120
to
122
| /* Workaround for https://github.com/python/cpython/issues/128341 | ||
| * This occurred again with the update from 3.14.2 to 3.14.3. | ||
| * Instead of a segmentation fault, meaningful error is raised. |
There was a problem hiding this comment.
Suggested change
| /* Workaround for https://github.com/python/cpython/issues/128341 | |
| * This occurred again with the update from 3.14.2 to 3.14.3. | |
| * Instead of a segmentation fault, meaningful error is raised. | |
| /* Workaround for https://github.com/python/cpython/issues/128341. | |
| * This occurred again with the update from 3.14.2 to 3.14.3. | |
| * Instead of a segmentation fault, meaningful error is raised. |
| # End: | ||
|
|
||
| # Fedora-specific, downstream only | ||
| CFLAGS += -D_PyHack_check_version_on_modinit=1 |
There was a problem hiding this comment.
You should use PY_STDMODULE_CFLAGS to not leak the flag to flags used to build 3rd party extension (setuptools & cie).
Suggested change
| CFLAGS += -D_PyHack_check_version_on_modinit=1 | |
| PY_STDMODULE_CFLAGS += -D_PyHack_check_version_on_modinit=1 |
| PyErr_Format( | ||
| PyExc_ImportError, | ||
| "internal Python C API version mismatch: " | ||
| "module %s compiled with %lu.%lu.%lu; runtime version is %lu.%lu.%lu", |
There was a problem hiding this comment.
Suggested change
| "module %s compiled with %lu.%lu.%lu; runtime version is %lu.%lu.%lu", | |
| "module %s compiled with %lu.%lu.%lu; " | |
| "runtime version is %lu.%lu.%lu", |
| (const unsigned long)((PY_VERSION_HEX >> 8) & 0xFF), | ||
| (const unsigned long)((Py_Version >> 24) & 0xFF), | ||
| (const unsigned long)((Py_Version >> 16) & 0xFF), | ||
| (const unsigned long)((Py_Version >> 8) & 0xFF) |
There was a problem hiding this comment.
The format major.minor.micro lacks PY_RELEASE_LEVEL and PY_RELEASE_SERIAL which is need to distinguish two alpha releases. But since this change is only for Python 3.14, it's fine to fine the release level/serial (we don't ship 3.14 alpha releases anymore).
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
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.
This is a downstream workaround for
python#128341 -
it is resolved for Python 3.15+, but the issue happened again in the update from 3.14.2 to 3.14.3 (segfault when importing _pickle).