add exit handler
This commit is contained in:
29
src/call-exit-handler.c
Normal file
29
src/call-exit-handler.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <libguile.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "riverguile.h"
|
||||
|
||||
static void *call_exit_handler_inner (void *data)
|
||||
{
|
||||
assert(data == NULL);
|
||||
return scm_call_0(context.exit_handler);
|
||||
}
|
||||
|
||||
void *call_exit_handler (void)
|
||||
{
|
||||
assert(context.exit_handler != NULL);
|
||||
|
||||
/* Continuation barrier causes stack unwind on exceptions (i.e. errors
|
||||
* in the user defined exit handler) to stop here. Otherwise the entire
|
||||
* stack created by scm_with_guile() would be unwound. This makes
|
||||
* responding to exceptions nicer.
|
||||
*/
|
||||
SCM call_result = scm_c_with_continuation_barrier(
|
||||
call_exit_handler_inner, NULL
|
||||
);
|
||||
|
||||
if ( call_result == NULL )
|
||||
return (void *)"ERROR: An exception occured while calling the exit handler.\n";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user