Skip to content

Commit d3f03fa

Browse files
committed
PyErr_NormalizeException may not set an error, so convert the PyErr_SetObject
call on hitting the recursion limit into just assigning it to the arguments provided.
1 parent dd98e04 commit d3f03fa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15+
- Fix a problem in PyErr_NormalizeException that leads to "undetected errors"
16+
when hitting the recursion limit under certain circumstances.
17+
1518
- Issue #1665206: Remove the last eager import in _warnings.c and make it lazy.
1619

1720
- Issue #4865: On MacOSX /Library/Python/2.7/site-packages is added to

Python/errors.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,15 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
225225
tstate = PyThreadState_GET();
226226
if (++tstate->recursion_depth > Py_GetRecursionLimit()) {
227227
--tstate->recursion_depth;
228-
PyErr_SetObject(PyExc_RuntimeError, PyExc_RecursionErrorInst);
228+
/* throw away the old exception... */
229+
Py_DECREF(*exc);
230+
Py_DECREF(*val);
231+
/* ... and use the recursion error instead */
232+
*exc = PyExc_RuntimeError;
233+
*val = PyExc_RecursionErrorInst;
234+
Py_INCREF(*exc);
235+
Py_INCREF(*val);
236+
/* just keeping the old traceback */
229237
return;
230238
}
231239
PyErr_NormalizeException(exc, val, tb);

0 commit comments

Comments
 (0)