Aliases for new unwind_action set() function with no argument?

@jwe just added the ability to change the function associated with an unwind_action object after it has been created.

When a cleanup function is installed with an unwind_action, and the code correctly executes the block that it was protecting, the unwind_action function needs to be cleared so that it no longer executes. Right now that is done by calling set without at argument to set the function to NULL as in unwind_action.set ().

For code clarity, would it be useful to have an alias for this construct which shows the programmer’s intention? For unwind_protect frames there was a function discard. Thus, at the end of successfully running a block of code one could call frame.discard () which makes it clear that the frame is no longer needed. Alternatively, instead of set with a null argument it might be good to have a function unset defined in the header file for unwind_action which is the equivalent of set().

Yeah, I wondered whether it might be clearer if we had a “discard” alias that meant the same thing as calling “set” with no arguments. Since you also had the same thought, I guess it would be a good idea to add it.

BTW, my reason for allowing undefined cleanup objects and adding the “set” function was to allow a cleanup action to be executed at the end of a function when the action is optional and needs to be set in a nested code block. Then I realized that this feature would also allow discarding/disabling the cleanup action.

These features and the new “run” function allow us to replace almost all uses of unwind_protect with unwind_action objects.

I would also like to look at eliminating all the various action_container types except the one that accepts a std::function object as I think that can handle all the cases we need to consider.

I added discard () as an alias for set () in unwind-prot.h and then transitioned the three instances that I know of in this changeset: octave: 20092ae957da.

Thanks for making the change. I agree that discard will be easier to immediately understand than set with no arguments.