]> granicus.if.org Git - php/commitdiff
Fix warnings in mysqlnd_alloc.c
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 12 Jun 2019 10:28:51 +0000 (12:28 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 12 Jun 2019 11:17:25 +0000 (13:17 +0200)
And also separate the PHP_DEBUG codepaths more, to avoids having an
ifdef every other line...

ext/mysqlnd/mysqlnd_alloc.c

index 980dd074841d05d34b701ce887bcb9fd9ea82b16..a1471dd557e51793d68b0a9b194694cbc92fe58a 100644 (file)
@@ -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);