Re: 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-80b5d03f-49bb-4d86-a9ac-6d277055a3c1-1409877297390@3capp-gmx-bs42>
Alright, thanks for the quick answer. So I just won't worry about this. Btw, I don't see, why

PyErr_SetNone(PyExc_MemoryError); should consume more memory, i.e. be more likely to fail

than the pre-allocated variant, since it uses "None" instead of PyExc_MemoryErrorInst and "None"

is also pre-allocated. So why this comment anyway (beside that it's funny)?

Gesendet: Freitag, 05. September 2014 um 02:14 Uhr

Von: "Jeff Emanuel" <[email protected]>

An: [email protected]

Betreff: Re: [Jython-dev] creating memory error when there's no memory - Jython's vs CPython's solution

No memory is different from insufficient available memory. Often a memory error condition occurs

when attempting to allocate a large block of memory fails, but there is still plenty of memory available for one litte

exception object. This applies to the CPython situation too, the "hee,hee" comment is unlikely to be true

in most memory error conditions.

In the rare case where all memory is truly consumed, then you're pre-allocation solution may be necessary.

However, thinking further down the line, the code that tries to handle the memory error is likely to need

some additional memory if it is to handle the error gracefully.

On 9/4/2014 4:39 PM, Stefan Richthofer wrote:

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

------------------------------------------------------------------------------ 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

------------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.