diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-12 12:28:51 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-06-12 13:17:25 +0200 |
commit | 3e4b9659d33d4c2eaf4e11a7917f5d9d2355aed1 (patch) | |
tree | 5f0cc576ed2159a4507e2d02510e4d5e49e30679 | |
parent | 9fa552f3935f29371102f784b1bbfde753253aed (diff) | |
download | php-git-3e4b9659d33d4c2eaf4e11a7917f5d9d2355aed1.tar.gz |
Fix warnings in mysqlnd_alloc.c
And also separate the PHP_DEBUG codepaths more, to avoids having an
ifdef every other line...
-rw-r--r-- | ext/mysqlnd/mysqlnd_alloc.c | 151 |
1 files changed, 60 insertions, 91 deletions
diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index 980dd07484..a1471dd557 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -82,26 +82,22 @@ static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_emalloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_emalloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = emalloc_rel(REAL_SIZE(size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_emalloc_name); + ret = emalloc_rel(REAL_SIZE(size)); #endif 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) zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = persistent? &MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = pemalloc_rel(REAL_SIZE(size), persistent); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name); + ret = pemalloc_rel(REAL_SIZE(size), persistent); #endif 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) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); -#if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold); -#endif +#if PHP_DEBUG TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE)); -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = ecalloc_rel(nmemb, REAL_SIZE(size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name); + TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE)); + ret = ecalloc_rel(nmemb, REAL_SIZE(size)); #endif 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 zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = persistent? &MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = pecalloc_rel(nmemb, REAL_SIZE(size), persistent); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name); + ret = pecalloc_rel(nmemb, REAL_SIZE(size), persistent); #endif 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) size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0; #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_erealloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size); -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_erealloc_name); + TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size); + ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size)); #endif 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 size_t old_size = collect_memory_statistics && ptr? *(size_t *) (((char*)ptr) - sizeof(size_t)) : 0; #if PHP_DEBUG zend_long * threshold = persistent? &MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_perealloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent); -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = perealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size), persistent); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_perealloc_name); + TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr, old_size, new_size, persistent); + ret = perealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size), persistent); #endif TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret); @@ -396,26 +375,22 @@ static void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D) zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_malloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_malloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = malloc(REAL_SIZE(size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_malloc_name); + ret = malloc(REAL_SIZE(size)); #endif 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) zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_calloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_calloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = calloc(nmemb, REAL_SIZE(size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_calloc_name); + ret = calloc(nmemb, REAL_SIZE(size)); #endif 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) zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); #if PHP_DEBUG zend_long * threshold = &MYSQLND_G(debug_realloc_fail_threshold); -#endif TRACE_ALLOC_ENTER(mysqlnd_realloc_name); -#if PHP_DEBUG { char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } -#endif TRACE_ALLOC_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr); TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(TRUE)); -#if PHP_DEBUG - /* -1 is also "true" */ - if (*threshold) { -#endif + if (*threshold == 0) { + ret = NULL; + } else { ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size)); -#if PHP_DEBUG --*threshold; - } else if (*threshold == 0) { - ret = NULL; } +#else + TRACE_ALLOC_ENTER(mysqlnd_realloc_name); + TRACE_ALLOC_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr); + TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(TRUE)); + ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size)); #endif TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret); |