Skip to content

gh-132775: Do Not Set __name__ to __main__ With _PyPickle_GetXIData() #133472

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Loading