This repository has been archived by the owner on Feb 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callstack.c
57 lines (50 loc) · 1.6 KB
/
callstack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <talloc.h>
#include "callstack.h"
callstack *callstack_new()
{
callstack *this = talloc(NULL, callstack);
this->head = NULL;
return this;
}
callstack_node *callstack_node_dup(callstack_node *this)
{
callstack_node *dup = talloc(NULL, callstack_node);
dup->meta = talloc_steal(dup, metadata_dup(this->meta));
dup->next = NULL;
return dup;
}
callstack *callstack_dup(callstack *this)
{
callstack *dup = talloc(NULL, callstack);
dup->head = talloc_steal(dup, callstack_node_dup(this->head));
callstack_node *dup_node = dup->head;
for (callstack_node *node = this->head->next; node; node = node->next) {
dup_node->next = talloc_steal(dup, callstack_node_dup(node));
dup_node = dup_node->next;
}
return dup;
}
void callstack_push(callstack *this, metadata *meta)
{
callstack_node *node = talloc(this, callstack_node);
node->meta = talloc_steal(node, metadata_dup(meta));
node->next = this->head;
this->head = node;
}
void callstack_pop(callstack *this)
{
callstack_node *node = this->head;
this->head = node->next;
talloc_free(node);
}
char *callstack_sprint(callstack *this)
{
char *sprint = talloc_strdup(NULL, "");
for (callstack_node *node = this->head; node; node = node->next) {
if (node->meta->name)
sprint = talloc_asprintf_append(sprint, " %s:%i:%i %s\n", node->meta->file, node->meta->line, node->meta->col, node->meta->name);
else
sprint = talloc_asprintf_append(sprint, " %s:%i:%i\n", node->meta->file, node->meta->line, node->meta->col);
}
return sprint;
}