assumed_nonnull crap... temp fix.
[smatch.git] / smatch_function_hooks.c
blob4c2ac648b1f5c05b1a8f822d8d8894cf43c14c1a
1 #include <search.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include "smatch.h"
6 struct fcall_back {
7 void *call_back;
8 void *data;
9 };
11 ALLOCATOR(fcall_back, "call backs");
12 DECLARE_PTR_LIST(call_back_list, struct fcall_back);
14 static int my_id;
16 void add_function_hook(const char *lock_for, void *call_back, void *data)
18 ENTRY e, *ep;
19 struct fcall_back *cb;
21 cb = __alloc_fcall_back(0);
22 cb->call_back = call_back;
23 cb->data = data;
24 e.key = alloc_string(lock_for);
25 ep = hsearch(e, FIND);
26 if (!ep) {
27 struct call_back_list *list = NULL;
29 add_ptr_list(&list, cb);
30 e.data = list;
31 } else {
32 free_string(ep->key);
33 add_ptr_list((struct call_back_list **)&ep->data, cb);
34 e.data = ep->data;
36 hsearch(e, ENTER);
39 typedef void (call_back_func)(struct expression *expr, void *data);
40 static void match_function_call(struct expression *expr)
42 ENTRY e, *ep;
43 struct fcall_back *tmp;
45 if (expr->fn->type != EXPR_SYMBOL || !expr->fn->symbol)
46 return;
48 e.key = expr->fn->symbol->ident->name;
49 ep = hsearch(e, FIND);
50 if (!ep)
51 return;
53 FOR_EACH_PTR((struct call_back_list *)ep->data, tmp) {
54 ((call_back_func *) tmp->call_back)(expr, tmp->data);
55 } END_FOR_EACH_PTR(tmp);
58 void register_function_hooks(int id)
60 my_id = id;
61 hcreate(1000); // We will track maybe 1000 functions.
62 add_hook(&match_function_call, FUNCTION_CALL_HOOK);