Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite961611

Browse files
gh-132775: Do Not Set __name__ to __main__ With _PyPickle_GetXIData() (gh-133472)
This is a follow-up togh-133107. I realized that we could end up with aninfinite recursion if we try to run a function from __main__ in a subinterpreter.
1 parent60cdd80 commite961611

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎Python/crossinterp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,12 @@ _unpickle_context_set_module(struct _unpickle_context *ctx,
512512
structsync_module_resultres= {0};
513513
structsync_module_result*cached=NULL;
514514
constchar*filename=NULL;
515+
constchar*run_modname=modname;
515516
if (strcmp(modname,"__main__")==0) {
516517
cached=&ctx->main.cached;
517518
filename=ctx->main.filename;
519+
// We don't want to trigger "if __name__ == '__main__':".
520+
run_modname="<fake __main__>";
518521
}
519522
else {
520523
res.failed=PyExc_NotImplementedError;
@@ -533,7 +536,7 @@ _unpickle_context_set_module(struct _unpickle_context *ctx,
533536
res.failed=PyExc_NotImplementedError;
534537
gotofinally;
535538
}
536-
res.loaded=runpy_run_path(filename,modname);
539+
res.loaded=runpy_run_path(filename,run_modname);
537540
if (res.loaded==NULL) {
538541
Py_CLEAR(res.module);
539542
res.failed=_PyErr_GetRaisedException(ctx->tstate);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp