gh-152132: Handle sys.exit() in Py_RunMain command and file paths#152191
Open
tangyuan0821 wants to merge 3 commits into
Open
gh-152132: Handle sys.exit() in Py_RunMain command and file paths#152191tangyuan0821 wants to merge 3 commits into
tangyuan0821 wants to merge 3 commits into
Conversation
Two issues introduced by the Py_RunMain SystemExit fix: 1. pymain_run_command lost traceback source lines for -c commands because PyRun_StringFlags does not register source in linecache. Add _PyRun_SimpleStringFlagsEx, which returns PyObject* without calling PyErr_Print(), and use it in pymain_run_command with the "<string>" name so source linecache registration is preserved. 2. _PyRun_SimpleFileObjectEx could lose exceptions during cleanup when PyDict_PopString fails (e.g. under low-memory conditions). Save and restore the original exception around cleanup code when the main code failed; use PyErr_Print() for cleanup errors when the main code succeeded to match legacy behavior.
ZeroIntensity
left a comment
Member
There was a problem hiding this comment.
Please add a test case.
Comment on lines
+415
to
+416
| PyObject *v = _PyRun_SimpleFileObjectEx(fp, filename, 1, &cf); | ||
| if (v == NULL) { |
Member
There was a problem hiding this comment.
Please don't use single-letter variable names.
Comment on lines
+545
to
+547
| PyObject * | ||
| _PyRun_SimpleFileObjectEx(FILE *fp, PyObject *filename, int closeit, | ||
| PyCompilerFlags *flags) |
Member
There was a problem hiding this comment.
- This is not a good name -- the
Exsuffix existing in CPython is a historical artifact that we try to avoid these days. - Most of this function is copied exactly from
_PyRun_SimpleFileObject. Rather than duplicating the logic, let's factor this out into a common helper function.
Comment on lines
+674
to
+675
| PyObject * | ||
| _PyRun_SimpleStringFlagsEx(const char *command, const char* name, PyCompilerFlags *flags) |
Member
There was a problem hiding this comment.
Same comments as _PyRun_SimpleFileObjectEx.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Switch to low-level APIs so SystemExit goes through pymain_exit_err_print() instead of exit().