From 2e3fc57c5c205e352a805830fd3ec4c7dbfa2efa Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Tue, 10 Nov 2015 14:25:06 +0100 Subject: MNDR: - move things out of mysqlnd_priv.h --- ext/mysqlnd/mysqlnd_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_alloc.c') diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index c28044ca7f..db1d0a22b7 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -12,8 +12,7 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | + | Authors: Andrey Hristov | | Ulf Wendel | +----------------------------------------------------------------------+ */ -- cgit v1.2.1 From 49493a2dcfb2cd1758b69b13d9006ead3be0e066 Mon Sep 17 00:00:00 2001 From: Lior Kaplan Date: Fri, 1 Jan 2016 19:19:27 +0200 Subject: Happy new year (Update copyright to 2016) --- ext/mysqlnd/mysqlnd_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mysqlnd/mysqlnd_alloc.c') diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index e1c39e28c3..396add5024 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 2006-2015 The PHP Group | + | Copyright (c) 2006-2016 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From a19173e4af5ee82dce9c9d8211a064e7f77c68d9 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Mon, 4 Jan 2016 16:48:35 +0100 Subject: - Make functions static, as they are not needed to be public - exported through a structure - Fixed typo in statistic name - Added 2 static functions for copying a MYSQLND_CSTRING and converting a CSTRING to STRING. --- ext/mysqlnd/mysqlnd_alloc.c | 91 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 22 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_alloc.c') diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index 89ddefcaf6..d5edeea834 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -38,6 +38,7 @@ static const char mysqlnd_malloc_name[] = "_mysqlnd_malloc"; static const char mysqlnd_calloc_name[] = "_mysqlnd_calloc"; static const char mysqlnd_realloc_name[] = "_mysqlnd_realloc"; static const char mysqlnd_free_name[] = "_mysqlnd_free"; +static const char mysqlnd_pememdup_name[] = "_mysqlnd_pememdup"; static const char mysqlnd_pestrndup_name[] = "_mysqlnd_pestrndup"; static const char mysqlnd_pestrdup_name[] = "_mysqlnd_pestrdup"; @@ -73,7 +74,7 @@ PHPAPI const char * mysqlnd_debug_std_no_trace_funcs[] = #define FAKE_PTR(p) (collect_memory_statistics && (p)? (((char *)(p)) + sizeof(size_t)) : (p)) /* {{{ _mysqlnd_emalloc */ -void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) +static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -113,7 +114,7 @@ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) /* {{{ _mysqlnd_pemalloc */ -void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) +static void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -156,7 +157,7 @@ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) /* {{{ _mysqlnd_ecalloc */ -void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) +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); @@ -197,7 +198,7 @@ void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) /* {{{ _mysqlnd_pecalloc */ -void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D) +static void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -239,7 +240,7 @@ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent M /* {{{ _mysqlnd_erealloc */ -void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) +static void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -280,7 +281,7 @@ void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) /* {{{ _mysqlnd_perealloc */ -void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D) +static void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -324,7 +325,7 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQL /* {{{ _mysqlnd_efree */ -void _mysqlnd_efree(void *ptr MYSQLND_MEM_D) +static void _mysqlnd_efree(void *ptr MYSQLND_MEM_D) { size_t free_amount = 0; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -355,7 +356,7 @@ void _mysqlnd_efree(void *ptr MYSQLND_MEM_D) /* {{{ _mysqlnd_pefree */ -void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D) +static void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D) { size_t free_amount = 0; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -387,7 +388,7 @@ void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D) /* {{{ _mysqlnd_malloc */ -void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D) +static void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -426,7 +427,7 @@ void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D) /* {{{ _mysqlnd_calloc */ -void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) +static void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -465,7 +466,7 @@ void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) /* {{{ _mysqlnd_realloc */ -void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D) +static void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D) { void *ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -507,7 +508,7 @@ void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D) /* {{{ _mysqlnd_free */ -void _mysqlnd_free(void *ptr MYSQLND_MEM_D) +static void _mysqlnd_free(void *ptr MYSQLND_MEM_D) { size_t free_amount = 0; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -536,13 +537,40 @@ void _mysqlnd_free(void *ptr MYSQLND_MEM_D) } /* }}} */ -#define SMART_STR_START_SIZE 2048 -#define SMART_STR_PREALLOC 512 -#include "zend_smart_str.h" + +/* {{{ _mysqlnd_pememdup */ +static char * _mysqlnd_pememdup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) +{ + char * ret; + zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); + TRACE_ALLOC_ENTER(mysqlnd_pememdup_name); + +#if PHP_DEBUG + { + char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + } +#endif + TRACE_ALLOC_INF_FMT("ptr=%p", ptr); + + ret = (persistent) ? __zend_malloc(REAL_SIZE(length + 1)) : _emalloc(REAL_SIZE(length + 1) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + { + char * dest = (char *) FAKE_PTR(ret); + memcpy(dest, ptr, length); + } + + if (collect_memory_statistics) { + *(size_t *) ret = length; + MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_DUP_COUNT : STAT_MEM_EDUP_COUNT); + } + + TRACE_ALLOC_RETURN(FAKE_PTR(ret)); +} +/* }}} */ /* {{{ _mysqlnd_pestrndup */ -char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) +static char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) { char * ret; zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics); @@ -577,8 +605,13 @@ char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_bool persi /* }}} */ +#define SMART_STR_START_SIZE 2048 +#define SMART_STR_PREALLOC 512 +#include "zend_smart_str.h" + + /* {{{ _mysqlnd_pestrdup */ -char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D) +static char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D) { char * ret; smart_str tmp_str = {0, 0}; @@ -611,7 +644,7 @@ char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_ME /* {{{ _mysqlnd_sprintf */ -PHPAPI int _mysqlnd_sprintf(char ** pbuf, size_t max_len, const char *format, ...) +static int _mysqlnd_sprintf(char ** pbuf, size_t max_len, const char *format, ...) { int len; va_list ap; @@ -624,14 +657,14 @@ PHPAPI int _mysqlnd_sprintf(char ** pbuf, size_t max_len, const char *format, .. /* {{{ _mysqlnd_sprintf_free */ -PHPAPI void _mysqlnd_sprintf_free(char * p) +static void _mysqlnd_sprintf_free(char * p) { efree(p); } /* }}} */ /* {{{ _mysqlnd_vsprintf */ -PHPAPI int _mysqlnd_vsprintf(char ** pbuf, size_t max_len, const char * format, va_list ap) +static int _mysqlnd_vsprintf(char ** pbuf, size_t max_len, const char * format, va_list ap) { return vspprintf(pbuf, max_len, format, ap); } @@ -738,6 +771,18 @@ static void mysqlnd_zend_mm_free(void * ptr MYSQLND_MEM_D) /* }}} */ +/* {{{ mysqlnd_zend_mm_pememdup */ +static char * mysqlnd_zend_mm_pememdup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) +{ + char * dest = pemalloc(length, persistent); + if (dest) { + memcpy(dest, ptr, length); + } + return dest; +} +/* }}} */ + + /* {{{ mysqlnd_zend_mm_pestrndup */ static char * mysqlnd_zend_mm_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) { @@ -771,6 +816,7 @@ PHPAPI struct st_mysqlnd_allocator_methods mysqlnd_allocator = _mysqlnd_calloc, _mysqlnd_realloc, _mysqlnd_free, + _mysqlnd_pememdup, _mysqlnd_pestrndup, _mysqlnd_pestrdup, _mysqlnd_sprintf, @@ -789,9 +835,10 @@ PHPAPI struct st_mysqlnd_allocator_methods mysqlnd_allocator = mysqlnd_zend_mm_calloc, mysqlnd_zend_mm_realloc, mysqlnd_zend_mm_free, + mysqlnd_zend_mm_pememdup, mysqlnd_zend_mm_pestrndup, - mysqlnd_zend_mm_pestrdup - sprintf, + mysqlnd_zend_mm_pestrdup, + vsprintf, mysqlnd_zend_mm_efree, #endif }; -- cgit v1.2.1 From 37418deb020772b8314527a7fcacd26f9c451a16 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Tue, 5 Jan 2016 16:28:33 +0100 Subject: Fix reloc for the allocator. Original files and lines were not showing correct. This seems to be a PHP7 issue. --- ext/mysqlnd/mysqlnd_alloc.c | 135 +++++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 64 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_alloc.c') diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index d5edeea834..2a0141c78b 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -25,6 +25,7 @@ #include "mysqlnd_wireprotocol.h" #include "mysqlnd_statistics.h" +#define MYSQLND_DEBUG_MEMORY 1 static const char mysqlnd_emalloc_name[] = "_mysqlnd_emalloc"; static const char mysqlnd_pemalloc_name[] = "_mysqlnd_pemalloc"; @@ -62,6 +63,8 @@ PHPAPI const char * mysqlnd_debug_std_no_trace_funcs[] = NULL /* must be always last */ }; +#if MYSQLND_DEBUG_MEMORY + #if ZEND_DEBUG #else @@ -85,8 +88,8 @@ static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif @@ -94,7 +97,7 @@ static void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D) /* -1 is also "true" */ if (*threshold) { #endif - ret = _emalloc(REAL_SIZE(size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = emalloc_rel(REAL_SIZE(size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -125,8 +128,8 @@ static void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif @@ -134,7 +137,7 @@ static void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) /* -1 is also "true" */ if (*threshold) { #endif - ret = (persistent) ? __zend_malloc(REAL_SIZE(size)) : _emalloc(REAL_SIZE(size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = pemalloc_rel(REAL_SIZE(size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -168,8 +171,8 @@ static void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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)); @@ -178,7 +181,7 @@ static void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) /* -1 is also "true" */ if (*threshold) { #endif - ret = _ecalloc(nmemb, REAL_SIZE(size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = ecalloc_rel(nmemb, REAL_SIZE(size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -208,8 +211,8 @@ static void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persi TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name); #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif @@ -217,7 +220,7 @@ static void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persi /* -1 is also "true" */ if (*threshold) { #endif - ret = (persistent) ? __zend_calloc(nmemb, REAL_SIZE(size)) : _ecalloc(nmemb, REAL_SIZE(size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = pecalloc_rel(nmemb, REAL_SIZE(size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -252,8 +255,8 @@ static void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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); @@ -262,7 +265,7 @@ static void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) /* -1 is also "true" */ if (*threshold) { #endif - ret = _erealloc(REAL_PTR(ptr), REAL_SIZE(new_size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = erealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size)); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -293,8 +296,8 @@ static void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persisten #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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); @@ -303,7 +306,7 @@ static void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persisten /* -1 is also "true" */ if (*threshold) { #endif - ret = perealloc(REAL_PTR(ptr), REAL_SIZE(new_size), persistent); + ret = perealloc_rel(REAL_PTR(ptr), REAL_SIZE(new_size), persistent); #if PHP_DEBUG --*threshold; } else if (*threshold == 0) { @@ -333,8 +336,8 @@ static void _mysqlnd_efree(void *ptr MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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", ptr); @@ -344,7 +347,7 @@ static void _mysqlnd_efree(void *ptr MYSQLND_MEM_D) free_amount = *(size_t *)(((char*)ptr) - sizeof(size_t)); TRACE_ALLOC_INF_FMT("ptr=%p size=%u", ((char*)ptr) - sizeof(size_t), (unsigned int) free_amount); } - _efree(REAL_PTR(ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + efree_rel(REAL_PTR(ptr)); } if (collect_memory_statistics) { @@ -364,8 +367,8 @@ static void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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 persistent=%u", ptr, persistent); @@ -375,7 +378,7 @@ static void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D) free_amount = *(size_t *)(((char*)ptr) - sizeof(size_t)); TRACE_ALLOC_INF_FMT("ptr=%p size=%u", ((char*)ptr) - sizeof(size_t), (unsigned int) free_amount); } - (persistent) ? free(REAL_PTR(ptr)) : _efree(REAL_PTR(ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + pefree_rel(REAL_PTR(ptr), persistent); } if (collect_memory_statistics) { @@ -399,8 +402,8 @@ static void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif @@ -438,8 +441,8 @@ static void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + char * fn = strrchr(__zend_filename, PHP_DIR_SEPARATOR); + TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_filename, __zend_lineno); } #endif @@ -477,8 +480,8 @@ static void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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); @@ -516,8 +519,8 @@ static void _mysqlnd_free(void *ptr MYSQLND_MEM_D) #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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", ptr); @@ -547,13 +550,13 @@ static char * _mysqlnd_pememdup(const char * const ptr, size_t length, zend_bool #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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", ptr); - ret = (persistent) ? __zend_malloc(REAL_SIZE(length + 1)) : _emalloc(REAL_SIZE(length + 1) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = pemalloc_rel(REAL_SIZE(length + 1), persistent); { char * dest = (char *) FAKE_PTR(ret); memcpy(dest, ptr, length); @@ -578,13 +581,13 @@ static char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_boo #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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", ptr); - ret = (persistent) ? __zend_malloc(REAL_SIZE(length + 1)) : _emalloc(REAL_SIZE(length + 1) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = pemalloc_rel(REAL_SIZE(length + 1), persistent); { size_t l = length; char * p = (char *) ptr; @@ -620,8 +623,8 @@ static char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYS TRACE_ALLOC_ENTER(mysqlnd_pestrdup_name); #if PHP_DEBUG { - char * fn = strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR); - TRACE_ALLOC_INF_FMT("file=%-15s line=%4d", fn? fn + 1:__zend_orig_filename, __zend_orig_lineno); + 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", ptr); @@ -629,7 +632,7 @@ static char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYS smart_str_appendc(&tmp_str, *p); } while (*p++); - ret = (persistent) ? __zend_malloc(ZSTR_LEN(tmp_str.s) + sizeof(size_t)) : _emalloc(REAL_SIZE(ZSTR_LEN(tmp_str.s) + sizeof(size_t)) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC); + ret = pemalloc_rel(ZSTR_LEN(tmp_str.s) + sizeof(size_t), persistent); memcpy(FAKE_PTR(ret), ZSTR_VAL(tmp_str.s), ZSTR_LEN(tmp_str.s)); if (ret && collect_memory_statistics) { @@ -643,6 +646,18 @@ static char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYS /* }}} */ + + +#endif /* MYSQLND_DEBUG_MEMORY */ + +/* {{{ _mysqlnd_sprintf_free */ +static void _mysqlnd_sprintf_free(char * p) +{ + efree(p); +} +/* }}} */ + + /* {{{ _mysqlnd_sprintf */ static int _mysqlnd_sprintf(char ** pbuf, size_t max_len, const char *format, ...) { @@ -655,14 +670,6 @@ static int _mysqlnd_sprintf(char ** pbuf, size_t max_len, const char *format, .. } /* }}} */ - -/* {{{ _mysqlnd_sprintf_free */ -static void _mysqlnd_sprintf_free(char * p) -{ - efree(p); -} -/* }}} */ - /* {{{ _mysqlnd_vsprintf */ static int _mysqlnd_vsprintf(char ** pbuf, size_t max_len, const char * format, va_list ap) { @@ -671,14 +678,13 @@ static int _mysqlnd_vsprintf(char ** pbuf, size_t max_len, const char * format, /* }}} */ -#define MYSQLND_DEBUG_MEMORY 1 #if MYSQLND_DEBUG_MEMORY == 0 /* {{{ mysqlnd_zend_mm_emalloc */ static void * mysqlnd_zend_mm_emalloc(size_t size MYSQLND_MEM_D) { - return emalloc(size); + return emalloc_rel(size); } /* }}} */ @@ -686,7 +692,7 @@ static void * mysqlnd_zend_mm_emalloc(size_t size MYSQLND_MEM_D) /* {{{ mysqlnd_zend_mm_pemalloc */ static void * mysqlnd_zend_mm_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D) { - return pemalloc(size, persistent); + return pemalloc_rel(size, persistent); } /* }}} */ @@ -694,7 +700,7 @@ static void * mysqlnd_zend_mm_pemalloc(size_t size, zend_bool persistent MYSQLND /* {{{ mysqlnd_zend_mm_ecalloc */ static void * mysqlnd_zend_mm_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D) { - return ecalloc(nmemb, size); + return ecalloc_rel(nmemb, size); } /* }}} */ @@ -702,7 +708,7 @@ static void * mysqlnd_zend_mm_ecalloc(unsigned int nmemb, size_t size MYSQLND_ME /* {{{ mysqlnd_zend_mm_pecalloc */ static void * mysqlnd_zend_mm_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D) { - return pecalloc(nmemb, size, persistent); + return pecalloc_rel(nmemb, size, persistent); } /* }}} */ @@ -710,7 +716,7 @@ static void * mysqlnd_zend_mm_pecalloc(unsigned int nmemb, size_t size, zend_boo /* {{{ mysqlnd_zend_mm_erealloc */ static void * mysqlnd_zend_mm_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) { - return erealloc(ptr, new_size); + return erealloc_rel(ptr, new_size); } /* }}} */ @@ -718,7 +724,7 @@ static void * mysqlnd_zend_mm_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D) /* {{{ mysqlnd_zend_mm_perealloc */ static void * mysqlnd_zend_mm_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D) { - return perealloc(ptr, new_size, persistent); + return perealloc_rel(ptr, new_size, persistent); } /* }}} */ @@ -726,7 +732,7 @@ static void * mysqlnd_zend_mm_perealloc(void *ptr, size_t new_size, zend_bool pe /* {{{ mysqlnd_zend_mm_efree */ static void mysqlnd_zend_mm_efree(void * ptr MYSQLND_MEM_D) { - efree(ptr); + efree_rel(ptr); } /* }}} */ @@ -734,7 +740,7 @@ static void mysqlnd_zend_mm_efree(void * ptr MYSQLND_MEM_D) /* {{{ mysqlnd_zend_mm_pefree */ static void mysqlnd_zend_mm_pefree(void * ptr, zend_bool persistent MYSQLND_MEM_D) { - pefree(ptr, persistent); + pefree_rel(ptr, persistent); } /* }}} */ @@ -774,7 +780,7 @@ static void mysqlnd_zend_mm_free(void * ptr MYSQLND_MEM_D) /* {{{ mysqlnd_zend_mm_pememdup */ static char * mysqlnd_zend_mm_pememdup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) { - char * dest = pemalloc(length, persistent); + char * dest = pemalloc_rel(length, persistent); if (dest) { memcpy(dest, ptr, length); } @@ -786,7 +792,7 @@ static char * mysqlnd_zend_mm_pememdup(const char * const ptr, size_t length, ze /* {{{ mysqlnd_zend_mm_pestrndup */ static char * mysqlnd_zend_mm_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D) { - return pestrndup(ptr, length, persistent); + return persistent? zend_strndup(ptr, length ) : estrndup_rel(ptr, length); } /* }}} */ @@ -794,7 +800,7 @@ static char * mysqlnd_zend_mm_pestrndup(const char * const ptr, size_t length, z /* {{{ mysqlnd_zend_mm_pestrdup */ static char * mysqlnd_zend_mm_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D) { - return pestrdup(ptr, persistent); + return pestrdup_rel(ptr, persistent); } /* }}} */ @@ -803,7 +809,7 @@ static char * mysqlnd_zend_mm_pestrdup(const char * const ptr, zend_bool persist PHPAPI struct st_mysqlnd_allocator_methods mysqlnd_allocator = { -#if MYSQLND_DEBUG_MEMORY +#if MYSQLND_DEBUG_MEMORY == 1 _mysqlnd_emalloc, _mysqlnd_pemalloc, _mysqlnd_ecalloc, @@ -838,8 +844,9 @@ PHPAPI struct st_mysqlnd_allocator_methods mysqlnd_allocator = mysqlnd_zend_mm_pememdup, mysqlnd_zend_mm_pestrndup, mysqlnd_zend_mm_pestrdup, - vsprintf, - mysqlnd_zend_mm_efree, + _mysqlnd_sprintf, + _mysqlnd_vsprintf, + _mysqlnd_sprintf_free, #endif }; -- cgit v1.2.1 From f2ab731a8c47d2988ddf0d61cb06c0f62e17ab19 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Wed, 16 Mar 2016 10:24:52 +0100 Subject: Fix emails in headers. @mysql.com addresses are no more since many years. --- ext/mysqlnd/mysqlnd_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_alloc.c') diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c index 696ab11a23..fb62a7b138 100644 --- a/ext/mysqlnd/mysqlnd_alloc.c +++ b/ext/mysqlnd/mysqlnd_alloc.c @@ -12,9 +12,9 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | - | Ulf Wendel | + | Authors: Andrey Hristov | + | Ulf Wendel | + | Georg Richter | +----------------------------------------------------------------------+ */ -- cgit v1.2.1