Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d8adff

Browse files
committed
PyErr_NoMemory(): If the pre-instantiated memory exception is non-null
(PyExc_MemoryErrorInst) raise this instead of PyExc_MemoryError. This only happens when exception classes are enabled (e.g. when Python is started with -X).
1 parent dd82bb9 commit 2d8adff

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Python/errors.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,15 @@ PyErr_BadArgument()
256256
PyObject *
257257
PyErr_NoMemory()
258258
{
259-
PyErr_SetNone(PyExc_MemoryError);
259+
/* raise the pre-allocated instance if it still exists */
260+
if (PyExc_MemoryErrorInst)
261+
PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst);
262+
else
263+
/* this will probably fail since there's no memory and hee,
264+
hee, we have to instantiate this class
265+
*/
266+
PyErr_SetNone(PyExc_MemoryError);
267+
260268
return NULL;
261269
}
262270

0 commit comments

Comments
 (0)