line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
#include "gmem.h" |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
int gmem_unused = 0; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#if defined(GMEM_CHECK) && GMEM_CHECK >= 1 |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
long gmem_new = 0; |
9
|
|
|
|
|
|
|
long gmem_del = 0; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
static int gmem_inited = 0; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
void gmem_init() |
14
|
|
|
|
|
|
|
{ |
15
|
|
|
|
|
|
|
if (gmem_inited) { |
16
|
|
|
|
|
|
|
return; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
atexit(gmem_fini); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
gmem_inited = 1; |
22
|
|
|
|
|
|
|
gmem_new = gmem_del = 0; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#if defined(GMEM_CHECK) && GMEM_CHECK >= 1 |
25
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM BEG %ld %ld ===\n", gmem_new, gmem_del); |
26
|
|
|
|
|
|
|
#endif |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
void gmem_fini(void) |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
if (!gmem_inited) { |
32
|
|
|
|
|
|
|
return ; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#if defined(GMEM_CHECK) && GMEM_CHECK >= 1 |
36
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM END %ld %ld ===\n", gmem_new, gmem_del); |
37
|
|
|
|
|
|
|
if (gmem_new == gmem_del) { |
38
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM OK ===\n"); |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM ERR %ld BYTES ===\n", gmem_new - gmem_del); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
#endif |
43
|
|
|
|
|
|
|
gmem_inited = 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
int gmem_new_called(const char* file, |
47
|
|
|
|
|
|
|
int line, |
48
|
|
|
|
|
|
|
void* var, |
49
|
|
|
|
|
|
|
int count, |
50
|
|
|
|
|
|
|
long size) |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
long total = 0; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if (!var) { |
55
|
|
|
|
|
|
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if (size <= 0 || count <= 0) { |
59
|
|
|
|
|
|
|
return 0; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
if (!gmem_inited) { |
63
|
|
|
|
|
|
|
gmem_init(); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
total = size * count; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#if defined(GMEM_CHECK) && GMEM_CHECK >= 2 |
69
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM NEW %s %d %p %d %ld %ld ===\n", |
70
|
|
|
|
|
|
|
file, line, var, count, size, total); |
71
|
|
|
|
|
|
|
#endif |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
gmem_new += total; |
74
|
|
|
|
|
|
|
return total; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
int gmem_del_called(const char* file, |
78
|
|
|
|
|
|
|
int line, |
79
|
|
|
|
|
|
|
void* var, |
80
|
|
|
|
|
|
|
int count, |
81
|
|
|
|
|
|
|
long size) |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
long total = 0; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if (!var) { |
86
|
|
|
|
|
|
|
return 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
if (size < 0 && var) { |
90
|
|
|
|
|
|
|
size = strlen((char*) var) + 1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
if (size <= 0 || count <= 0) { |
93
|
|
|
|
|
|
|
return 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
if (!gmem_inited) { |
97
|
|
|
|
|
|
|
gmem_init(); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
total = size * count; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#if defined(GMEM_CHECK) && GMEM_CHECK >= 2 |
103
|
|
|
|
|
|
|
fprintf(stderr, "=== MEM DEL %s %d %p %d %ld %ld ===\n", |
104
|
|
|
|
|
|
|
file, line, var, count, size, total); |
105
|
|
|
|
|
|
|
#endif |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
gmem_del += total; |
108
|
|
|
|
|
|
|
return total; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
int gmem_strnew(const char* file, |
112
|
|
|
|
|
|
|
int line, |
113
|
|
|
|
|
|
|
char** tgt, |
114
|
|
|
|
|
|
|
const char* src, |
115
|
|
|
|
|
|
|
int len) |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
if (!tgt) { |
118
|
|
|
|
|
|
|
return 0; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
*tgt = 0; |
122
|
|
|
|
|
|
|
if (!src) { |
123
|
|
|
|
|
|
|
return 0; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
if (len <= 0) { |
127
|
|
|
|
|
|
|
len = strlen(src) + 1; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
_GMEM_NEW(*tgt, char*, len); |
130
|
|
|
|
|
|
|
memcpy(*tgt, src, len); |
131
|
|
|
|
|
|
|
gmem_new_called(file, line, *tgt, len, 1); |
132
|
|
|
|
|
|
|
return len; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
int gmem_strdel(const char* file, |
136
|
|
|
|
|
|
|
int line, |
137
|
|
|
|
|
|
|
char** str, |
138
|
|
|
|
|
|
|
int len) |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
if (!str || !*str) { |
141
|
|
|
|
|
|
|
return 0; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
if (len <= 0) { |
145
|
|
|
|
|
|
|
len = strlen(*str) + 1; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
gmem_del_called(file, line, *str, len, 1); |
148
|
|
|
|
|
|
|
_GMEM_DEL(*str, char*, len); |
149
|
|
|
|
|
|
|
*str = 0; |
150
|
|
|
|
|
|
|
return len; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#else |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
void gmem_init() |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
void gmem_fini(void) |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#endif /* #if defined(GMEM_CHECK) && GMEM_CHECK >= 1 */ |