diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 858eff5fc2..0e22573d20 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -227,6 +227,9 @@ BaseException_set_tb(PyBaseExceptionObject *self, PyObject *tb) "__traceback__ must be a traceback or None"); return -1; } + if ((PyObject *)self == PyExc_RecursionErrorInst) { + return 0; + } Py_INCREF(tb); Py_XSETREF(self->traceback, tb); @@ -324,6 +327,9 @@ PyException_GetCause(PyObject *self) { void PyException_SetCause(PyObject *self, PyObject *cause) { + if (self == PyExc_RecursionErrorInst) { + return; + } ((PyBaseExceptionObject *)self)->suppress_context = 1; Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause); } @@ -339,6 +345,9 @@ PyException_GetContext(PyObject *self) { void PyException_SetContext(PyObject *self, PyObject *context) { + if (self == PyExc_RecursionErrorInst) { + return; + } Py_XSETREF(((PyBaseExceptionObject *)self)->context, context); }