From: Stefan R. <Ste...@gm...> - 2014-09-05 00:35:08
|
<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div> <div>Alright, thanks for the quick answer. So I just won't worry about this. Btw, I don't see, why</div> <div>PyErr_SetNone(PyExc_MemoryError); should consume more memory, i.e. be more likely to fail</div> <div>than the pre-allocated variant, since it uses "None" instead of PyExc_MemoryErrorInst and "None"</div> <div>is also pre-allocated. So why this comment anyway (beside that it's funny)?</div> <div> <div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"> <div style="margin:0 0 10px 0;"><b>Gesendet:</b> Freitag, 05. September 2014 um 02:14 Uhr<br/> <b>Von:</b> "Jeff Emanuel" <jem...@fr...><br/> <b>An:</b> jyt...@li...<br/> <b>Betreff:</b> Re: [Jython-dev] creating memory error when there's no memory - Jython's vs CPython's solution</div> <div name="quoted-content"> <div style="background-color: rgb(255,255,255);"><tt>No memory is different from insufficient available memory. Often a memory error condition occurs<br/> when attempting to allocate a large block of memory fails, but there is still plenty of memory available for one litte<br/> exception object. This applies to the CPython situation too, the "hee,hee" comment is unlikely to be true<br/> in most memory error conditions.<br/> <br/> In the rare case where all memory is truly consumed, then you're pre-allocation solution may be necessary.<br/> However, thinking further down the line, the code that tries to handle the memory error is likely to need<br/> some additional memory if it is to handle the error gracefully. <br/> <br/> </tt> <div class="moz-cite-prefix">On 9/4/2014 4:39 PM, Stefan Richthofer wrote:</div> <blockquote> <div style="font-family: Verdana;font-size: 12.0px;"> <div>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:</div> <div> </div> <div> public static PyException MemoryError(String message) {<br/> return new PyException(Py.MemoryError, message);<br/> }</div> <div> </div> <div>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:</div> <div> </div> <div> <div>PyObject *<br/> PyErr_NoMemory(void)<br/> {<br/> if (PyErr_ExceptionMatches(PyExc_MemoryError))<br/> /* already current */<br/> return NULL;</div> <div> /* raise the pre-allocated instance if it still exists */<br/> if (PyExc_MemoryErrorInst)<br/> PyErr_SetObject(PyExc_MemoryError, PyExc_MemoryErrorInst);<br/> else<br/> /* this will probably fail since there's no memory and hee,<br/> hee, we have to instantiate this class<br/> */<br/> PyErr_SetNone(PyExc_MemoryError);</div> <div> return NULL;<br/> }</div> <div> </div> <div>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?) ?</div> <div>Maybe one should also pre-allocate a PyException for this purpose (with a static default message though).</div> <div> </div> <div>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.</div> <div> </div> <div>Thanks in advance!</div> <div> </div> <div>Stefan</div> </div> </div> <fieldset class="mimeAttachmentHeader"> </fieldset> <pre>------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. <a class="moz-txt-link-freetext" href="http://tv.slashdot.org/" target="_blank">http://tv.slashdot.org/</a></pre> <fieldset class="mimeAttachmentHeader"> </fieldset> <pre>_______________________________________________ Jython-dev mailing list <a class="moz-txt-link-abbreviated" href="Jyt...@li..." target="_parent">Jyt...@li...</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a> </pre> </blockquote> <br/> ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. <a href="http://tv.slashdot.org/_______________________________________________" target="_blank">http://tv.slashdot.org/_______________________________________________</a> Jython-dev mailing list Jyt...@li... <a href="https://lists.sourceforge.net/lists/listinfo/jython-dev" target="_blank">https://lists.sourceforge.net/lists/listinfo/jython-dev</a></div> </div> </div> </div> </div></div></body></html> |