From 3200d99763b08cf4585adb6d7cb755bbcb4ac493 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 3 Jun 2014 21:15:02 +0000 Subject: [PATCH] Merge sapi/phpdbg into PHP-5.6 --- phpdbg.c | 47 +++++++++++++++++++++++++++++++++++------------ phpdbg_watch.c | 2 +- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/phpdbg.c b/phpdbg.c index fc121839e8..0239e692b4 100644 --- a/phpdbg.c +++ b/phpdbg.c @@ -879,6 +879,32 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) { } #endif +static inline zend_mm_heap *phpdbg_mm_get_heap() { + zend_mm_heap *mm_heap; + + TSRMLS_FETCH(); + + mm_heap = zend_mm_set_heap(NULL TSRMLS_CC); + zend_mm_set_heap(mm_heap TSRMLS_CC); + + return mm_heap; +} + +void *phpdbg_malloc_wrapper(size_t size) +{ + return zend_mm_alloc(phpdbg_mm_get_heap(), size); +} + +void phpdbg_free_wrapper(void *p) +{ + zend_mm_free(phpdbg_mm_get_heap(), p); +} + +void *phpdbg_realloc_wrapper(void *ptr, size_t size) +{ + return zend_mm_realloc(phpdbg_mm_get_heap(), ptr, size); +} + int main(int argc, char **argv) /* {{{ */ { sapi_module_struct *phpdbg = &phpdbg_sapi_module; @@ -1221,20 +1247,17 @@ phpdbg_main: EXCEPTION_POINTERS *xp; __try { #endif - zend_mm_heap *mm_heap = zend_mm_set_heap(NULL TSRMLS_CC); -#if ZEND_DEBUG - if (!mm_heap->use_zend_alloc) { - mm_heap->_malloc = malloc; - mm_heap->_realloc = realloc; - mm_heap->_free = free; -#endif - PHPDBG_G(original_free_function) = mm_heap->_free; - mm_heap->_free = phpdbg_watch_efree; + zend_mm_heap *mm_heap = phpdbg_mm_get_heap(); + + if (mm_heap->use_zend_alloc) { + mm_heap->_malloc = phpdbg_malloc_wrapper; + mm_heap->_realloc = phpdbg_realloc_wrapper; + mm_heap->_free = phpdbg_free_wrapper; mm_heap->use_zend_alloc = 0; -#if ZEND_DEBUG } -#endif - zend_mm_set_heap(mm_heap TSRMLS_CC); + + PHPDBG_G(original_free_function) = mm_heap->_free; + mm_heap->_free = phpdbg_watch_efree; zend_activate(TSRMLS_C); diff --git a/phpdbg_watch.c b/phpdbg_watch.c index 2efbb1237c..e88622444b 100644 --- a/phpdbg_watch.c +++ b/phpdbg_watch.c @@ -580,7 +580,7 @@ void phpdbg_setup_watchpoints(TSRMLS_D) { zend_llist_init(&PHPDBG_G(watchlist_mem), sizeof(void *), phpdbg_watch_mem_dtor, 1); phpdbg_btree_init(&PHPDBG_G(watchpoint_tree), sizeof(void *) * 8); phpdbg_btree_init(&PHPDBG_G(watch_HashTables), sizeof(void *) * 8); - _zend_hash_init(&PHPDBG_G(watchpoints), 8, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC); + zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC); } static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump TSRMLS_DC) { -- 2.40.0