cvs: ZendEngine2 / zend.h zend_compile.c zend_compile.h zend_execute.c zend_interfaces.c zend_interfaces.h zend_iterators.h zend_vm_def.h
zend_vm_execute.h

From: Date: Sun, 05 Feb 2006 23:26:55 +0000
Subject: cvs: ZendEngine2 / zend.h zend_compile.c zend_compile.h zend_execute.c zend_interfaces.c zend_interfaces.h zend_iterators.h zend_vm_def.h
zend_vm_execute.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-4562@lists.php.net to get a copy of this message
helly Sun Feb 5 23:26:55 2006 UTC Modified files: /ZendEngine2 zend.h zend_compile.c zend_compile.h zend_execute.c zend_interfaces.c zend_interfaces.h zend_iterators.h zend_vm_def.h zend_vm_execute.h Log: - Disallow foreach($v as &$ref) when $v is an object that implements interface Iterator. The signature of Iterator::current() doesn't allow that. Maybe ppl also want IteratorByReference or similar. Unfortunatley this comes with an API change but there is no easier way.

http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend.h?r1=1.308&r2=1.309&diff_format=u Index: ZendEngine2/zend.h diff -u ZendEngine2/zend.h:1.308 ZendEngine2/zend.h:1.309 --- ZendEngine2/zend.h:1.308 Tue Jan 17 12:18:51 2006 +++ ZendEngine2/zend.h Sun Feb 5 23:26:55 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.h,v 1.308 2006/01/17 12:18:51 dmitry Exp $ */ +/* $Id: zend.h,v 1.309 2006/02/05 23:26:55 helly Exp $ */ #ifndef ZEND_H #define ZEND_H @@ -357,7 +357,7 @@ /* handlers */ zend_object_value (*create_object)(zend_class_entry *class_type TSRMLS_DC); - zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object TSRMLS_DC); + zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC); int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */ /* serializer callbacks */ http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_compile.c?r1=1.678&r2=1.679&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.678 ZendEngine2/zend_compile.c:1.679 --- ZendEngine2/zend_compile.c:1.678 Tue Jan 17 12:18:51 2006 +++ ZendEngine2/zend_compile.c Sun Feb 5 23:26:55 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.678 2006/01/17 12:18:51 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.679 2006/02/05 23:26:55 helly Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -3757,7 +3757,7 @@ opline->result.u.var = get_temporary_variable(CG(active_op_array)); opline->op1 = *array; SET_UNUSED(opline->op2); - opline->extended_value = is_variable; + opline->extended_value = is_variable ? ZEND_FE_RESET_VARIABLE : 0; *open_brackets_token = opline->result; { @@ -3830,6 +3830,7 @@ } /* Mark extended_value for assign-by-reference */ opline->extended_value |= ZEND_FE_FETCH_BYREF; + CG(active_op_array)->opcodes[foreach_token->u.opline_num].extended_value |= ZEND_FE_RESET_REFERENCE; } value_node = opline->result; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_compile.h?r1=1.328&r2=1.329&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.328 ZendEngine2/zend_compile.h:1.329 --- ZendEngine2/zend_compile.h:1.328 Wed Jan 4 23:52:06 2006 +++ ZendEngine2/zend_compile.h Sun Feb 5 23:26:55 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.328 2006/01/04 23:52:06 andi Exp $ */ +/* $Id: zend_compile.h,v 1.329 2006/02/05 23:26:55 helly Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -661,6 +661,9 @@ #define ZEND_FE_FETCH_BYREF 1 #define ZEND_FE_FETCH_WITH_KEY 2 +#define ZEND_FE_RESET_VARIABLE 1 +#define ZEND_FE_RESET_REFERENCE 2 + #define ZEND_MEMBER_FUNC_CALL 1<<0 #define ZEND_ARG_SEND_BY_REF (1<<0) http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_execute.c?r1=1.732&r2=1.733&diff_format=u Index: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.732 ZendEngine2/zend_execute.c:1.733 --- ZendEngine2/zend_execute.c:1.732 Thu Jan 19 07:26:57 2006 +++ ZendEngine2/zend_execute.c Sun Feb 5 23:26:55 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.732 2006/01/19 07:26:57 dmitry Exp $ */ +/* $Id: zend_execute.c,v 1.733 2006/02/05 23:26:55 helly Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -34,6 +34,7 @@ #include "zend_fast_cache.h" #include "zend_ini.h" #include "zend_exceptions.h" +#include "zend_interfaces.h" #include "zend_vm.h" #include "zend_unicode.h" http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_interfaces.c?r1=1.40&r2=1.41&diff_format=u Index: ZendEngine2/zend_interfaces.c diff -u ZendEngine2/zend_interfaces.c:1.40 ZendEngine2/zend_interfaces.c:1.41 --- ZendEngine2/zend_interfaces.c:1.40 Tue Jan 17 12:18:52 2006 +++ ZendEngine2/zend_interfaces.c Sun Feb 5 23:26:55 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_interfaces.c,v 1.40 2006/01/17 12:18:52 dmitry Exp $ */ +/* $Id: zend_interfaces.c,v 1.41 2006/02/05 23:26:55 helly Exp $ */ #include "zend.h" #include "zend_API.h" @@ -270,9 +270,15 @@ }; /* {{{ zend_user_it_get_iterator */ -static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) +static zend_object_iterator *zend_user_it_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { - zend_user_iterator *iterator = emalloc(sizeof(zend_user_iterator)); + zend_user_iterator *iterator; + + if (by_ref) { + zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } + + iterator = emalloc(sizeof(zend_user_iterator)); object->refcount++; iterator->it.data = (void*)object; @@ -284,7 +290,7 @@ /* }}} */ /* {{{ zend_user_it_get_new_iterator */ -static zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) +ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) { zval *iterator = zend_user_it_new_iterator(ce, object TSRMLS_CC); zend_object_iterator *new_iterator; @@ -302,7 +308,11 @@ } return NULL; } - new_iterator = ce_it->get_iterator(ce_it, iterator TSRMLS_CC); + if (by_ref && ce_it && instanceof_function(ce_it, zend_ce_iterator TSRMLS_CC)) { + zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); + } + + new_iterator = ce_it->get_iterator(ce_it, iterator, by_ref TSRMLS_CC); zval_ptr_dtor(&iterator); return new_iterator; } http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_interfaces.h?r1=1.14&r2=1.15&diff_format=u Index: ZendEngine2/zend_interfaces.h diff -u ZendEngine2/zend_interfaces.h:1.14 ZendEngine2/zend_interfaces.h:1.15 --- ZendEngine2/zend_interfaces.h:1.14 Wed Jan 4 23:52:06 2006 +++ ZendEngine2/zend_interfaces.h Sun Feb 5 23:26:55 2006 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_interfaces.h,v 1.14 2006/01/04 23:52:06 andi Exp $ */ +/* $Id: zend_interfaces.h,v 1.15 2006/02/05 23:26:55 helly Exp $ */ #ifndef ZEND_INTERFACES_H #define ZEND_INTERFACES_H @@ -49,6 +49,8 @@ #define zend_call_method_with_2_params(obj, obj_ce, fn_proxy, function_name, retval, arg1, arg2) \ zend_call_method(obj, obj_ce, fn_proxy, function_name, sizeof(function_name)-1, retval, 2, arg1, arg2 TSRMLS_CC) +ZEND_API zend_object_iterator *zend_user_it_get_new_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC); + ZEND_API void zend_register_interfaces(TSRMLS_D); END_EXTERN_C() http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_iterators.h?r1=1.11&r2=1.12&diff_format=u Index: ZendEngine2/zend_iterators.h diff -u ZendEngine2/zend_iterators.h:1.11 ZendEngine2/zend_iterators.h:1.12 --- ZendEngine2/zend_iterators.h:1.11 Wed Jan 4 23:52:06 2006 +++ ZendEngine2/zend_iterators.h Sun Feb 5 23:26:55 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_iterators.h,v 1.11 2006/01/04 23:52:06 andi Exp $ */ +/* $Id: zend_iterators.h,v 1.12 2006/02/05 23:26:55 helly Exp $ */ /* These iterators were designed to operate within the foreach() * structures provided by the engine, but could be extended for use @@ -57,11 +57,8 @@ ulong index; /* private to fe_reset/fe_fetch opcodes */ }; -typedef zval *(*zend_object_new_iterator_t)(zend_class_entry *ce, zval *object TSRMLS_DC); - typedef struct _zend_class_iterator_funcs { zend_object_iterator_funcs *funcs; - zend_object_new_iterator_t new_iterator; union _zend_function *zf_new_iterator; union _zend_function *zf_valid; union _zend_function *zf_current; http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_def.h?r1=1.91&r2=1.92&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.91 ZendEngine2/zend_vm_def.h:1.92 --- ZendEngine2/zend_vm_def.h:1.91 Tue Jan 17 12:18:52 2006 +++ ZendEngine2/zend_vm_def.h Sun Feb 5 23:26:55 2006 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.91 2006/01/17 12:18:52 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.92 2006/02/05 23:26:55 helly Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -3041,7 +3041,7 @@ zend_class_entry *ce = NULL; zend_bool is_empty = 0; - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { array_ptr_ptr = GET_OP1_ZVAL_PTR_PTR(BP_VAR_R); if (array_ptr_ptr == NULL || array_ptr_ptr == &EG(uninitialized_zval_ptr)) { ALLOC_INIT_ZVAL(array_ptr); @@ -3078,12 +3078,12 @@ } if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr TSRMLS_CC); + iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { array_ptr = zend_iterator_wrap(iter TSRMLS_CC); } else { - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { FREE_OP1_VAR_PTR(); } else { FREE_OP1_IF_VAR(); @@ -3140,7 +3140,7 @@ is_empty = 1; } - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { FREE_OP1_VAR_PTR(); } else { FREE_OP1_IF_VAR(); http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_vm_execute.h?r1=1.95&r2=1.96&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.95 ZendEngine2/zend_vm_execute.h:1.96 --- ZendEngine2/zend_vm_execute.h:1.95 Tue Jan 17 12:18:52 2006 +++ ZendEngine2/zend_vm_execute.h Sun Feb 5 23:26:55 2006 @@ -1980,7 +1980,7 @@ zend_class_entry *ce = NULL; zend_bool is_empty = 0; - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { array_ptr_ptr = NULL; if (array_ptr_ptr == NULL || array_ptr_ptr == &EG(uninitialized_zval_ptr)) { ALLOC_INIT_ZVAL(array_ptr); @@ -2017,12 +2017,12 @@ } if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr TSRMLS_CC); + iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { array_ptr = zend_iterator_wrap(iter TSRMLS_CC); } else { - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else { @@ -2079,7 +2079,7 @@ is_empty = 1; } - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else { @@ -4478,7 +4478,7 @@ zend_class_entry *ce = NULL; zend_bool is_empty = 0; - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { array_ptr_ptr = NULL; if (array_ptr_ptr == NULL || array_ptr_ptr == &EG(uninitialized_zval_ptr)) { ALLOC_INIT_ZVAL(array_ptr); @@ -4515,12 +4515,12 @@ } if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr TSRMLS_CC); + iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { array_ptr = zend_iterator_wrap(iter TSRMLS_CC); } else { - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else { @@ -4577,7 +4577,7 @@ is_empty = 1; } - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else { @@ -7573,7 +7573,7 @@ zend_class_entry *ce = NULL; zend_bool is_empty = 0; - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { array_ptr_ptr = _get_zval_ptr_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC); if (array_ptr_ptr == NULL || array_ptr_ptr == &EG(uninitialized_zval_ptr)) { ALLOC_INIT_ZVAL(array_ptr); @@ -7610,12 +7610,12 @@ } if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr TSRMLS_CC); + iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { array_ptr = zend_iterator_wrap(iter TSRMLS_CC); } else { - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; } else { if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -7672,7 +7672,7 @@ is_empty = 1; } - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; } else { if (free_op1.var) {zval_ptr_dtor(&free_op1.var);}; @@ -20213,7 +20213,7 @@ zend_class_entry *ce = NULL; zend_bool is_empty = 0; - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { array_ptr_ptr = _get_zval_ptr_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC); if (array_ptr_ptr == NULL || array_ptr_ptr == &EG(uninitialized_zval_ptr)) { ALLOC_INIT_ZVAL(array_ptr); @@ -20250,12 +20250,12 @@ } if (ce && ce->get_iterator) { - iter = ce->get_iterator(ce, array_ptr TSRMLS_CC); + iter = ce->get_iterator(ce, array_ptr, opline->extended_value & ZEND_FE_RESET_REFERENCE TSRMLS_CC); if (iter && !EG(exception)) { array_ptr = zend_iterator_wrap(iter TSRMLS_CC); } else { - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else { @@ -20312,7 +20312,7 @@ is_empty = 1; } - if (opline->extended_value) { + if (opline->extended_value & ZEND_FE_RESET_VARIABLE) { } else {
« previous php.zend-engine.cvs (#4562) next »