diff options
-rw-r--r-- | src/cflow.h | 1 | ||||
-rw-r--r-- | src/linked-list.c | 15 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/symbol.c | 35 |
4 files changed, 39 insertions, 13 deletions
diff --git a/src/cflow.h b/src/cflow.h index 5867a18..0e3ee44 100644 --- a/src/cflow.h +++ b/src/cflow.h | |||
@@ -198,6 +198,7 @@ void linked_list_iterate(struct linked_list **plist, | |||
198 | int (*itr) (void *, void *), void *data); | 198 | int (*itr) (void *, void *), void *data); |
199 | void linked_list_unlink(struct linked_list *list, | 199 | void linked_list_unlink(struct linked_list *list, |
200 | struct linked_list_entry *ent); | 200 | struct linked_list_entry *ent); |
201 | size_t linked_list_size(struct linked_list *list); | ||
201 | 202 | ||
202 | int data_in_list(void *data, struct linked_list *list); | 203 | int data_in_list(void *data, struct linked_list *list); |
203 | 204 | ||
diff --git a/src/linked-list.c b/src/linked-list.c index 095b63e..3c57bf0 100644 --- a/src/linked-list.c +++ b/src/linked-list.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include <cflow.h> | 17 | #include <cflow.h> |
18 | 18 | ||
19 | static struct linked_list * | 19 | static struct linked_list * |
20 | deref_linked_list (struct linked_list **plist) | 20 | deref_linked_list(struct linked_list **plist) |
21 | { | 21 | { |
22 | if (!*plist) { | 22 | if (!*plist) { |
23 | struct linked_list *list = xmalloc(sizeof(*list)); | 23 | struct linked_list *list = xmalloc(sizeof(*list)); |
@@ -144,3 +144,16 @@ data_in_list(void *data, struct linked_list *list) | |||
144 | return 1; | 144 | return 1; |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | |||
148 | size_t | ||
149 | linked_list_size(struct linked_list *list) | ||
150 | { | ||
151 | size_t size = 0; | ||
152 | if (list) { | ||
153 | struct linked_list_entry *p; | ||
154 | for (p = linked_list_head(list); p; p = p->next) | ||
155 | size++; | ||
156 | } | ||
157 | return size; | ||
158 | } | ||
159 | |||
@@ -647,6 +647,7 @@ parse_opt (int key, char *arg, struct argp_state *state) | |||
647 | break; | 647 | break; |
648 | case 'x': | 648 | case 'x': |
649 | print_option = PRINT_XREF; | 649 | print_option = PRINT_XREF; |
650 | SYMBOL_EXCLUDE('s'); /* Exclude static symbols by default */ | ||
650 | break; | 651 | break; |
651 | case OPT_PREPROCESS: | 652 | case OPT_PREPROCESS: |
652 | preprocess_option = 1; | 653 | preprocess_option = 1; |
diff --git a/src/symbol.c b/src/symbol.c index 460f954..5f7dec2 100644 --- a/src/symbol.c +++ b/src/symbol.c | |||
@@ -297,21 +297,35 @@ collect_processor(void *data, void *proc_data) | |||
297 | return true; | 297 | return true; |
298 | } | 298 | } |
299 | 299 | ||
300 | static int | ||
301 | collect_list_entry(void *item, void *proc_data) | ||
302 | { | ||
303 | Symbol *s = item; | ||
304 | struct collect_data *cd = proc_data; | ||
305 | if (cd->sel(s)) { | ||
306 | cd->sym[cd->index] = s; | ||
307 | cd->index++; | ||
308 | } | ||
309 | return 0; | ||
310 | } | ||
311 | |||
300 | size_t | 312 | size_t |
301 | collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p), | 313 | collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p), |
302 | size_t reserved_slots) | 314 | size_t reserved_slots) |
303 | { | 315 | { |
304 | struct collect_data cdata; | 316 | struct collect_data cdata; |
305 | 317 | size_t size; | |
306 | cdata.sym = NULL; | 318 | |
319 | size = hash_get_n_entries(symbol_table) | ||
320 | + linked_list_size(static_func_list); | ||
321 | cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym)); | ||
307 | cdata.index = 0; | 322 | cdata.index = 0; |
308 | cdata.sel = sel; | 323 | cdata.sel = sel; |
309 | hash_do_for_each (symbol_table, collect_processor, &cdata); | 324 | hash_do_for_each(symbol_table, collect_processor, &cdata); |
310 | cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym)); | 325 | linked_list_iterate(&static_func_list, collect_list_entry, &cdata); |
311 | if (!cdata.sym) | 326 | |
312 | xalloc_die(); | 327 | cdata.sym = xrealloc(cdata.sym, |
313 | cdata.index = 0; | 328 | (cdata.index + reserved_slots) * sizeof(*cdata.sym)); |
314 | hash_do_for_each (symbol_table, collect_processor, &cdata); | ||
315 | *return_sym = cdata.sym; | 329 | *return_sym = cdata.sym; |
316 | return cdata.index; | 330 | return cdata.index; |
317 | } | 331 | } |
@@ -324,10 +338,7 @@ collect_functions(Symbol ***return_sym) | |||
324 | struct linked_list_entry *p; | 338 | struct linked_list_entry *p; |
325 | 339 | ||
326 | /* Count static functions */ | 340 | /* Count static functions */ |
327 | snum = 0; | 341 | snum = linked_list_size(static_func_list); |
328 | if (static_func_list) | ||
329 | for (p = linked_list_head(static_func_list); p; p = p->next) | ||
330 | snum++; | ||
331 | 342 | ||
332 | /* Collect global functions */ | 343 | /* Collect global functions */ |
333 | num = collect_symbols(&symbols, symbol_is_function, snum); | 344 | num = collect_symbols(&symbols, symbol_is_function, snum); |