-
Notifications
You must be signed in to change notification settings - Fork 2
Raise an error when importing modules compiled for an older Python #139
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
base: fedora-3.14
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,48 @@ struct PyModuleDef { | |
| freefunc m_free; | ||
| }; | ||
|
|
||
| #if defined(_PyHack_check_version_on_modinit) && defined(Py_BUILD_CORE) | ||
| /* The mechanism for the check has been implemented on Python 3.15+: | ||
| * https://github.com/python/cpython/pull/137212 | ||
| * In Fedora, we need this in older Pythons too: | ||
| * if somebody attempts to import a module compiled for a different Python version, | ||
| * instead of segmentation fault a meaningful error is raised. | ||
| */ | ||
| PyAPI_DATA(const unsigned long) Py_Version; | ||
|
|
||
| static inline int | ||
| _PyHack_CheckInternalAPIVersion(const char *mod_name) | ||
| { | ||
| if (PY_VERSION_HEX != Py_Version) { | ||
| PyErr_Format( | ||
| PyExc_ImportError, | ||
| "internal Python C API version mismatch: " | ||
| "module %s compiled with %lu.%lu.%lu; runtime version is %lu.%lu.%lu", | ||
| mod_name, | ||
| (const unsigned long)((PY_VERSION_HEX >> 24) & 0xFF), | ||
| (const unsigned long)((PY_VERSION_HEX >> 16) & 0xFF), | ||
| (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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The format |
||
| ); | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| static inline PyObject * | ||
| PyModuleDef_Init_with_check(PyModuleDef *def) | ||
| { | ||
| if (_PyHack_CheckInternalAPIVersion(def->m_name) < 0) { | ||
| return NULL; | ||
| } | ||
| return PyModuleDef_Init(def); | ||
| } | ||
|
|
||
| #define PyModuleDef_Init PyModuleDef_Init_with_check | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3415,3 +3415,6 @@ MODULE__MULTIBYTECODEC_DEPS=$(srcdir)/Modules/cjkcodecs/multibytecodec.h | |||||
| # Local Variables: | ||||||
| # mode: makefile | ||||||
| # End: | ||||||
|
|
||||||
| # Fedora-specific, downstream only | ||||||
| CFLAGS += -D_PyHack_check_version_on_modinit=1 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use
Suggested change
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.