creating memory error when there's no memory - Jython's vs CPython's solution
"Stefan Richthofer" <[email protected]>
| Newsgroups | gmane.comp.lang.jython.devel |
|---|---|
| Message-ID | <trinity-ee91410e-fdf0-475b-9526-b6aea98b9847-1409870348484@3capp-gmx-bs42> |
I am currently working to produce a JyNI alpha 2.2 release that is compatible with Jython 2.7 beta 3 (JyNI 2.1 unfortunatly is not due to some changes in ThreadState). During this task I noticed the implementation for creating a MemoryError in Py.java:
public static PyException MemoryError(String message) {
return new PyException(Py.MemoryError, message);
}
Usually there is no more memory available if a MemoryError is needed, so how can the command "new PyException" actually succeed? In CPython they early pre-allocate a MemoryError instance "PyExc_MemoryErrorInst" in exceptions.c. This instance will be used when a memory error is needed although no memory is left to create it. For convenience, let me copy the "PyErr_NoMemory"-method here:
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);
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;
}
Note their comment "this will probably fail since there's no memory and hee, hee, we have to instantiate this class". Why is this no problem for Jython (is it really not?) ?
Maybe one should also pre-allocate a PyException for this purpose (with a static default message though).
This is not necessarily relevant for JyNI; I am just wondering, whether I should replicate CPython's solution or whether I can safely redirect to Jython's variant.
Thanks in advance!
Stefan
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Jython-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-dev