For Programmers: Free Programming Magazines  


Home > Archive > PHP Zend Engine > July 2007 > cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h /tests bug40509.phpt bug40705.php









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cvs: ZendEngine2 / zend_vm_def.h zend_vm_execute.h /tests bug40509.phpt bug40705.php
Dmitry Stogov

2007-07-24, 6:57 pm

dmitry Tue Jul 24 19:24:56 2007 UTC

Modified files:
/ZendEngine2 zend_vm_def.h zend_vm_execute.h
/ZendEngine2/tests bug40509.phpt bug40705.phpt
Log:
Fixed bug #40705 (Iterating within function moves original array pointer)
Fixed bug #40509 (key() function changed behaviour if global array is used within function)


http://cvs.php.net/viewvc.cgi/ZendE...4&diff_format=u
Index: ZendEngine2/zend_vm_def.h
diff -u ZendEngine2/zend_vm_def.h:1.173 ZendEngine2/zend_vm_def.h:1.174
--- ZendEngine2/zend_vm_def.h:1.173 Sat Jul 21 05:27:07 2007
+++ ZendEngine2/zend_vm_def.h Tue Jul 24 19:24:56 2007
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/

-/* $Id: zend_vm_def.h,v 1.173 2007/07/21 05:27:07 pollita Exp $ */
+/* $Id: zend_vm_def.h,v 1.174 2007/07/24 19:24:56 dmitry Exp $ */

/* If you change this file, please regenerate the zend_vm_execute.h and
* zend_vm_opcodes.h files by running:
@@ -3324,11 +3324,9 @@
array_ptr->refcount++;
}
} else {
- if (OP1_TYPE == IS_VAR &&
- free_op1.var == NULL &&
+ if ((OP1_TYPE == IS_VAR || OP1_TYPE == IS_CV) &&
!array_ptr->is_ref &&
array_ptr->refcount > 1) {
- /* non-separated return value from function */
zval *tmp;

ALLOC_ZVAL(tmp);
http://cvs.php.net/viewvc.cgi/ZendE...8&diff_format=u
Index: ZendEngine2/zend_vm_execute.h
diff -u ZendEngine2/zend_vm_execute.h:1.177 ZendEngine2/zend_vm_execute.h:1.178
--- ZendEngine2/zend_vm_execute.h:1.177 Sat Jul 21 05:27:07 2007
+++ ZendEngine2/zend_vm_execute.h Tue Jul 24 19:24:56 2007
@@ -1969,7 +1969,7 @@
static int ZEND_FE_RESET_SPEC_CONST_HANDLER(ZEND_OP
CODE_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;
@@ -2016,11 +2016,9 @@
array_ptr->refcount++;
}
} else {
- if (IS_CONST == IS_VAR &&
- free_op1.var == NULL &&
+ if ((IS_CONST == IS_VAR || IS_CONST == IS_CV) &&
!array_ptr->is_ref &&
array_ptr->refcount > 1) {
- /* non-separated return value from function */
zval *tmp;

ALLOC_ZVAL(tmp);
@@ -5176,11 +5174,9 @@
array_ptr->refcount++;
}
} else {
- if (IS_TMP_VAR == IS_VAR &&
- free_op1.var == NULL &&
+ if ((IS_TMP_VAR == IS_VAR || IS_TMP_VAR == IS_CV) &&
!array_ptr->is_ref &&
array_ptr->refcount > 1) {
- /* non-separated return value from function */
zval *tmp;

ALLOC_ZVAL(tmp);
@@ -8446,11 +8442,9 @@
array_ptr->refcount++;
}
} else {
- if (IS_VAR == IS_VAR &&
- free_op1.var == NULL &&
+ if ((IS_VAR == IS_VAR || IS_VAR == IS_CV) &&
!array_ptr->is_ref &&
array_ptr->refcount > 1) {
- /* non-separated return value from function */
zval *tmp;

ALLOC_ZVAL(tmp);
@@ -21620,7 +21614,7 @@
static int ZEND_FE_RESET_SPEC_CV_HANDLER(ZEND_OPCOD
E_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;
@@ -21667,11 +21661,9 @@
array_ptr->refcount++;
}
} else {
- if (IS_CV == IS_VAR &&
- free_op1.var == NULL &&
+ if ((IS_CV == IS_VAR || IS_CV == IS_CV) &&
!array_ptr->is_ref &&
array_ptr->refcount > 1) {
- /* non-separated return value from function */
zval *tmp;

ALLOC_ZVAL(tmp);
http://cvs.php.net/viewvc.cgi/ZendE...2&diff_format=u
Index: ZendEngine2/tests/bug40509.phpt
diff -u /dev/null ZendEngine2/tests/bug40509.phpt:1.2
--- /dev/null Tue Jul 24 19:24:56 2007
+++ ZendEngine2/tests/bug40509.phpt Tue Jul 24 19:24:56 2007
@@ -0,0 +1,26 @@
+--TEST--
+Bug #40509 key() function changed behaviour if global array is used within function
+--FILE--
+<?php
+function foo()
+{
+ global $arr;
+
+ $c = $arr["v"];
+ foreach ($c as $v) {}
+}
+
+$arr["v"] = array("a");
+
+var_dump(key($arr["v"]));
+foo();
+var_dump(key($arr["v"]));
+foreach ($arr["v"] as $k => $v) {
+ var_dump($k);
+}
+var_dump(key($arr["v"]));
+--EXPECT--
+int(0)
+int(0)
+int(0)
+NULL
http://cvs.php.net/viewvc.cgi/ZendE...2&diff_format=u
Index: ZendEngine2/tests/bug40705.phpt
diff -u /dev/null ZendEngine2/tests/bug40705.phpt:1.2
--- /dev/null Tue Jul 24 19:24:56 2007
+++ ZendEngine2/tests/bug40705.phpt Tue Jul 24 19:24:56 2007
@@ -0,0 +1,26 @@
+--TEST--
+Bug #40705 Iterating within function moves original array pointer
+--FILE--
+<?php
+function doForeach($array)
+{
+ foreach ($array as $k => $v) {
+ // do stuff
+ }
+}
+
+$foo = array('foo', 'bar', 'baz');
+var_dump(key($foo));
+doForeach($foo);
+var_dump(key($foo));
+foreach ($foo as $k => $v) {
+ var_dump($k);
+}
+var_dump(key($foo));
+--EXPECT--
+int(0)
+int(0)
+int(0)
+int(1)
+int(2)
+NULL
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com