cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h /tests bug37046.phpt

From: Date: Wed, 12 Apr 2006 11:38:09 +0000
Subject: cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h /tests bug37046.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-4807@lists.php.net to get a copy of this message
dmitry Wed Apr 12 11:38:09 2006 UTC Modified files: /ZendEngine2 zend_vm_def.h zend_vm_execute.h /ZendEngine2/tests bug37046.phpt Log: Fixed bug #37046 (foreach breaks static scope) http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_def.h?r1=1.109&r2=1.110&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.109 ZendEngine2/zend_vm_def.h:1.110 --- ZendEngine2/zend_vm_def.h:1.109 Mon Apr 10 23:15:26 2006 +++ ZendEngine2/zend_vm_def.h Wed Apr 12 11:38:08 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.109 2006/04/10 23:15:26 helly Exp $ */ +/* $Id: zend_vm_def.h,v 1.110 2006/04/12 11:38:08 dmitry Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -3096,7 +3096,20 @@ } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); } else { - array_ptr->refcount++; + if (OP1_TYPE == IS_VAR && + free_op1.var == NULL && + !array_ptr->is_ref && + array_ptr->refcount > 1) { + /* non-separated return value from function */ + zval *tmp; + + ALLOC_ZVAL(tmp); + INIT_PZVAL_COPY(tmp, array_ptr); + zval_copy_ctor(tmp); + array_ptr = tmp; + } else { + array_ptr->refcount++; + } } } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_execute.h?r1=1.113&r2=1.114&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.113 ZendEngine2/zend_vm_execute.h:1.114 --- ZendEngine2/zend_vm_execute.h:1.113 Mon Apr 10 23:15:26 2006 +++ ZendEngine2/zend_vm_execute.h Wed Apr 12 11:38:08 2006 @@ -2030,7 +2030,7 @@ static int ZEND_FE_RESET_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { zend_op *opline = EX(opline); - + zend_free_op free_op1; zval *array_ptr, **array_ptr_ptr; HashTable *fe_ht; zend_object_iterator *iter = NULL; @@ -2071,7 +2071,20 @@ } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); } else { - array_ptr->refcount++; + if (IS_CONST == IS_VAR && + free_op1.var == NULL && + !array_ptr->is_ref && + array_ptr->refcount > 1) { + /* non-separated return value from function */ + zval *tmp; + + ALLOC_ZVAL(tmp); + INIT_PZVAL_COPY(tmp, array_ptr); + zval_copy_ctor(tmp); + array_ptr = tmp; + } else { + array_ptr->refcount++; + } } } @@ -4554,7 +4567,20 @@ } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); } else { - array_ptr->refcount++; + if (IS_TMP_VAR == IS_VAR && + free_op1.var == NULL && + !array_ptr->is_ref && + array_ptr->refcount > 1) { + /* non-separated return value from function */ + zval *tmp; + + ALLOC_ZVAL(tmp); + INIT_PZVAL_COPY(tmp, array_ptr); + zval_copy_ctor(tmp); + array_ptr = tmp; + } else { + array_ptr->refcount++; + } } } @@ -7634,7 +7660,20 @@ } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); } else { - array_ptr->refcount++; + if (IS_VAR == IS_VAR && + free_op1.var == NULL && + !array_ptr->is_ref && + array_ptr->refcount > 1) { + /* non-separated return value from function */ + zval *tmp; + + ALLOC_ZVAL(tmp); + INIT_PZVAL_COPY(tmp, array_ptr); + zval_copy_ctor(tmp); + array_ptr = tmp; + } else { + array_ptr->refcount++; + } } } @@ -20213,7 +20252,7 @@ static int ZEND_FE_RESET_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS) { zend_op *opline = EX(opline); - + zend_free_op free_op1; zval *array_ptr, **array_ptr_ptr; HashTable *fe_ht; zend_object_iterator *iter = NULL; @@ -20254,7 +20293,20 @@ } else if (Z_TYPE_P(array_ptr) == IS_OBJECT) { ce = Z_OBJCE_P(array_ptr); } else { - array_ptr->refcount++; + if (IS_CV == IS_VAR && + free_op1.var == NULL && + !array_ptr->is_ref && + array_ptr->refcount > 1) { + /* non-separated return value from function */ + zval *tmp; + + ALLOC_ZVAL(tmp); + INIT_PZVAL_COPY(tmp, array_ptr); + zval_copy_ctor(tmp); + array_ptr = tmp; + } else { + array_ptr->refcount++; + } } } http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/bug37046.phpt?r1=1.1&r2=1.2&diff_format=u Index: ZendEngine2/tests/bug37046.phpt diff -u /dev/null ZendEngine2/tests/bug37046.phpt:1.2 --- /dev/null Wed Apr 12 11:38:09 2006 +++ ZendEngine2/tests/bug37046.phpt Wed Apr 12 11:38:09 2006 @@ -0,0 +1,23 @@ +--TEST-- +Bug #37046 (foreach breaks static scope) +--FILE-- +<?php +function s() { + static $storage = array(array('x', 'y')); + return $storage[0]; +} + +foreach (s() as $k => $function) { + echo "op1 $k\n"; + if ($k == 0) { + foreach (s() as $k => $function) { + echo "op2 $k\n"; + } + } +} +?> +--EXPEXT-- +op1 0 +op2 0 +op2 1 +op1 1

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