aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/crossinterp.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2025-05-05 17:25:26 -0600
committerGitHub <noreply@github.com>2025-05-05 17:25:26 -0600
commite9616110aaecfbe5ec479fe6cf10aad6a68c0ccc (patch)
tree846d9c2b020c149ea72253d4a27d15d0e502bfbb /Python/crossinterp.c
parent60cdd800d95517f4395210f38709de9e8f11ea90 (diff)
downloadcpython-e9616110aaecfbe5ec479fe6cf10aad6a68c0ccc.tar.gz
cpython-e9616110aaecfbe5ec479fe6cf10aad6a68c0ccc.zip
gh-132775: Do Not Set __name__ to __main__ With _PyPickle_GetXIData() (gh-133472)
This is a follow-up to gh-133107. I realized that we could end up with an infinite recursion if we try to run a function from __main__ in a subinterpreter.
Diffstat (limited to 'Python/crossinterp.c')
-rw-r--r--Python/crossinterp.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index a9f9b785629..74ce02f1a26 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -512,9 +512,12 @@ _unpickle_context_set_module(struct _unpickle_context *ctx,
struct sync_module_result res = {0};
struct sync_module_result *cached = NULL;
const char *filename = NULL;
+ const char *run_modname = modname;
if (strcmp(modname, "__main__") == 0) {
cached = &ctx->main.cached;
filename = ctx->main.filename;
+ // We don't want to trigger "if __name__ == '__main__':".
+ run_modname = "<fake __main__>";
}
else {
res.failed = PyExc_NotImplementedError;
@@ -533,7 +536,7 @@ _unpickle_context_set_module(struct _unpickle_context *ctx,
res.failed = PyExc_NotImplementedError;
goto finally;
}
- res.loaded = runpy_run_path(filename, modname);
+ res.loaded = runpy_run_path(filename, run_modname);
if (res.loaded == NULL) {
Py_CLEAR(res.module);
res.failed = _PyErr_GetRaisedException(ctx->tstate);