cvs: ZendEngine2(PHP_5_3) / zend_alloc.c zend_alloc.h

From: Date: Tue, 06 Nov 2007 07:22:13 +0000
Subject: cvs: ZendEngine2(PHP_5_3) / zend_alloc.c zend_alloc.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-6126@lists.php.net to get a copy of this message
dmitry Tue Nov 6 07:22:13 2007 UTC Modified files: (Branch: PHP_5_3) /ZendEngine2 zend_alloc.c zend_alloc.h Log: Allow user defined malloc/realloc/free http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.144.2.3.2.43.2.2&r2=1.144.2.3.2.43.2.3&diff_format=u Index: ZendEngine2/zend_alloc.c diff -u ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.2 ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.3 --- ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.2 Thu Oct 25 07:32:40 2007 +++ ZendEngine2/zend_alloc.c Tue Nov 6 07:22:13 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.2 2007/10/25 07:32:40 dmitry Exp $ */ +/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.3 2007/11/06 07:22:13 dmitry Exp $ */ #include "zend.h" #include "zend_alloc.h" @@ -403,6 +403,9 @@ struct _zend_mm_heap { int use_zend_alloc; + void *(*malloc)(size_t); + void (*free)(void*); + void *(*realloc)(void*, size_t); size_t free_bitmap; size_t large_free_bitmap; size_t block_size; @@ -2264,7 +2267,7 @@ TSRMLS_FETCH(); if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) { - return malloc(size); + return AG(mm_heap)->malloc(size); } return _zend_mm_alloc_int(AG(mm_heap), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); } @@ -2274,7 +2277,7 @@ TSRMLS_FETCH(); if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) { - free(ptr); + AG(mm_heap)->free(ptr); return; } _zend_mm_free_int(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); @@ -2285,7 +2288,7 @@ TSRMLS_FETCH(); if (UNEXPECTED(!AG(mm_heap)->use_zend_alloc)) { - return realloc(ptr, size); + return AG(mm_heap)->realloc(ptr, size); } return _zend_mm_realloc_int(AG(mm_heap), ptr, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); } @@ -2452,6 +2455,11 @@ tmp = getenv("USE_ZEND_ALLOC"); if (tmp) { alloc_globals->mm_heap->use_zend_alloc = zend_atoi(tmp, 0); + if (!alloc_globals->mm_heap->use_zend_alloc) { + alloc_globals->mm_heap->malloc = malloc; + alloc_globals->mm_heap->free = free; + alloc_globals->mm_heap->realloc = realloc; + } } } @@ -2485,6 +2493,17 @@ return heap->storage; } +ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap, + void* (*malloc)(size_t), + void (*free)(void*), + void* (realloc)(void*, size_t)) +{ + heap->use_zend_alloc = 0; + heap->malloc = malloc; + heap->free = free; + heap->realloc = realloc; +} + #if ZEND_DEBUG ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) { http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.h?r1=1.63.2.2.2.12.2.1&r2=1.63.2.2.2.12.2.2&diff_format=u Index: ZendEngine2/zend_alloc.h diff -u ZendEngine2/zend_alloc.h:1.63.2.2.2.12.2.1 ZendEngine2/zend_alloc.h:1.63.2.2.2.12.2.2 --- ZendEngine2/zend_alloc.h:1.63.2.2.2.12.2.1 Sat Sep 29 10:37:29 2007 +++ ZendEngine2/zend_alloc.h Tue Nov 6 07:22:13 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.h,v 1.63.2.2.2.12.2.1 2007/09/29 10:37:29 dmitry Exp $ */ +/* $Id: zend_alloc.h,v 1.63.2.2.2.12.2.2 2007/11/06 07:22:13 dmitry Exp $ */ #ifndef ZEND_ALLOC_H #define ZEND_ALLOC_H @@ -233,6 +233,11 @@ ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap TSRMLS_DC); ZEND_API zend_mm_storage *zend_mm_get_storage(zend_mm_heap *heap); +ZEND_API void zend_mm_set_custom_handlers(zend_mm_heap *heap, + void* (*malloc)(size_t), + void (*free)(void*), + void* (realloc)(void*, size_t)); + #endif /*

« previous php.zend-engine.cvs (#6126) next »