Skip to content

Commit 3e4b965

Browse files
committed
Fix warnings in mysqlnd_alloc.c
And also separate the PHP_DEBUG codepaths more, to avoids having an ifdef every other line...
1 parent 9fa552f commit 3e4b965

File tree

1 file changed

+60
-91
lines changed

1 file changed

+60
-91
lines changed

ext/mysqlnd/mysqlnd_alloc.c

Lines changed: 60 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,22 @@ static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
8282
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
8383
#if PHP_DEBUG
8484
zend_long * threshold = &MYSQLND_G(debug_emalloc_fail_threshold);
85-
#endif
8685
TRACE_ALLOC_ENTER(mysqlnd_emalloc_name);
8786

88-
#if PHP_DEBUG
8987
{
9088
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
9189
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
9290
}
93-
#endif
9491

95-
#if PHP_DEBUG
96-
/* -1 is also "true" */
97-
if (*threshold) {
98-
#endif
92+
if (*threshold == 0) {
93+
ret = NULL;
94+
} else {
9995
ret = emalloc_rel(REAL_SIZE(size));
100-
#if PHP_DEBUG
10196
--*threshold;
102-
} else if (*threshold == 0) {
103-
ret = NULL;
10497
}
98+
#else
99+
TRACE_ALLOC_ENTER(mysqlnd_emalloc_name);
100+
ret = emalloc_rel(REAL_SIZE(size));
105101
#endif
106102

107103
TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
@@ -122,26 +118,22 @@ static void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D)
122118
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
123119
#if PHP_DEBUG
124120
zend_long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold);
125-
#endif
126121
TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name);
127122

128-
#if PHP_DEBUG
129123
{
130124
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
131125
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
132126
}
133-
#endif
134127

135-
#if PHP_DEBUG
136-
/* -1 is also "true" */
137-
if (*threshold) {
138-
#endif
128+
if (*threshold == 0) {
129+
ret = NULL;
130+
} else {
139131
ret = pemalloc_rel(REAL_SIZE(size), persistent);
140-
#if PHP_DEBUG
141132
--*threshold;
142-
} else if (*threshold == 0) {
143-
ret = NULL;
144133
}
134+
#else
135+
TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name);
136+
ret = pemalloc_rel(REAL_SIZE(size), persistent);
145137
#endif
146138

147139
TRACE_ALLOC_INF_FMT("size=%lu ptr=%p persistent=%u", size, ret, persistent);
@@ -163,29 +155,26 @@ static void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
163155
{
164156
void *ret;
165157
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
166-
#if PHP_DEBUG
167158
zend_long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold);
168-
#endif
159+
#if PHP_DEBUG
169160
TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name);
170161

171-
#if PHP_DEBUG
172162
{
173163
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
174164
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
175165
}
176-
#endif
177166
TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE));
178167

179-
#if PHP_DEBUG
180-
/* -1 is also "true" */
181-
if (*threshold) {
182-
#endif
168+
if (*threshold == 0) {
169+
ret = NULL;
170+
} else {
183171
ret = ecalloc_rel(nmemb, REAL_SIZE(size));
184-
#if PHP_DEBUG
185172
--*threshold;
186-
} else if (*threshold == 0) {
187-
ret = NULL;
188173
}
174+
#else
175+
TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name);
176+
TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE));
177+
ret = ecalloc_rel(nmemb, REAL_SIZE(size));
189178
#endif
190179

191180
TRACE_ALLOC_INF_FMT("after : %lu", zend_memory_usage(FALSE));
@@ -206,25 +195,21 @@ static void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persi
206195
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
207196
#if PHP_DEBUG
208197
zend_long * threshold = persistent? &MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold);
209-
#endif
210198
TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name);
211-
#if PHP_DEBUG
212199
{
213200
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
214201
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
215202
}
216-
#endif
217203

218-
#if PHP_DEBUG
219-
/* -1 is also "true" */
220-
if (*threshold) {
221-
#endif
204+
if (*threshold == 0) {
205+
ret = NULL;
206+
} else {
222207
ret = pecalloc_rel(nmemb, REAL_SIZE(size), persistent);
223-
#if PHP_DEBUG
224208
--*threshold;
225-
} else if (*threshold == 0) {
226-
ret = NULL;
227209
}
210+
#else
211+
TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name);
212+
ret = pecalloc_rel(nmemb, REAL_SIZE(size), persistent);
228213
#endif
229214

230215
TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
@@ -249,27 +234,24 @@ static void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D)
249234
size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0;
250235
#if PHP_DEBUG
251236
zend_long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold);
252-
#endif
253237
TRACE_ALLOC_ENTER(mysqlnd_erealloc_name);
254238

255-
#if PHP_DEBUG
256239
{
257240
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
258241
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
259242
}
260-
#endif
261243
TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size);
262244

263-
#if PHP_DEBUG
264-
/* -1 is also "true" */
265-
if (*threshold) {
266-
#endif
245+
if (*threshold == 0) {
246+
ret = NULL;
247+
} else {
267248
ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size));
268-
#if PHP_DEBUG
269249
--*threshold;
270-
} else if (*threshold == 0) {
271-
ret = NULL;
272250
}
251+
#else
252+
TRACE_ALLOC_ENTER(mysqlnd_erealloc_name);
253+
TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size);
254+
ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size));
273255
#endif
274256

275257
TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);
@@ -290,27 +272,24 @@ static void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persisten
290272
size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0;
291273
#if PHP_DEBUG
292274
zend_long * threshold = persistent? &MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold);
293-
#endif
294275
TRACE_ALLOC_ENTER(mysqlnd_perealloc_name);
295276

296-
#if PHP_DEBUG
297277
{
298278
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
299279
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
300280
}
301-
#endif
302281
TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent);
303282

304-
#if PHP_DEBUG
305-
/* -1 is also "true" */
306-
if (*threshold) {
307-
#endif
283+
if (*threshold == 0) {
284+
ret = NULL;
285+
} else {
308286
ret = perealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size), persistent);
309-
#if PHP_DEBUG
310287
--*threshold;
311-
} else if (*threshold == 0) {
312-
ret = NULL;
313288
}
289+
#else
290+
TRACE_ALLOC_ENTER(mysqlnd_perealloc_name);
291+
TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent);
292+
ret = perealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size), persistent);
314293
#endif
315294

316295
TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);
@@ -396,26 +375,22 @@ static void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D)
396375
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
397376
#if PHP_DEBUG
398377
zend_long * threshold = &MYSQLND_G(debug_malloc_fail_threshold);
399-
#endif
400378
TRACE_ALLOC_ENTER(mysqlnd_malloc_name);
401379

402-
#if PHP_DEBUG
403380
{
404381
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
405382
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
406383
}
407-
#endif
408384

409-
#if PHP_DEBUG
410-
/* -1 is also "true" */
411-
if (*threshold) {
412-
#endif
385+
if (*threshold == 0) {
386+
ret = NULL;
387+
} else {
413388
ret = malloc(REAL_SIZE(size));
414-
#if PHP_DEBUG
415389
--*threshold;
416-
} else if (*threshold == 0) {
417-
ret = NULL;
418390
}
391+
#else
392+
TRACE_ALLOC_ENTER(mysqlnd_malloc_name);
393+
ret = malloc(REAL_SIZE(size));
419394
#endif
420395

421396
TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
@@ -435,26 +410,22 @@ static void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
435410
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
436411
#if PHP_DEBUG
437412
zend_long * threshold = &MYSQLND_G(debug_calloc_fail_threshold);
438-
#endif
439413
TRACE_ALLOC_ENTER(mysqlnd_calloc_name);
440414

441-
#if PHP_DEBUG
442415
{
443416
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
444417
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
445418
}
446-
#endif
447419

448-
#if PHP_DEBUG
449-
/* -1 is also "true" */
450-
if (*threshold) {
451-
#endif
420+
if (*threshold == 0) {
421+
ret = NULL;
422+
} else {
452423
ret = calloc(nmemb, REAL_SIZE(size));
453-
#if PHP_DEBUG
454424
--*threshold;
455-
} else if (*threshold == 0) {
456-
ret = NULL;
457425
}
426+
#else
427+
TRACE_ALLOC_ENTER(mysqlnd_calloc_name);
428+
ret = calloc(nmemb, REAL_SIZE(size));
458429
#endif
459430

460431
TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
@@ -474,28 +445,26 @@ static void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D)
474445
zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
475446
#if PHP_DEBUG
476447
zend_long * threshold = &MYSQLND_G(debug_realloc_fail_threshold);
477-
#endif
478448
TRACE_ALLOC_ENTER(mysqlnd_realloc_name);
479449

480-
#if PHP_DEBUG
481450
{
482451
char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR);
483452
TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno);
484453
}
485-
#endif
486454
TRACE_ALLOC_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
487455
TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(TRUE));
488456

489-
#if PHP_DEBUG
490-
/* -1 is also "true" */
491-
if (*threshold) {
492-
#endif
457+
if (*threshold == 0) {
458+
ret = NULL;
459+
} else {
493460
ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size));
494-
#if PHP_DEBUG
495461
--*threshold;
496-
} else if (*threshold == 0) {
497-
ret = NULL;
498462
}
463+
#else
464+
TRACE_ALLOC_ENTER(mysqlnd_realloc_name);
465+
TRACE_ALLOC_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
466+
TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(TRUE));
467+
ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size));
499468
#endif
500469

501470
TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);

0 commit comments

Comments
 (0)