Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
9 changes: 9 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,3 +1339,12 @@ def test_readline_history_file(self):
def test_keyboard_interrupt_after_isearch(self):
output, exit_code = self.run_repl(["\x12", "\x03", "exit"])
self.assertEqual(exit_code, 0)

def test_exit_code(self):
_, exit_code = self.run_repl(["exit(128)"])
self.assertEqual(exit_code, 128)

env = os.environ.copy()
env["PYTHON_BASIC_REPL"] = "1"
_, exit_code = self.run_repl(["exit(64)"], env=env)
self.assertEqual(exit_code, 64)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in PyREPL that caused :func:`exit` to always return 1.
1 change: 1 addition & 0 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pymain_err_print(int *exitcode_p)
int exitcode;
if (_Py_HandleSystemExit(&exitcode)) {
*exitcode_p = exitcode;
Py_Exit(exitcode);
Copy link
Member Author

@Eclips4 Eclips4 Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed in order to match behavior of PyRUn_AnyFileExFlags(which the old REPL called an still calls if PYTHON_BASIC_REPL=1) which somewhere calls handle_system_exit (Python/pythonrun.c::L632)) which handles SystemExit and calls Py_Exit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case this path doesn't return as this calls PyFinalize_Ex and then exit()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As well as previous approach with PyRun_AnyFileExFlags, so, is this a problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow what you mean. Could you clarify ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not being clear!
I mean, the previous approach with PyRun_AnyFileExFlags contains path with handle_system_exit which is also didn't return as it calls PyFinalizeEx and then exit().

return 1;
}

Expand Down
Loading