PIPS
reset_hooks.c File Reference
#include <stdio.h>
#include <genC.h>
#include "misc.h"
+ Include dependency graph for reset_hooks.c:

Go to the source code of this file.

Functions

void reset_hooks_register (reset_func_t function)
 add function to be called for cleanup if an exception is raised. More...
 
void reset_hooks_call (void)
 this function is expected to be called when catching an exception. More...
 
void reset_hooks_is_empty (void)
 check that the stack was cleaned. More...
 
void reset_hooks_unregister (reset_func_t function)
 remove registered cleanup hook. More...
 

Variables

static list reset_hooks = NIL
 reset functions to call on exceptions to be used by pipsmake? More...
 

Function Documentation

◆ reset_hooks_call()

void reset_hooks_call ( void  )

this function is expected to be called when catching an exception.

Definition at line 53 of file reset_hooks.c.

54 {
55  // call reset functions
57  (*((reset_func_t) f))();
58 
59  // cleanup
61  reset_hooks = NIL;
62 }
#define VOID_STAR(x)
Definition: genC.h:95
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
void(* reset_func_t)(void)
Definition: misc-local.h:222
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
static list reset_hooks
reset functions to call on exceptions to be used by pipsmake?
Definition: reset_hooks.c:40

References f(), FOREACH, gen_free_list(), NIL, reset_hooks, and VOID_STAR.

Referenced by reset_static_phase_variables().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_hooks_is_empty()

void reset_hooks_is_empty ( void  )

check that the stack was cleaned.

Definition at line 66 of file reset_hooks.c.

67 {
68  pips_assert("no reset functions", reset_hooks == NIL);
69 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

References NIL, pips_assert, and reset_hooks.

Referenced by catch_user_error().

+ Here is the caller graph for this function:

◆ reset_hooks_register()

void reset_hooks_register ( reset_func_t  function)

add function to be called for cleanup if an exception is raised.

reset_hooks.c

Parameters
functionunction

Definition at line 44 of file reset_hooks.c.

45 {
46  pips_assert("reset function not already in list",
47  !gen_in_list_p(function, reset_hooks));
48  reset_hooks = CONS(VOID_STAR, function, reset_hooks);
49 }
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734

References CONS, gen_in_list_p(), pips_assert, reset_hooks, and VOID_STAR.

Referenced by atomize_as_required(), hpfc_close(), hpfc_common(), hpfc_compile(), hpfc_directives_handler(), hpfc_filter(), hpfc_init(), module_to_value_mappings(), and print_module_icfg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_hooks_unregister()

void reset_hooks_unregister ( reset_func_t  function)

remove registered cleanup hook.

Parameters
functionunction

Definition at line 73 of file reset_hooks.c.

74 {
75  // should it really be the first? probably too optimistic.
76  /*
77  pips_assert(reset_hooks &&
78  VOID_STAR(CAR(reset_hooks)) == function,
79  "unregister reset functions in reverse order");
80  */
81  pips_assert("unregister a function already registered",
82  gen_in_list_p(function, reset_hooks));
83  gen_remove_once(&reset_hooks, function);
84 }
void gen_remove_once(list *pl, const void *o)
Remove the first occurence of o in list pl:
Definition: list.c:691

References gen_in_list_p(), gen_remove_once(), pips_assert, and reset_hooks.

Referenced by atomize_as_required(), free_value_mappings(), hpfc_close(), hpfc_common(), hpfc_compile(), hpfc_directives_handler(), hpfc_filter(), hpfc_init(), and print_module_icfg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ reset_hooks

list reset_hooks = NIL
static

reset functions to call on exceptions to be used by pipsmake?

should it be a stack? should there by a stack of stacks for different TRY/CATCH levels? should it be processed up to a marker? would an additionnal void* for arguments make sense?

Definition at line 40 of file reset_hooks.c.

Referenced by reset_hooks_call(), reset_hooks_is_empty(), reset_hooks_register(), and reset_hooks_unregister().