helly Mon Dec 19 00:55:40 2005 EDT
Modified files:
/php-src/ext/spl spl_iterators.c
Log:
- MFH IteratorIterator::__construct() fixes
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_iterators.c?r1=1.100&r2=1.101&diff_format=u
Index: php-src/ext/spl/spl_iterators.c
diff -u php-src/ext/spl/spl_iterators.c:1.100
php-src/ext/spl/spl_iterators.c:1.101
--- php-src/ext/spl/spl_iterators.c:1.100 Sun Dec 18 22:53:18 2005
+++ php-src/ext/spl/spl_iterators.c Mon Dec 19 00:55:40 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_iterators.c,v 1.100 2005/12/18 22:53:18 tony2001 Exp $ */
+/* $Id: spl_iterators.c,v 1.101 2005/12/19 00:55:40 helly Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -828,9 +828,11 @@
static INLINE spl_dual_it_object*
spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_inner,
dual_it_type dit_type)
{
- zval *zobject, *retval = NULL;
+ zval *zobject, *retval;
spl_dual_it_object *intern;
zend_class_entry *ce;
+ int inc_refcount = 1;
+
php_set_error_handling(EH_THROW,
U_CLASS_ENTRY(spl_ce_InvalidArgumentException) TSRMLS_CC);
@@ -898,8 +900,15 @@
ce = *pce_cast;
}
if (instanceof_function(ce,
U_CLASS_ENTRY(zend_ce_aggregate) TSRMLS_CC)) {
- zobject =
zend_call_method_with_0_params(&zobject, ce,
&ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
+
zend_call_method_with_0_params(&zobject, ce,
&ce->iterator_funcs.zf_new_iterator, "getiterator", &retval);
+ if (!retval || Z_TYPE_P(retval) !=
IS_OBJECT || !instanceof_function(Z_OBJCE_P(retval),
U_CLASS_ENTRY(zend_ce_traversable) TSRMLS_CC)) {
+
zend_throw_exception_ex(U_CLASS_ENTRY(spl_ce_LogicException), 0 TSRMLS_CC,
"%s::getIterator() must return an object that implememnts Traversable",
ce->name);
+
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ return NULL;
+ }
+ zobject = retval;
ce = Z_OBJCE_P(zobject);
+ inc_refcount = 0;
}
}
break;
@@ -937,16 +946,14 @@
php_set_error_handling(EH_THROW, zend_exception_get_default(TSRMLS_C)
TSRMLS_CC);
- zobject->refcount++;
+ if (inc_refcount) {
+ zobject->refcount++;
+ }
intern->inner.zobject = zobject;
intern->inner.ce = dit_type == DIT_IteratorIterator ? ce :
Z_OBJCE_P(zobject);
intern->inner.object = zend_object_store_get_object(zobject TSRMLS_CC);
intern->inner.iterator =
intern->inner.ce->get_iterator(intern->inner.ce, zobject TSRMLS_CC);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
-
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return intern;
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php