From: Daniel Li Date: Fri, 23 May 2025 18:45:45 +0000 (-0400) Subject: gh-120170: Exclude __mp_main__ in C version of whichmodule() (#120171) X-Git-Tag: v3.15.0a1~1545 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05a19b5e56894fd1e63aff6b38fb23ad7c7b3047;p=thirdparty%2FPython%2Fcpython.git gh-120170: Exclude __mp_main__ in C version of whichmodule() (#120171) Co-authored-by: Lysandros Nikolaou --- diff --git a/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst b/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst new file mode 100644 index 000000000000..ce7d874aa203 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-06-06-17-49-07.gh-issue-120170.DUxhmT.rst @@ -0,0 +1,3 @@ +Fix an issue in the :mod:`!_pickle` extension module in which importing +:mod:`multiprocessing` could change how pickle identifies which module an +object belongs to, potentially breaking the unpickling of those objects. diff --git a/Modules/_pickle.c b/Modules/_pickle.c index d260f1a68f8c..29ef0cb0c2e0 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1879,6 +1879,10 @@ _checkmodule(PyObject *module_name, PyObject *module, _PyUnicode_EqualToASCIIString(module_name, "__main__")) { return -1; } + if (PyUnicode_Check(module_name) && + _PyUnicode_EqualToASCIIString(module_name, "__mp_main__")) { + return -1; + } PyObject *candidate = getattribute(module, dotted_path, 0); if (candidate == NULL) {