cvs: ZendEngine2 / zend_alloc.c zend_alloc.h

From: Date: Tue, 06 Nov 2007 07:37:50 +0000
Subject: cvs: ZendEngine2 / zend_alloc.c zend_alloc.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-6128@lists.php.net to get a copy of this message
dmitry Tue Nov 6 07:37:50 2007 UTC Modified files: /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.205&r2=1.206&diff_format=u Index: ZendEngine2/zend_alloc.c diff -u ZendEngine2/zend_alloc.c:1.205 ZendEngine2/zend_alloc.c:1.206 --- ZendEngine2/zend_alloc.c:1.205 Thu Oct 25 07:32:58 2007 +++ ZendEngine2/zend_alloc.c Tue Nov 6 07:37:50 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.c,v 1.205 2007/10/25 07:32:58 dmitry Exp $ */ +/* $Id: zend_alloc.c,v 1.206 2007/11/06 07:37:50 dmitry Exp $ */ #include "zend.h" #include "zend_alloc.h" @@ -423,6 +423,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; @@ -2306,7 +2309,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); } @@ -2317,7 +2320,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); @@ -2329,7 +2332,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); } @@ -2591,6 +2594,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; + } } } /* }}} */ @@ -2629,6 +2637,17 @@ } /* }}} */ +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.90&r2=1.91&diff_format=u Index: ZendEngine2/zend_alloc.h diff -u ZendEngine2/zend_alloc.h:1.90 ZendEngine2/zend_alloc.h:1.91 --- ZendEngine2/zend_alloc.h:1.90 Sat Sep 29 10:37:39 2007 +++ ZendEngine2/zend_alloc.h Tue Nov 6 07:37:50 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.h,v 1.90 2007/09/29 10:37:39 dmitry Exp $ */ +/* $Id: zend_alloc.h,v 1.91 2007/11/06 07:37:50 dmitry Exp $ */ #ifndef ZEND_ALLOC_H #define ZEND_ALLOC_H @@ -226,6 +226,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 (#6128) next »