Skip to content

Commit bb790af

Browse files
committed
fix: in TraceRefs it will return fatal error
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
1 parent 52310f0 commit bb790af

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Lib/test/test_repl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@ def test_exec_set_nomemory_hang(self):
120120
p.stdin.write(user_input)
121121
output = kill_python(p)
122122

123-
self.assertIn(p.returncode, (0, 1, 120))
123+
# it can exit with MemoryError or Fatal Python error when --with-trace-refs
124+
# it return -6 here
125+
self.assertIn(p.returncode, (0, 1, 120, -6))
124126
self.assertGreater(len(output), 0) # At minimum, should not hang
125-
self.assertIn("MemoryError", output)
127+
# Can result in either MemoryError exception or fatal error
128+
self.assertTrue("MemoryError" in output or "Fatal Python error" in output)
126129

127130
@cpython_only
128131
def test_multiline_string_parsing(self):

Python/ceval.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,13 +912,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
912912
int frame_lasti = _PyInterpreterFrame_LASTI(frame);
913913
PyObject *lasti = PyLong_FromLong(frame_lasti);
914914
if (lasti == NULL) {
915-
// gh-134163: If we can't allocate memory for lasti during exception handling,
916-
// this likely means we're in a severe memory shortage situation.
917-
if (!_PyErr_Occurred(tstate)) {
918-
// PyLong_FromLong should have set an exception
919-
// like _testcapi.set_nomemory(0), it might not. Ensure one is set.
920-
PyErr_NoMemory();
921-
}
922915
// Instead of going back to exception_unwind (which would cause
923916
// infinite recursion), directly exit to let the original exception
924917
// propagate up and hopefully be handled at a higher level.

0 commit comments

Comments
 (0)