|
|
dd3773 |
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
|
|
|
dd3773 |
index c28c1373f82..8c1dbc5047b 100644
|
|
|
dd3773 |
--- a/Include/pyerrors.h
|
|
|
dd3773 |
+++ b/Include/pyerrors.h
|
|
|
dd3773 |
@@ -219,6 +219,8 @@ PyAPI_DATA(PyObject *) PyExc_IOError;
|
|
|
dd3773 |
PyAPI_DATA(PyObject *) PyExc_WindowsError;
|
|
|
dd3773 |
#endif
|
|
|
dd3773 |
|
|
|
dd3773 |
+PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
|
|
|
dd3773 |
+
|
|
|
dd3773 |
/* Predefined warning categories */
|
|
|
dd3773 |
PyAPI_DATA(PyObject *) PyExc_Warning;
|
|
|
dd3773 |
PyAPI_DATA(PyObject *) PyExc_UserWarning;
|
|
|
dd3773 |
diff --git a/Misc/NEWS.d/next/C API/2017-12-20-15-23-06.bpo-30697.v9FmgG.rst b/Misc/NEWS.d/next/C API/2017-12-20-15-23-06.bpo-30697.v9FmgG.rst
|
|
|
dd3773 |
new file mode 100644
|
|
|
dd3773 |
index 00000000000..28f74ad4f30
|
|
|
dd3773 |
--- /dev/null
|
|
|
dd3773 |
+++ b/Misc/NEWS.d/next/C API/2017-12-20-15-23-06.bpo-30697.v9FmgG.rst
|
|
|
dd3773 |
@@ -0,0 +1 @@
|
|
|
dd3773 |
+Restore PyExc_RecursionErrorInst in 3.6
|
|
|
dd3773 |
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
|
|
|
dd3773 |
index df4899372a5..271e293e325 100644
|
|
|
dd3773 |
--- a/Objects/exceptions.c
|
|
|
dd3773 |
+++ b/Objects/exceptions.c
|
|
|
dd3773 |
@@ -2430,6 +2430,12 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
|
|
|
dd3773 |
|
|
|
dd3773 |
|
|
|
dd3773 |
|
|
|
dd3773 |
+/* Pre-computed RecursionError instance for when recursion depth is reached.
|
|
|
dd3773 |
+ Meant to be used when normalizing the exception for exceeding the recursion
|
|
|
dd3773 |
+ depth will cause its own infinite recursion.
|
|
|
dd3773 |
+*/
|
|
|
dd3773 |
+PyObject *PyExc_RecursionErrorInst = NULL;
|
|
|
dd3773 |
+
|
|
|
dd3773 |
#define PRE_INIT(TYPE) \
|
|
|
dd3773 |
if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
|
|
|
dd3773 |
if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \
|
|
|
dd3773 |
@@ -2691,11 +2697,37 @@ _PyExc_Init(PyObject *bltinmod)
|
|
|
dd3773 |
ADD_ERRNO(TimeoutError, ETIMEDOUT);
|
|
|
dd3773 |
|
|
|
dd3773 |
preallocate_memerrors();
|
|
|
dd3773 |
+
|
|
|
dd3773 |
+ if (!PyExc_RecursionErrorInst) {
|
|
|
dd3773 |
+ PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RecursionError, NULL, NULL);
|
|
|
dd3773 |
+ if (!PyExc_RecursionErrorInst)
|
|
|
dd3773 |
+ Py_FatalError("Cannot pre-allocate RecursionError instance for "
|
|
|
dd3773 |
+ "recursion errors");
|
|
|
dd3773 |
+ else {
|
|
|
dd3773 |
+ PyBaseExceptionObject *err_inst =
|
|
|
dd3773 |
+ (PyBaseExceptionObject *)PyExc_RecursionErrorInst;
|
|
|
dd3773 |
+ PyObject *args_tuple;
|
|
|
dd3773 |
+ PyObject *exc_message;
|
|
|
dd3773 |
+ exc_message = PyUnicode_FromString("maximum recursion depth exceeded");
|
|
|
dd3773 |
+ if (!exc_message)
|
|
|
dd3773 |
+ Py_FatalError("cannot allocate argument for RecursionError "
|
|
|
dd3773 |
+ "pre-allocation");
|
|
|
dd3773 |
+ args_tuple = PyTuple_Pack(1, exc_message);
|
|
|
dd3773 |
+ if (!args_tuple)
|
|
|
dd3773 |
+ Py_FatalError("cannot allocate tuple for RecursionError "
|
|
|
dd3773 |
+ "pre-allocation");
|
|
|
dd3773 |
+ Py_DECREF(exc_message);
|
|
|
dd3773 |
+ if (BaseException_init(err_inst, args_tuple, NULL))
|
|
|
dd3773 |
+ Py_FatalError("init of pre-allocated RecursionError failed");
|
|
|
dd3773 |
+ Py_DECREF(args_tuple);
|
|
|
dd3773 |
+ }
|
|
|
dd3773 |
+ }
|
|
|
dd3773 |
}
|
|
|
dd3773 |
|
|
|
dd3773 |
void
|
|
|
dd3773 |
_PyExc_Fini(void)
|
|
|
dd3773 |
{
|
|
|
dd3773 |
+ Py_CLEAR(PyExc_RecursionErrorInst);
|
|
|
dd3773 |
free_preallocated_memerrors();
|
|
|
dd3773 |
Py_CLEAR(errnomap);
|
|
|
dd3773 |
}
|
|
|
dd3773 |
diff --git a/PC/python3.def b/PC/python3.def
|
|
|
dd3773 |
index 4fc4a6814ee..ff70718fc37 100644
|
|
|
dd3773 |
--- a/PC/python3.def
|
|
|
dd3773 |
+++ b/PC/python3.def
|
|
|
dd3773 |
@@ -224,6 +224,7 @@ EXPORTS
|
|
|
dd3773 |
PyExc_PermissionError=python36.PyExc_PermissionError DATA
|
|
|
dd3773 |
PyExc_ProcessLookupError=python36.PyExc_ProcessLookupError DATA
|
|
|
dd3773 |
PyExc_RecursionError=python36.PyExc_RecursionError DATA
|
|
|
dd3773 |
+ PyExc_RecursionErrorInst=python36.PyExc_RecursionErrorInst DATA
|
|
|
dd3773 |
PyExc_ReferenceError=python36.PyExc_ReferenceError DATA
|
|
|
dd3773 |
PyExc_ResourceWarning=python36.PyExc_ResourceWarning DATA
|
|
|
dd3773 |
PyExc_RuntimeError=python36.PyExc_RuntimeError DATA
|