diff options
author | xdegaye <xdegaye@gmail.com> | 2017-10-26 15:48:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-26 15:48:48 (GMT) |
commit | 4b27d51222be751125e6800453a39360a2dec11d (patch) | |
tree | c41987cae0bf6f909eb7fb0b454a8746912b2403 /Modules | |
parent | d94ef8fe94ed192a24a71117c07e6c7b60a8ac6c (diff) | |
download | cpython-4b27d51222be751125e6800453a39360a2dec11d.zip cpython-4b27d51222be751125e6800453a39360a2dec11d.tar.gz cpython-4b27d51222be751125e6800453a39360a2dec11d.tar.bz2 |
[3.6] bpo-30697: Fix PyErr_NormalizeException() when no memory (GH-2327). (#4135)
(cherry picked from commit 56d1f5ca32892c7643eb8cee49c40c1644f1abfe)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 00626cc..c2c63e9 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4862,6 +4862,61 @@ static PyTypeObject awaitType = { }; +static int recurse_infinitely_error_init(PyObject *, PyObject *, PyObject *); + +static PyTypeObject PyRecursingInfinitelyError_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "RecursingInfinitelyError", /* tp_name */ + sizeof(PyBaseExceptionObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + "Instantiating this exception starts infinite recursion.", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)recurse_infinitely_error_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ +}; + +static int +recurse_infinitely_error_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *type = (PyObject *)&PyRecursingInfinitelyError_Type; + + /* Instantiating this exception starts infinite recursion. */ + Py_INCREF(type); + PyErr_SetObject(type, NULL); + return -1; +} + + static struct PyModuleDef _testcapimodule = { PyModuleDef_HEAD_INIT, "_testcapi", @@ -4903,6 +4958,14 @@ PyInit__testcapi(void) Py_INCREF(&awaitType); PyModule_AddObject(m, "awaitType", (PyObject *)&awaitType); + PyRecursingInfinitelyError_Type.tp_base = (PyTypeObject *)PyExc_Exception; + if (PyType_Ready(&PyRecursingInfinitelyError_Type) < 0) { + return NULL; + } + Py_INCREF(&PyRecursingInfinitelyError_Type); + PyModule_AddObject(m, "RecursingInfinitelyError", + (PyObject *)&PyRecursingInfinitelyError_Type); + PyModule_AddObject(m, "CHAR_MAX", PyLong_FromLong(CHAR_MAX)); PyModule_AddObject(m, "CHAR_MIN", PyLong_FromLong(CHAR_MIN)); PyModule_AddObject(m, "UCHAR_MAX", PyLong_FromLong(UCHAR_MAX)); |