Tim Harig <user...@ilthio.net> writes: > 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.
Sure, that's what the aux stack is for--you put any such references into it, for the setjmp handler to find later. You do that BEFORE setjmp returns, of course. > I am not saying that this cannot be done. What I am saying is that it > is inherently error prone. I suppose so, but so is everything else in C. On the overall scale of C-related hazards, this particular one isn't so bad if you code in a consistent style and are disciplined about recording the cleanups. You could also use something like an obstack, which is a stack allocated on the heap, so it persists after the control stack returns, but you can release the whole thing in one operation. -- http://mail.python.org/mailman/listinfo/python-list