CL_UNWIND_PROTECT
— Create a protected region.
cl_env_ptr env = ecl_process_env(); CL_UNWIND_PROTECT_BEGIN(env) { /* * Code that is protected. Uncaught lisp conditions, THROW, * signals such as SIGSEGV and SIGBUS may cause jump to * this region. */ } CL_UNWIND_PROTECT_EXIT { /* * If the exception, lisp condition or other control transfer * is caught, this code is executed. After this code, the * process will jump to the original destination of the * THROW, GOTO or other control statement that was interrupted. */ } CL_UNWIND_PROTECT_END /* * We only exit here if NO nonlocal jump was interrupted. */
When embedding ECL it is normally advisable to set up an unwind-protect frame to avoid the embedded lisp code to perform arbitary transfers of control. Furthermore, the unwind protect form will be used in at least in the following ocasions:
In a normal program exit, caused by ext:quit
,
ECL unwinds up to the outermost frame, which may be an CL_CATCH_ALL
or CL_UNWIND_PROTECT
macro.
Besides this, normal mechanisms for exit, such as
ext:quit
, and uncaught exceptions, such as serious
signals (Section 7.2.1), are best handled using
unwind-protect blocks.