summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-07-03 05:04:23 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-07-03 05:04:23 (GMT)
commitf488fb422a641aa7c38eb63c09f459e4baff7bc4 (patch)
treef09d64f919af622c0ebf28adb9a3bfec567e47c8 /Objects
parent27be130ec71fa95e2496bd9e42505aa6c7457682 (diff)
downloadcpython-f488fb422a641aa7c38eb63c09f459e4baff7bc4.zip
cpython-f488fb422a641aa7c38eb63c09f459e4baff7bc4.tar.gz
cpython-f488fb422a641aa7c38eb63c09f459e4baff7bc4.tar.bz2
Issue #19235: Add new RecursionError exception. Patch by Georg Brandl.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/exceptions.c19
-rw-r--r--Objects/typeobject.c2
2 files changed, 14 insertions, 7 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index d494995..a275997 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -1231,6 +1231,11 @@ SimpleExtendsException(PyExc_Exception, EOFError,
SimpleExtendsException(PyExc_Exception, RuntimeError,
"Unspecified run-time error.");
+/*
+ * RecursionError extends RuntimeError
+ */
+SimpleExtendsException(PyExc_RuntimeError, RecursionError,
+ "Recursion limit exceeded.");
/*
* NotImplementedError extends RuntimeError
@@ -2380,7 +2385,7 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
-/* Pre-computed RuntimeError instance for when recursion depth is reached.
+/* Pre-computed RecursionError instance for when recursion depth is reached.
Meant to be used when normalizing the exception for exceeding the recursion
depth will cause its own infinite recursion.
*/
@@ -2484,6 +2489,7 @@ _PyExc_Init(PyObject *bltinmod)
PRE_INIT(OSError)
PRE_INIT(EOFError)
PRE_INIT(RuntimeError)
+ PRE_INIT(RecursionError)
PRE_INIT(NotImplementedError)
PRE_INIT(NameError)
PRE_INIT(UnboundLocalError)
@@ -2560,6 +2566,7 @@ _PyExc_Init(PyObject *bltinmod)
#endif
POST_INIT(EOFError)
POST_INIT(RuntimeError)
+ POST_INIT(RecursionError)
POST_INIT(NotImplementedError)
POST_INIT(NameError)
POST_INIT(UnboundLocalError)
@@ -2643,9 +2650,9 @@ _PyExc_Init(PyObject *bltinmod)
preallocate_memerrors();
if (!PyExc_RecursionErrorInst) {
- PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL);
+ PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RecursionError, NULL, NULL);
if (!PyExc_RecursionErrorInst)
- Py_FatalError("Cannot pre-allocate RuntimeError instance for "
+ Py_FatalError("Cannot pre-allocate RecursionError instance for "
"recursion errors");
else {
PyBaseExceptionObject *err_inst =
@@ -2654,15 +2661,15 @@ _PyExc_Init(PyObject *bltinmod)
PyObject *exc_message;
exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
if (!exc_message)
- Py_FatalError("cannot allocate argument for RuntimeError "
+ Py_FatalError("cannot allocate argument for RecursionError "
"pre-allocation");
args_tuple = PyTuple_Pack(1, exc_message);
if (!args_tuple)
- Py_FatalError("cannot allocate tuple for RuntimeError "
+ Py_FatalError("cannot allocate tuple for RecursionError "
"pre-allocation");
Py_DECREF(exc_message);
if (BaseException_init(err_inst, args_tuple, NULL))
- Py_FatalError("init of pre-allocated RuntimeError failed");
+ Py_FatalError("init of pre-allocated RecursionError failed");
Py_DECREF(args_tuple);
}
}
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 82c8710..1beed72 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4142,7 +4142,7 @@ reduce_newobj(PyObject *obj, int proto)
* were implemented in the same function:
* - trying to pickle an object with a custom __reduce__ method that
* fell back to object.__reduce__ in certain circumstances led to
- * infinite recursion at Python level and eventual RuntimeError.
+ * infinite recursion at Python level and eventual RecursionError.
* - Pickling objects that lied about their type by overwriting the
* __class__ descriptor could lead to infinite recursion at C level
* and eventual segfault.