cvs: pecl /apc apc_compile.c apc_globals.h php_apc.c

From: Date: Tue, 17 Oct 2006 06:11:25 +0000
Subject: cvs: pecl /apc apc_compile.c apc_globals.h php_apc.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6493@lists.php.net to get a copy of this message
shire Tue Oct 17 06:11:25 2006 UTC Modified files: /pecl/apc apc_compile.c apc_globals.h php_apc.c Log: Enable recursive array structures, bug #6362 http://cvs.php.net/viewvc.cgi/pecl/apc/apc_compile.c?r1=3.61&r2=3.62&diff_format=u Index: pecl/apc/apc_compile.c diff -u pecl/apc/apc_compile.c:3.61 pecl/apc/apc_compile.c:3.62 --- pecl/apc/apc_compile.c:3.61 Thu Oct 12 20:25:44 2006 +++ pecl/apc/apc_compile.c Tue Oct 17 06:11:25 2006 @@ -28,7 +28,7 @@ */ -/* $Id: apc_compile.c,v 3.61 2006/10/12 20:25:44 gopalv Exp $ */ +/* $Id: apc_compile.c,v 3.62 2006/10/17 06:11:25 shire Exp $ */ #include "apc_compile.h" #include "apc_globals.h" @@ -241,7 +241,8 @@ static zval** my_copy_zval_ptr(zval** dst, const zval** src, apc_malloc_t allocate, apc_free_t deallocate) { int local_dst_alloc = 0; - + zval* dst_new; + assert(src != NULL); if (!dst) { @@ -253,7 +254,15 @@ if(local_dst_alloc) deallocate(dst); return NULL; } - if(!my_copy_zval(*dst, *src, allocate, deallocate)) return NULL; + dst_new = my_copy_zval(*dst, *src, allocate, deallocate); + if(!dst) { + deallocate(dst); + return NULL; + } + if(dst_new != *dst) { + deallocate(*dst); + *dst = dst_new; + } /* deep-copying ensures that there is only one reference to this in memory */ (*dst)->refcount = 1; @@ -266,9 +275,26 @@ /* {{{ my_copy_zval */ static zval* my_copy_zval(zval* dst, const zval* src, apc_malloc_t allocate, apc_free_t deallocate) { + zval **tmp; + int destroy_zvallist = 0; + TSRMLS_FETCH(); + assert(dst != NULL); assert(src != NULL); + /* Maintain a list of zvals we've copied to properly handle recursive structures */ + if(!APCG(copied_zvals)) { + APCG(copied_zvals) = emalloc(sizeof(HashTable)); + zend_hash_init(APCG(copied_zvals), 0, NULL, NULL, 0); + destroy_zvallist = 1; + } else { + if(zend_hash_index_find(APCG(copied_zvals), (ulong)src, (void**)&tmp) == SUCCESS) { + (*tmp)->refcount++; + return *tmp; + } + } + zend_hash_index_update(APCG(copied_zvals), (ulong)src, (void**)&dst, sizeof(zval*), NULL); + memcpy(dst, src, sizeof(src[0])); switch (src->type & ~IS_CONSTANT_INDEX) { @@ -314,6 +340,11 @@ 1, allocate, deallocate))) { my_destroy_class_entry(dst->value.obj.ce, deallocate); + if(destroy_zvallist) { + zend_hash_destroy(APCG(copied_zvals)); + efree(APCG(copied_zvals)); + APCG(copied_zvals) = NULL; + } return NULL; } break; @@ -326,6 +357,12 @@ assert(0); } + if(destroy_zvallist) { + zend_hash_destroy(APCG(copied_zvals)); + efree(APCG(copied_zvals)); + APCG(copied_zvals) = NULL; + } + return dst; } /* }}} */ @@ -1029,7 +1066,8 @@ local_dst_alloc = 1; } - if(!my_copy_zval(dst, src, allocate, deallocate)) { + dst = my_copy_zval(dst, src, allocate, deallocate); + if(!dst) { if(local_dst_alloc) deallocate(dst); return NULL; } http://cvs.php.net/viewvc.cgi/pecl/apc/apc_globals.h?r1=3.50&r2=3.51&diff_format=u Index: pecl/apc/apc_globals.h diff -u pecl/apc/apc_globals.h:3.50 pecl/apc/apc_globals.h:3.51 --- pecl/apc/apc_globals.h:3.50 Sun Sep 17 09:09:24 2006 +++ pecl/apc/apc_globals.h Tue Oct 17 06:11:25 2006 @@ -29,7 +29,7 @@ */ -/* $Id: apc_globals.h,v 3.50 2006/09/17 09:09:24 rasmus Exp $ */ +/* $Id: apc_globals.h,v 3.51 2006/10/17 06:11:25 shire Exp $ */ #ifndef APC_GLOBALS_H #define APC_GLOBALS_H @@ -74,6 +74,7 @@ #ifdef MULTIPART_EVENT_FORMDATA zend_bool rfc1867; /* Flag to enable rfc1867 handler */ #endif + HashTable *copied_zvals; /* my_copy recursion detection list */ ZEND_END_MODULE_GLOBALS(apc) /* (the following declaration is defined in php_apc.c) */ http://cvs.php.net/viewvc.cgi/pecl/apc/php_apc.c?r1=3.115&r2=3.116&diff_format=u Index: pecl/apc/php_apc.c diff -u pecl/apc/php_apc.c:3.115 pecl/apc/php_apc.c:3.116 --- pecl/apc/php_apc.c:3.115 Fri Sep 29 08:12:20 2006 +++ pecl/apc/php_apc.c Tue Oct 17 06:11:25 2006 @@ -26,7 +26,7 @@ */ -/* $Id: php_apc.c,v 3.115 2006/09/29 08:12:20 shire Exp $ */ +/* $Id: php_apc.c,v 3.116 2006/10/17 06:11:25 shire Exp $ */ #include "apc_zend.h" #include "apc_cache.h" @@ -81,6 +81,7 @@ #ifdef MULTIPART_EVENT_FORMDATA apc_globals->rfc1867 = 0; #endif + apc_globals->copied_zvals = NULL; } static void php_apc_shutdown_globals(zend_apc_globals* apc_globals TSRMLS_DC) @@ -166,7 +167,7 @@ #else php_info_print_table_row(2, "Locking type", "File Locks"); #endif - php_info_print_table_row(2, "Revision", "$Revision: 3.115 $"); + php_info_print_table_row(2, "Revision", "$Revision: 3.116 $"); php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__); php_info_print_table_end(); DISPLAY_INI_ENTRIES();

« previous php.pecl.cvs (#6493) next »