Skip to content

Commit 81c6244

Browse files
committed
fix: exec('_testcapi.set_nomemory(0)') hang in new repl 3.13
Signed-off-by: yihong0618 <[email protected]>
1 parent 837df27 commit 81c6244

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Python/ceval.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,14 @@ _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-
goto exception_unwind;
915+
// gh-134163
916+
// If we can't allocate memory for lasti during exception handling,
917+
// this likely means we're in a severe memory shortage situation.
918+
// Instead of going back to exception_unwind (which would cause
919+
// infinite recursion), directly exit to let the original exception
920+
// propagate up and hopefully be handled at a higher level.
921+
_PyFrame_SetStackPointer(frame, stack_pointer);
922+
goto exit_unwind;
916923
}
917924
PUSH(lasti);
918925
}

0 commit comments

Comments
 (0)