cvs: ZendEngine2 / zend_execute.c zend_iterators.h

From: Date: Fri, 07 Nov 2003 10:47:47 +0000
Subject: cvs: ZendEngine2 / zend_execute.c zend_iterators.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1967@lists.php.net to get a copy of this message
helly Fri Nov 7 05:47:47 2003 EDT Modified files: /ZendEngine2 zend_execute.c zend_iterators.h Log: Update Iterators: Call next at the correct point in time. Index: ZendEngine2/zend_execute.c diff -u ZendEngine2/zend_execute.c:1.546 ZendEngine2/zend_execute.c:1.547 --- ZendEngine2/zend_execute.c:1.546 Tue Nov 4 17:07:59 2003 +++ ZendEngine2/zend_execute.c Fri Nov 7 05:47:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute.c,v 1.546 2003/11/04 22:07:59 helly Exp $ */ +/* $Id: zend_execute.c,v 1.547 2003/11/07 10:47:47 helly Exp $ */ #define ZEND_INTENSIVE_DEBUGGING 0 @@ -3584,6 +3584,7 @@ EX_T(EX(opline)->result.u.var).var.ptr_ptr = &EX_T(EX(opline)->result.u.var).var.ptr; if (iter) { + iter->index = 0; if (iter->funcs->rewind) { iter->funcs->rewind(iter TSRMLS_CC); } @@ -3612,6 +3613,7 @@ ulong int_key; HashTable *fe_ht; zend_object_iterator *iter = NULL; + int key_type; PZVAL_LOCK(array); @@ -3629,16 +3631,29 @@ EX(opline) = op_array->opcodes+EX(opline)->op2.u.opline_num; return 0; /* CHECK_ME */ } + key_type = zend_hash_get_current_key_ex(fe_ht, &str_key, &str_key_len, &int_key, 1, NULL); break; case ZEND_ITER_OBJECT: /* !iter happens from exception */ + if (iter && iter->index++) { + /* This could cause an endless loop if index becomes zero again. + * In case that ever happens we need an additional flag. */ + iter->funcs->move_forward(iter TSRMLS_CC); + } if (!iter || iter->funcs->has_more(iter TSRMLS_CC) == FAILURE) { /* reached end of iteration */ EX(opline) = op_array->opcodes+EX(opline)->op2.u.opline_num; return 0; /* CHECK_ME */ } iter->funcs->get_current_data(iter, &value TSRMLS_CC); + if (iter->funcs->get_current_key) { + key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); + } else { + key_type = HASH_KEY_IS_LONG; + int_key = iter->index; + } + break; } @@ -3653,10 +3668,8 @@ ALLOC_ZVAL(key); INIT_PZVAL(key); - - switch (iter ? - iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC) : - zend_hash_get_current_key_ex(fe_ht, &str_key, &str_key_len, &int_key, 1, NULL)) { + + switch (key_type) { case HASH_KEY_IS_STRING: key->value.str.val = str_key; key->value.str.len = str_key_len-1; @@ -3670,9 +3683,7 @@ } zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); - if (iter) { - iter->funcs->move_forward(iter TSRMLS_CC); - } else { + if (!iter) { zend_hash_move_forward(fe_ht); } Index: ZendEngine2/zend_iterators.h diff -u ZendEngine2/zend_iterators.h:1.3 ZendEngine2/zend_iterators.h:1.4 --- ZendEngine2/zend_iterators.h:1.3 Sat Oct 18 14:43:00 2003 +++ ZendEngine2/zend_iterators.h Fri Nov 7 05:47:47 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_iterators.h,v 1.3 2003/10/18 18:43:00 helly Exp $ */ +/* $Id: zend_iterators.h,v 1.4 2003/11/07 10:47:47 helly Exp $ */ /* These iterators were designed to operate within the foreach() * structures provided by the engine, but could be extended for use @@ -38,7 +38,7 @@ /* fetch the item data for the current element */ void (*get_current_data)(zend_object_iterator *iter, zval ***data TSRMLS_DC); - /* fetch the key for the current element (return HASH_KEY_IS_STRING or HASH_KEY_IS_LONG) */ + /* fetch the key for the current element (return HASH_KEY_IS_STRING or HASH_KEY_IS_LONG) (optional, may be NULL) */ int (*get_current_key)(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC); /* step forwards to next element */ @@ -51,6 +51,7 @@ struct _zend_object_iterator { void *data; zend_object_iterator_funcs *funcs; + ulong index; /* private to fe_reset/fe_fetch opcodes */ }; typedef zval *(*zend_object_new_iterator_t)(zend_class_entry *ce, zval *object TSRMLS_DC);

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