Blame SOURCES/00292-restore-PyExc_RecursionErrorInst-symbol.patch

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