On 02/12/2010 19:15, Tim Harig wrote:
On 2010-12-02, Paul Rubin<no.em...@nospam.invalid>  wrote:
Tim Harig<user...@ilthio.net>  writes:
longjmp.  Alternatively you can have an auxiliary stack of cleanup
records that the longjmp handler walks through.  Of course if you do

Only if you already have pointers to *all* of the data structures at
the point where you put your setjmp().

The setjmp point only has to know where the aux stack is and its depth
when the longjmp happens.  The cleanup records contain any necessary
pointers to data structures that need freeing.  That is basically how
try/finally would do it too.  This is pretty standard stuff.

I am not talking about what setjmp() has to do, I am talking about what
*you* have to do after setjmp() returns.  If you have allocated memory in
intermediate functions and you don't have a reference to them outside of
the functions that longjmp() bypasses from returning properly (and thus
either not clearning data structures or returning a reference to those data
structures as it normally would) then you have potential memory leaks,
dangling pointers, etc.

I am not saying that this cannot be done.  What I am saying is that it
is inherently error prone.

Automatic garbage collection is nice to have when using exceptions
precisely because it's automatic, so unwinding the stack is much safer.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to