summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_debug.c
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2010-04-22 16:28:50 +0000
committerAndrey Hristov <andrey@php.net>2010-04-22 16:28:50 +0000
commit4842f96e2d45c301ac38f8ebb265e996d26a4af2 (patch)
treee19523bd81a0a31e90a39cd414d8f25bf1a16bb1 /ext/mysqlnd/mysqlnd_debug.c
parent5431f235db6b6c6c46d32a98567a2b7919fd843f (diff)
downloadphp-git-4842f96e2d45c301ac38f8ebb265e996d26a4af2.tar.gz
Change the way the allocator is called - through an abstraction
to give the possibility of pluggability. Thanks to the macros already used the changes are not pervasive.
Diffstat (limited to 'ext/mysqlnd/mysqlnd_debug.c')
-rw-r--r--ext/mysqlnd/mysqlnd_debug.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c
index 3ea5e0584e..e1a01acc08 100644
--- a/ext/mysqlnd/mysqlnd_debug.c
+++ b/ext/mysqlnd/mysqlnd_debug.c
@@ -28,6 +28,59 @@
#include "mysqlnd_statistics.h"
#include "zend_builtin_functions.h"
+static void * mysqlnd_zend_mm_emalloc(size_t size MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
+static void mysqlnd_zend_mm_efree(void * ptr MYSQLND_MEM_D);
+static void mysqlnd_zend_mm_pefree(void * ptr, zend_bool persistent MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_malloc(size_t size MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
+static void * mysqlnd_zend_mm_realloc(void * ptr, size_t new_size MYSQLND_MEM_D);
+static void mysqlnd_zend_mm_free(void * ptr MYSQLND_MEM_D);
+static char * mysqlnd_zend_mm_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D);
+static char * mysqlnd_zend_mm_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
+
+#define MYSQLND_DEBUG_MEMORY 1
+
+struct st_mysqlnd_allocator_methods mysqlnd_allocator =
+{
+#if MYSQLND_DEBUG_MEMORY
+ _mysqlnd_emalloc,
+ _mysqlnd_pemalloc,
+ _mysqlnd_ecalloc,
+ _mysqlnd_pecalloc,
+ _mysqlnd_erealloc,
+ _mysqlnd_perealloc,
+ _mysqlnd_efree,
+ _mysqlnd_pefree,
+ _mysqlnd_malloc,
+ _mysqlnd_calloc,
+ _mysqlnd_realloc,
+ _mysqlnd_free,
+ _mysqlnd_pestrndup,
+ _mysqlnd_pestrdup
+#else
+ mysqlnd_zend_mm_emalloc,
+ mysqlnd_zend_mm_pemalloc,
+ mysqlnd_zend_mm_ecalloc,
+ mysqlnd_zend_mm_pecalloc,
+ mysqlnd_zend_mm_erealloc,
+ mysqlnd_zend_mm_perealloc,
+ mysqlnd_zend_mm_efree,
+ mysqlnd_zend_mm_pefree,
+ mysqlnd_zend_mm_malloc,
+ mysqlnd_zend_mm_calloc,
+ mysqlnd_zend_mm_realloc,
+ mysqlnd_zend_mm_free,
+ mysqlnd_zend_mm_pestrndup,
+ mysqlnd_zend_mm_pestrdup
+#endif
+};
+
+
static const char * const mysqlnd_debug_default_trace_file = "/tmp/mysqlnd.trace";
@@ -994,6 +1047,118 @@ char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_ME
/* }}} */
+/* {{{ mysqlnd_zend_mm_emalloc */
+static void * mysqlnd_zend_mm_emalloc(size_t size MYSQLND_MEM_D)
+{
+ return emalloc(size);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_pemalloc */
+static void * mysqlnd_zend_mm_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D)
+{
+ return pemalloc(size, persistent);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_ecalloc */
+static void * mysqlnd_zend_mm_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
+{
+ return ecalloc(nmemb, size);
+}
+/* }}} */
+
+
+/* {{{ 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);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_erealloc */
+static void * mysqlnd_zend_mm_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D)
+{
+ return erealloc(ptr, new_size);
+}
+/* }}} */
+
+
+/* {{{ 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);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_efree */
+static void mysqlnd_zend_mm_efree(void * ptr MYSQLND_MEM_D)
+{
+ efree(ptr);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_pefree */
+static void mysqlnd_zend_mm_pefree(void * ptr, zend_bool persistent MYSQLND_MEM_D)
+{
+ pefree(ptr, persistent);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_malloc */
+static void * mysqlnd_zend_mm_malloc(size_t size MYSQLND_MEM_D)
+{
+ return malloc(size);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_calloc */
+static void * mysqlnd_zend_mm_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
+{
+ return calloc(nmemb, size);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_realloc */
+static void * mysqlnd_zend_mm_realloc(void * ptr, size_t new_size MYSQLND_MEM_D)
+{
+ return realloc(ptr, new_size);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_free */
+static void mysqlnd_zend_mm_free(void * ptr MYSQLND_MEM_D)
+{
+ free(ptr);
+}
+/* }}} */
+
+
+/* {{{ 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);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_zend_mm_pestrdup */
+static char * mysqlnd_zend_mm_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D)
+{
+ return pestrdup(ptr, persistent);
+}
+/* }}} */
+
+
/* Follows code borrowed from zend_builtin_functions.c because the functions there are static */