line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#ifndef XSH_MEM_H |
2
|
|
|
|
|
|
|
#define XSH_MEM_H 1 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include "util.h" /* XSH_ASSERT() */ |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#ifdef DEBUGGING |
7
|
|
|
|
|
|
|
# ifdef Poison |
8
|
|
|
|
|
|
|
# define XSH_POISON(D, N, T) Poison((D), (N), T) |
9
|
|
|
|
|
|
|
# endif |
10
|
|
|
|
|
|
|
# ifdef PoisonNew |
11
|
|
|
|
|
|
|
# define XSH_POISON_NEW(D, N, T) PoisonNew((D), (N), T) |
12
|
|
|
|
|
|
|
# define XSH_HAS_POISON_NEW 1 |
13
|
|
|
|
|
|
|
# endif |
14
|
|
|
|
|
|
|
# ifdef PoisonFree |
15
|
|
|
|
|
|
|
# define XSH_POISON_FREE(D, N, T) PoisonFree((D), (N), T) |
16
|
|
|
|
|
|
|
# define XSH_HAS_POISON_FREE 1 |
17
|
|
|
|
|
|
|
# endif |
18
|
|
|
|
|
|
|
#endif |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#ifdef XSH_POISON |
21
|
|
|
|
|
|
|
# ifndef XSH_POISON_NEW |
22
|
|
|
|
|
|
|
# define XSH_POISON_NEW(D, N, T) XSH_POISON(D, N, T) |
23
|
|
|
|
|
|
|
# define XSH_HAS_POISON_NEW 1 |
24
|
|
|
|
|
|
|
# endif |
25
|
|
|
|
|
|
|
# ifndef XSH_POISON_FREE |
26
|
|
|
|
|
|
|
# define XSH_POISON_FREE(D, N, T) XSH_POISON(D, N, T) |
27
|
|
|
|
|
|
|
# define XSH_HAS_POISON_FREE 1 |
28
|
|
|
|
|
|
|
# endif |
29
|
|
|
|
|
|
|
#endif |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#ifndef XSH_HAS_POISON_NEW |
32
|
|
|
|
|
|
|
# define XSH_HAS_POISON_NEW 0 |
33
|
|
|
|
|
|
|
#endif |
34
|
|
|
|
|
|
|
#ifndef XSH_HAS_POISON_FREE |
35
|
|
|
|
|
|
|
# define XSH_HAS_POISON_FREE 0 |
36
|
|
|
|
|
|
|
#endif |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
/* --- Shared memory ------------------------------------------------------- */ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
/* Context for PerlMemShared_*() functions */ |
41
|
|
|
|
|
|
|
#ifdef PERL_IMPLICIT_SYS |
42
|
|
|
|
|
|
|
# define pPMS pTHX |
43
|
|
|
|
|
|
|
# define pPMS_ pTHX_ |
44
|
|
|
|
|
|
|
# define aPMS aTHX |
45
|
|
|
|
|
|
|
# define aPMS_ aTHX_ |
46
|
|
|
|
|
|
|
#else |
47
|
|
|
|
|
|
|
# define pPMS void |
48
|
|
|
|
|
|
|
# define pPMS_ |
49
|
|
|
|
|
|
|
# define aPMS |
50
|
|
|
|
|
|
|
# define aPMS_ |
51
|
|
|
|
|
|
|
#endif |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
/* ... xsh_shared_alloc() .................................................. */ |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#if XSH_HAS_POISON_NEW |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
static void *xsh_shared_alloc(pPMS_ size_t size) { |
58
|
|
|
|
|
|
|
#define xsh_shared_alloc(S) xsh_shared_alloc(aPMS_ (S)) |
59
|
|
|
|
|
|
|
void *p; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
p = PerlMemShared_malloc(size); |
62
|
|
|
|
|
|
|
XSH_ASSERT(p); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
XSH_POISON_NEW(p, size, char); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return p; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#else /* XSH_HAS_POISON_NEW */ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#define xsh_shared_alloc(S) PerlMemShared_malloc(S) |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#endif /* !XSH_HAS_POISON_NEW */ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#define XSH_SHARED_ALLOC(D, N, T) ((D) = xsh_shared_alloc((N) * sizeof(T))) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
/* ... xsh_shared_calloc() ................................................. */ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#define xsh_shared_calloc(C, S) PerlMemShared_calloc((C), (S)) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#define XSH_SHARED_CALLOC(D, N, T) ((D) = xsh_shared_calloc((N), sizeof(T))) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
/* ... xsh_shared_free() ................................................... */ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#if XSH_HAS_POISON_FREE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
static void xsh_shared_free(pPMS_ void *p, size_t size) { |
88
|
|
|
|
|
|
|
#define xsh_shared_free(P, S) xsh_shared_free(aPMS_ (P), (S)) |
89
|
|
|
|
|
|
|
if (p) |
90
|
|
|
|
|
|
|
XSH_POISON_FREE(p, size, char); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
PerlMemShared_free(p); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#else /* XSH_HAS_POISON_FREE */ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#define xsh_shared_free(P, S) PerlMemShared_free(P) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#endif /* !XSH_HAS_POISON_FREE */ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#define XSH_SHARED_FREE(D, N, T) (xsh_shared_free((D), (N) * sizeof(T)), (D) = NULL) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
/* ... xsh_shared_realloc() ................................................ */ |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#if XSH_HAS_POISON_NEW && XSH_HAS_POISON_FREE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
static void *xsh_shared_realloc(pPMS_ void *p, size_t old_size, size_t new_size) { |
110
|
|
|
|
|
|
|
#define xsh_shared_realloc(P, OS, NS) xsh_shared_realloc(aPMS_ (P), (OS), (NS)) |
111
|
|
|
|
|
|
|
void *q; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if (!p) |
114
|
|
|
|
|
|
|
return xsh_shared_alloc(new_size); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
if (!new_size) { |
117
|
|
|
|
|
|
|
xsh_shared_free(p, old_size); |
118
|
|
|
|
|
|
|
return xsh_shared_alloc(1); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if (new_size < old_size) |
122
|
|
|
|
|
|
|
XSH_POISON_FREE(((char *) p) + new_size, old_size - new_size, char); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
q = PerlMemShared_realloc(p, new_size); |
125
|
|
|
|
|
|
|
XSH_ASSERT(q); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
if (old_size < new_size) |
128
|
|
|
|
|
|
|
XSH_POISON_NEW(((char *) q) + old_size, new_size - old_size, char); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
return q; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#else /* XSH_HAS_POISON_NEW && XSH_HAS_POISON_FREE */ |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#define xsh_shared_realloc(P, OS, NS) PerlMemShared_realloc((P), (NS)) |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#endif /* !XSH_HAS_POISON_NEW || !XSH_HAS_POISON_FREE */ |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
#define XSH_SHARED_REALLOC(D, OL, NL, T) ((D) = xsh_shared_realloc((D), (OL) * sizeof(T), (NL) * sizeof(T))) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
/* ... xsh_shared_recalloc() ............................................... */ |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
static void *xsh_shared_recalloc(pPMS_ void *p, size_t old_size, size_t new_size) { |
144
|
|
|
|
|
|
|
#define xsh_shared_recalloc(P, OS, NS) xsh_shared_recalloc(aPMS_ (P), (OS), (NS)) |
145
|
|
|
|
|
|
|
void *q; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#ifdef XSH_POISON_FREE |
148
|
|
|
|
|
|
|
if (new_size < old_size) |
149
|
|
|
|
|
|
|
XSH_POISON_FREE(((char *) p) + new_size, old_size - new_size, char); |
150
|
|
|
|
|
|
|
#endif /* XSH_POISON_FREE */ |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
q = PerlMemShared_realloc(p, new_size); |
153
|
|
|
|
|
|
|
XSH_ASSERT(q); |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
if (old_size < new_size) |
156
|
0
|
|
|
|
|
|
Zero(((char *) q) + old_size, new_size - old_size, char); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return q; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
#define XSH_SHARED_RECALLOC(D, OL, NL, T) ((D) = xsh_shared_recalloc((D), (OL) * sizeof(T), (NL) * sizeof(T))) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
/* --- Interpreter-local memory -------------------------------------------- */ |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#ifndef Newx |
166
|
|
|
|
|
|
|
# define Newx(D, N, T) New(0, (D), (N), T) |
167
|
|
|
|
|
|
|
#endif |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#ifndef PERL_POISON |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
#if XSH_HAS_POISON_NEW |
172
|
|
|
|
|
|
|
# define XSH_LOCAL_ALLOC(D, N, T) (Newx((D), (N), T), XSH_POISON_NEW((D), (N), T)) |
173
|
|
|
|
|
|
|
#endif |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#if XSH_HAS_POISON_FREE |
176
|
|
|
|
|
|
|
# define XSH_LOCAL_FREE(D, N, T) (XSH_POISON_FREE((D), (N), T), Safefree(D)) |
177
|
|
|
|
|
|
|
#endif |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#if XSH_HAS_POISON_NEW && XSH_HAS_POISON_FREE |
180
|
|
|
|
|
|
|
# define XSH_LOCAL_REALLOC(D, OL, NL, T) ((((D) && ((NL) < (OL))) ? XSH_POISON_FREE(((T *) (D)) + (NL), (OL) - (NL), T) : NOOP), Renew((D), (NL), T), (((OL) < (NL)) ? XSH_POISON_NEW(((T *) (D)) + (OL), (NL) - (OL), T) : NOOP)) |
181
|
|
|
|
|
|
|
#endif |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#endif /* !PERL_POISON */ |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#ifndef XSH_LOCAL_ALLOC |
186
|
|
|
|
|
|
|
# define XSH_LOCAL_ALLOC(D, N, T) Newx((D), (N), T) |
187
|
|
|
|
|
|
|
#endif |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#define XSH_LOCAL_CALLOC(D, N, T) Newxz((D), (N), T) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#ifndef XSH_LOCAL_FREE |
192
|
|
|
|
|
|
|
# define XSH_LOCAL_FREE(D, N, T) Safefree(D) |
193
|
|
|
|
|
|
|
#endif |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
#ifndef XSH_LOCAL_REALLOC |
196
|
|
|
|
|
|
|
# define XSH_LOCAL_REALLOC(D, OL, NL, T) Renew((D), (NL), T) |
197
|
|
|
|
|
|
|
#endif |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#endif /* XSH_MEM_H */ |