(PyExc_MemoryErrorInst) raise this instead of PyExc_MemoryError. This
only happens when exception classes are enabled (e.g. when Python is
started with -X).
PyObject *
PyErr_NoMemory()
{
- PyErr_SetNone(PyExc_MemoryError);
+ /* raise the pre-allocated instance if it still exists */
+ if (PyExc_MemoryErrorInst)
+ PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst);
+ else
+ /* this will probably fail since there's no memory and hee,
+ hee, we have to instantiate this class
+ */
+ PyErr_SetNone(PyExc_MemoryError);
+
return NULL;
}