[Python-Dev] PyErr_NoMemory (original) (raw)
Tim Peters tim_one@email.msn.com
Fri, 18 Aug 2000 01:43:14 -0400
- Previous message: [Python-Dev] PyErr_NoMemory
- Next message: [Python-Dev] Introducing memprof (was PyErr_NoMemory)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Vladimir Marangozov]
The current PyErrNoMemory() function reads:
PyObject * PyErrNoMemory(void) { /* raise the pre-allocated instance if it still exists */ if (PyExcMemoryErrorInst) PyErrSetObject(PyExcMemoryError, PyExcMemoryErrorInst); else /* this will probably fail since there's no memory and hee, hee, we have to instantiate this class */ PyErrSetNone(PyExcMemoryError); return NULL; } thus overriding any previous exceptions unconditionally. This is a problem when the current exception already is PyExcMemoryError, 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 * PyErrNoMemory(void) { if (PyErrExceptionMatches(PyExcMemoryError)) /* already current */ return NULL; /* raise the pre-allocated instance if it still exists */ if (PyExcMemoryErrorInst) PyErrSetObject(PyExcMemoryError, PyExcMemoryErrorInst); ...
If nobody sees a problem with this, I'm very tempted to check it in. Any objections?
Looks good to me. And if it breaks something, it will be darned hard to tell .
- Previous message: [Python-Dev] PyErr_NoMemory
- Next message: [Python-Dev] Introducing memprof (was PyErr_NoMemory)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]