[Python-Dev] PyErr_NoMemory
Vladimir Marangozov
Vladimir.Marangozov@inrialpes.fr
Thu, 17 Aug 2000 17:09:44 +0200 (CEST)
The current PyErr_NoMemory() function reads:
PyObject *
PyErr_NoMemory(void)
{
/* 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;
}
thus overriding any previous exceptions unconditionally. This is a
problem when the current exception already *is* PyExc_MemoryError,
notably when we have a chain (cascade) of memory errors. It is a
problem because the original memory error and eventually its error
message is lost.
I suggest to make this code look like:
PyObject *
PyErr_NoMemory(void)
{
if (PyErr_ExceptionMatches(PyExc_MemoryError))
/* already current */
return NULL;
/* raise the pre-allocated instance if it still exists */
if (PyExc_MemoryErrorInst)
PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst);
...
If nobody sees a problem with this, I'm very tempted to check it in.
Any objections?
--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252