Steve Fink: # > > - Easy to forget to remove temporaries from the root set # > > - Easy to double-anchor objects and forget to remove the # temporary # > > anchoring # > > - longjmp() can bypass the unanchoring # > # > The temporary objects could be stored in a stack, which is # popped when # > leaving the current function (both with normal exits and longjmp). # > This should make it a lot less likely to forget the unanchoring. # # How do you do this with longjmp? I could see chaining another # handler onto the longjmp context so that longjmp would # backtrack through all of these allocations, but that would # require allocating space for another context. And allocating # space further slows down the common case... # # longjmp is really the major blocker for this option, so if # you can work around it, then maybe we'll have something. Your # stack-based approach sounds plausible as a way to make it # easier to handle the bookkeeping, as long as you don't do it # with macros. :-) Maybe wrapper functions?
Pseudocode: void some_func(struct Parrot_Interp *interpreter) { anchor(interpreter, a); anchor(interpreter, b); TRY(interpreter) { something_that_might_throw_an_exception(); } CATCH(interpreter) { } unanchor(interpreter, b); unanchor(interpreter, a); } #define TRY(interp) if(setup_exception((interp)) #define CATCH(interp) else BOOLVAL setup_exception(struct Parrot_Interp *interpreter) { Parrot_jmpbuf jb=NULL; //setup jmpbuf... if(setjmp(jmpbuf)) { jb=stack_pop(interpreter, interpreter->jb_stack); //Everything above us naturally falls off interpreter->anchor_stack_top=jb->anchor_stack_top; } else { Parrot_jmpbuf *jb=malloc(sizeof(Parrot_jmpbuf)); jb->real_jmpbuf=jmpbuf; jb->anchor_stack_top=interpreter->anchor_stack_top; ... stack_push(interpreter, interpreter->jb_stack, jb); } } Yeah, I know, macros are evil, but they make this code *soooo* much prettier... --Brent Dax <[EMAIL PROTECTED]> @roles=map {"Parrot $_"} qw(embedding regexen Configure) "If you want to propagate an outrageously evil idea, your conclusion must be brazenly clear, but your proof unintelligible." --Ayn Rand, explaining how today's philosophies came to be