@@ -146,7 +146,7 @@ static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
146
146
147
147
while (object -> level > 0 ) {
148
148
sub_iter = object -> iterators [object -> level ].iterator ;
149
- sub_iter -> funcs -> dtor (sub_iter TSRMLS_CC );
149
+ zend_iterator_dtor (sub_iter TSRMLS_CC );
150
150
zval_ptr_dtor (& object -> iterators [object -> level -- ].zobject );
151
151
}
152
152
object -> iterators = erealloc (object -> iterators , sizeof (spl_sub_iterator ));
@@ -161,7 +161,7 @@ static int spl_recursive_it_valid_ex(spl_recursive_it_object *object, zval *zthi
161
161
zend_object_iterator * sub_iter ;
162
162
int level = object -> level ;
163
163
164
- while (level >=0 ) {
164
+ while (level >= 0 ) {
165
165
sub_iter = object -> iterators [level ].iterator ;
166
166
if (sub_iter -> funcs -> valid (sub_iter TSRMLS_CC ) == SUCCESS ) {
167
167
return SUCCESS ;
@@ -357,7 +357,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
357
357
}
358
358
}
359
359
}
360
- iterator -> funcs -> dtor (iterator TSRMLS_CC );
360
+ zend_iterator_dtor (iterator TSRMLS_CC );
361
361
zval_ptr_dtor (& object -> iterators [object -> level ].zobject );
362
362
object -> level -- ;
363
363
} else {
@@ -376,7 +376,7 @@ static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object, zval *zt
376
376
377
377
while (object -> level ) {
378
378
sub_iter = object -> iterators [object -> level ].iterator ;
379
- sub_iter -> funcs -> dtor (sub_iter TSRMLS_CC );
379
+ zend_iterator_dtor (sub_iter TSRMLS_CC );
380
380
zval_ptr_dtor (& object -> iterators [object -> level -- ].zobject );
381
381
if (!EG (exception ) && (!object -> endChildren || object -> endChildren -> common .scope != spl_ce_RecursiveIteratorIterator )) {
382
382
zend_call_method_with_0_params (zthis , object -> ce , & object -> endChildren , "endchildren" , NULL );
@@ -438,17 +438,17 @@ zend_object_iterator_funcs spl_recursive_it_iterator_funcs = {
438
438
439
439
static void spl_recursive_it_it_construct (INTERNAL_FUNCTION_PARAMETERS , zend_class_entry * ce_base , zend_class_entry * ce_inner , recursive_it_it_type rit_type )
440
440
{
441
- zval * object = getThis ();
442
- spl_recursive_it_object * intern ;
443
- zval * iterator ;
444
- zend_class_entry * ce_iterator ;
445
- long mode , flags ;
446
- int inc_refcount = 1 ;
447
- zend_error_handling error_handling ;
441
+ zval * object = getThis ();
442
+ spl_recursive_it_object * intern ;
443
+ zval * iterator ;
444
+ zend_class_entry * ce_iterator ;
445
+ long mode , flags ;
446
+ int inc_refcount = 1 ;
447
+ zend_error_handling error_handling ;
448
448
449
449
zend_replace_error_handling (EH_THROW , spl_ce_InvalidArgumentException , & error_handling TSRMLS_CC );
450
450
451
- switch (rit_type ) {
451
+ switch (rit_type ) {
452
452
case RIT_RecursiveTreeIterator : {
453
453
454
454
zval caching_it , caching_it_flags , * user_caching_it_flags = NULL ;
@@ -542,12 +542,14 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
542
542
if (intern -> nextElement -> common .scope == ce_base ) {
543
543
intern -> nextElement = NULL ;
544
544
}
545
+
545
546
ce_iterator = Z_OBJCE_P (iterator ); /* respect inheritance, don't use spl_ce_RecursiveIterator */
546
547
intern -> iterators [0 ].iterator = ce_iterator -> get_iterator (ce_iterator , iterator , 0 TSRMLS_CC );
547
548
if (inc_refcount ) {
548
- Z_ADDREF_P (iterator );
549
+ ZVAL_COPY (& intern -> iterators [0 ].zobject , iterator );
550
+ } else {
551
+ ZVAL_COPY_VALUE (& intern -> iterators [0 ].zobject , iterator );
549
552
}
550
- intern -> iterators [0 ].zobject = * iterator ;
551
553
intern -> iterators [0 ].ce = ce_iterator ;
552
554
intern -> iterators [0 ].state = RS_START ;
553
555
@@ -558,7 +560,7 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
558
560
559
561
while (intern -> level >= 0 ) {
560
562
sub_iter = intern -> iterators [intern -> level ].iterator ;
561
- sub_iter -> funcs -> dtor (sub_iter TSRMLS_CC );
563
+ zend_iterator_dtor (sub_iter TSRMLS_CC );
562
564
zval_ptr_dtor (& intern -> iterators [intern -> level -- ].zobject );
563
565
}
564
566
efree (intern -> iterators );
@@ -857,7 +859,7 @@ static void spl_RecursiveIteratorIterator_dtor(zend_object *_object TSRMLS_DC)
857
859
if (object -> iterators ) {
858
860
while (object -> level >= 0 ) {
859
861
sub_iter = object -> iterators [object -> level ].iterator ;
860
- sub_iter -> funcs -> dtor (sub_iter TSRMLS_CC );
862
+ zend_iterator_dtor (sub_iter TSRMLS_CC );
861
863
zval_ptr_dtor (& object -> iterators [object -> level -- ].zobject );
862
864
}
863
865
efree (object -> iterators );
@@ -1282,14 +1284,14 @@ static union _zend_function *spl_dual_it_get_method(zval *object_ptr, zend_strin
1282
1284
function_handler = std_object_handlers .get_method (object_ptr , method , key TSRMLS_CC );
1283
1285
if (!function_handler && intern -> inner .ce ) {
1284
1286
if ((function_handler = zend_hash_find_ptr (& intern -> inner .ce -> function_table , method )) == NULL ) {
1285
- if (Z_OBJ_HT_P (intern -> inner .zobject )-> get_method ) {
1287
+ if (Z_OBJ_HT (intern -> inner .zobject )-> get_method ) {
1286
1288
//!!! maybe we really need a zval ** here?
1287
1289
//*object_ptr = &intern->inner.zobject?
1288
- object_ptr = intern -> inner .zobject ;
1290
+ object_ptr = & intern -> inner .zobject ;
1289
1291
function_handler = Z_OBJ_HT_P (object_ptr )-> get_method (object_ptr , method , key TSRMLS_CC );
1290
1292
}
1291
1293
} else {
1292
- object_ptr = intern -> inner .zobject ;
1294
+ object_ptr = & intern -> inner .zobject ;
1293
1295
}
1294
1296
}
1295
1297
return function_handler ;
@@ -1519,9 +1521,11 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
1519
1521
zend_restore_error_handling (& error_handling TSRMLS_CC );
1520
1522
1521
1523
if (inc_refcount ) {
1522
- Z_ADDREF_P (zobject );
1524
+ ZVAL_COPY (& intern -> inner .zobject , zobject );
1525
+ } else {
1526
+ ZVAL_COPY_VALUE (& intern -> inner .zobject , zobject );
1523
1527
}
1524
- intern -> inner . zobject = zobject ;
1528
+
1525
1529
intern -> inner .ce = dit_type == DIT_IteratorIterator ? ce : Z_OBJCE_P (zobject );
1526
1530
intern -> inner .object = Z_OBJ_P (zobject );
1527
1531
intern -> inner .iterator = intern -> inner .ce -> get_iterator (intern -> inner .ce , zobject , 0 TSRMLS_CC );
@@ -1558,8 +1562,8 @@ SPL_METHOD(dual_it, getInnerIterator)
1558
1562
1559
1563
SPL_FETCH_AND_CHECK_DUAL_IT (intern , getThis ());
1560
1564
1561
- if (intern -> inner .zobject ) {
1562
- RETVAL_ZVAL (intern -> inner .zobject , 1 , 0 );
1565
+ if (! ZVAL_IS_UNDEF ( & intern -> inner .zobject ) ) {
1566
+ RETVAL_ZVAL (& intern -> inner .zobject , 1 , 0 );
1563
1567
} else {
1564
1568
RETURN_NULL ();
1565
1569
}
@@ -1843,7 +1847,7 @@ SPL_METHOD(RecursiveFilterIterator, hasChildren)
1843
1847
1844
1848
SPL_FETCH_AND_CHECK_DUAL_IT (intern , getThis ());
1845
1849
1846
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "haschildren" , & retval );
1850
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "haschildren" , & retval );
1847
1851
if (Z_TYPE (retval ) != IS_UNDEF ) {
1848
1852
RETURN_ZVAL (& retval , 0 , 1 );
1849
1853
} else {
@@ -1864,7 +1868,7 @@ SPL_METHOD(RecursiveFilterIterator, getChildren)
1864
1868
1865
1869
SPL_FETCH_AND_CHECK_DUAL_IT (intern , getThis ());
1866
1870
1867
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
1871
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
1868
1872
if (!EG (exception ) && Z_TYPE (retval ) != IS_UNDEF ) {
1869
1873
spl_instantiate_arg_ex1 (Z_OBJCE_P (getThis ()), return_value , & retval TSRMLS_CC );
1870
1874
}
@@ -1884,7 +1888,7 @@ SPL_METHOD(RecursiveCallbackFilterIterator, getChildren)
1884
1888
1885
1889
intern = (spl_dual_it_object * )Z_OBJ_P (getThis ());
1886
1890
1887
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
1891
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
1888
1892
if (!EG (exception ) && Z_TYPE (retval ) != IS_UNDEF ) {
1889
1893
spl_instantiate_arg_ex2 (Z_OBJCE_P (getThis ()), return_value , & retval , & intern -> u .cbfilter -> fci .function_name TSRMLS_CC );
1890
1894
}
@@ -1925,7 +1929,7 @@ SPL_METHOD(CallbackFilterIterator, accept)
1925
1929
1926
1930
ZVAL_COPY_VALUE (& params [0 ], & intern -> current .data );
1927
1931
ZVAL_COPY_VALUE (& params [1 ], & intern -> current .key );
1928
- ZVAL_COPY_VALUE (& params [2 ], intern -> inner .zobject );
1932
+ ZVAL_COPY_VALUE (& params [2 ], & intern -> inner .zobject );
1929
1933
1930
1934
fci -> retval = & result ;
1931
1935
fci -> param_count = 3 ;
@@ -2181,7 +2185,7 @@ SPL_METHOD(RecursiveRegexIterator, getChildren)
2181
2185
2182
2186
SPL_FETCH_AND_CHECK_DUAL_IT (intern , getThis ());
2183
2187
2184
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
2188
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & retval );
2185
2189
if (!EG (exception )) {
2186
2190
ZVAL_STR (& regex , STR_COPY (intern -> u .regex .regex ));
2187
2191
spl_instantiate_arg_ex2 (Z_OBJCE_P (getThis ()), return_value , & retval , & regex TSRMLS_CC );
@@ -2195,15 +2199,15 @@ SPL_METHOD(RecursiveRegexIterator, getChildren)
2195
2199
/* {{{ spl_dual_it_dtor */
2196
2200
static void spl_dual_it_dtor (zend_object * _object TSRMLS_DC )
2197
2201
{
2198
- spl_dual_it_object * object = (spl_dual_it_object * )_object ;
2202
+ spl_dual_it_object * object = (spl_dual_it_object * )_object ;
2199
2203
2200
2204
/* call standard dtor */
2201
2205
zend_objects_destroy_object (_object TSRMLS_CC );
2202
2206
2203
2207
spl_dual_it_free (object TSRMLS_CC );
2204
2208
2205
2209
if (object -> inner .iterator ) {
2206
- object -> inner . iterator -> funcs -> dtor (object -> inner .iterator TSRMLS_CC );
2210
+ zend_iterator_dtor (object -> inner .iterator TSRMLS_CC );
2207
2211
}
2208
2212
}
2209
2213
/* }}} */
@@ -2214,12 +2218,12 @@ static void spl_dual_it_free_storage(zend_object *_object TSRMLS_DC)
2214
2218
spl_dual_it_object * object = (spl_dual_it_object * )_object ;
2215
2219
2216
2220
2217
- if (object -> inner .zobject ) {
2218
- zval_ptr_dtor (object -> inner .zobject );
2221
+ if (! ZVAL_IS_UNDEF ( & object -> inner .zobject ) ) {
2222
+ zval_ptr_dtor (& object -> inner .zobject );
2219
2223
}
2220
2224
2221
2225
if (object -> dit_type == DIT_AppendIterator ) {
2222
- object -> u . append . iterator -> funcs -> dtor (object -> u .append .iterator TSRMLS_CC );
2226
+ zend_iterator_dtor (object -> u .append .iterator TSRMLS_CC );
2223
2227
if (Z_TYPE (object -> u .append .zarrayit ) != IS_UNDEF ) {
2224
2228
zval_ptr_dtor (& object -> u .append .zarrayit );
2225
2229
}
@@ -2408,7 +2412,7 @@ static inline void spl_limit_it_seek(spl_dual_it_object *intern, long pos TSRMLS
2408
2412
if (pos != intern -> current .pos && instanceof_function (intern -> inner .ce , spl_ce_SeekableIterator TSRMLS_CC )) {
2409
2413
ZVAL_LONG (& zpos , pos );
2410
2414
spl_dual_it_free (intern TSRMLS_CC );
2411
- zend_call_method_with_1_params (intern -> inner .zobject , intern -> inner .ce , NULL , "seek" , NULL , & zpos );
2415
+ zend_call_method_with_1_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "seek" , NULL , & zpos );
2412
2416
zval_ptr_dtor (& zpos );
2413
2417
if (!EG (exception )) {
2414
2418
intern -> current .pos = pos ;
@@ -2560,7 +2564,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC)
2560
2564
/* Recursion ? */
2561
2565
if (intern -> dit_type == DIT_RecursiveCachingIterator ) {
2562
2566
zval retval , zchildren , zflags ;
2563
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "haschildren" , & retval );
2567
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "haschildren" , & retval );
2564
2568
if (EG (exception )) {
2565
2569
zval_ptr_dtor (& retval );
2566
2570
if (intern -> u .caching .flags & CIT_CATCH_GET_CHILD ) {
@@ -2570,7 +2574,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC)
2570
2574
}
2571
2575
} else {
2572
2576
if (zend_is_true (& retval TSRMLS_CC )) {
2573
- zend_call_method_with_0_params (intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & zchildren );
2577
+ zend_call_method_with_0_params (& intern -> inner .zobject , intern -> inner .ce , NULL , "getchildren" , & zchildren );
2574
2578
if (EG (exception )) {
2575
2579
zval_ptr_dtor (& zchildren );
2576
2580
if (intern -> u .caching .flags & CIT_CATCH_GET_CHILD ) {
@@ -2599,7 +2603,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC)
2599
2603
int use_copy ;
2600
2604
zval expr_copy ;
2601
2605
if (intern -> u .caching .flags & CIT_TOSTRING_USE_INNER ) {
2602
- ZVAL_COPY_VALUE (& intern -> u .caching .zstr , intern -> inner .zobject );
2606
+ ZVAL_COPY_VALUE (& intern -> u .caching .zstr , & intern -> inner .zobject );
2603
2607
} else {
2604
2608
ZVAL_COPY_VALUE (& intern -> u .caching .zstr , & intern -> current .data );
2605
2609
}
@@ -3217,24 +3221,21 @@ int spl_append_it_next_iterator(spl_dual_it_object *intern TSRMLS_DC) /* {{{*/
3217
3221
{
3218
3222
spl_dual_it_free (intern TSRMLS_CC );
3219
3223
3220
- if (intern -> inner .zobject ) {
3221
- zval_ptr_dtor (intern -> inner .zobject );
3222
- intern -> inner .zobject = NULL ;
3224
+ if (! ZVAL_IS_UNDEF ( & intern -> inner .zobject ) ) {
3225
+ zval_ptr_dtor (& intern -> inner .zobject );
3226
+ ZVAL_UNDEF ( & intern -> inner .zobject ) ;
3223
3227
intern -> inner .ce = NULL ;
3224
- intern -> inner .object = NULL ;
3225
3228
if (intern -> inner .iterator ) {
3226
- intern -> inner . iterator -> funcs -> dtor (intern -> inner .iterator TSRMLS_CC );
3229
+ zend_iterator_dtor (intern -> inner .iterator TSRMLS_CC );
3227
3230
intern -> inner .iterator = NULL ;
3228
3231
}
3229
3232
}
3230
3233
if (intern -> u .append .iterator -> funcs -> valid (intern -> u .append .iterator TSRMLS_CC ) == SUCCESS ) {
3231
3234
zval * it ;
3232
3235
3233
3236
it = intern -> u .append .iterator -> funcs -> get_current_data (intern -> u .append .iterator TSRMLS_CC );
3234
- Z_ADDREF_P (it );
3235
- intern -> inner .zobject = it ;
3237
+ ZVAL_COPY (& intern -> inner .zobject , it );
3236
3238
intern -> inner .ce = Z_OBJCE_P (it );
3237
- intern -> inner .object = Z_OBJ_P (it );
3238
3239
intern -> inner .iterator = intern -> inner .ce -> get_iterator (intern -> inner .ce , it , 0 TSRMLS_CC );
3239
3240
spl_dual_it_rewind (intern TSRMLS_CC );
3240
3241
return SUCCESS ;
@@ -3289,7 +3290,7 @@ SPL_METHOD(AppendIterator, append)
3289
3290
}
3290
3291
do {
3291
3292
spl_append_it_next_iterator (intern TSRMLS_CC );
3292
- } while (intern -> inner .zobject != it );
3293
+ } while (Z_OBJ ( intern -> inner .zobject ) != Z_OBJCE_P ( it ) );
3293
3294
spl_append_it_fetch (intern TSRMLS_CC );
3294
3295
}
3295
3296
} /* }}} */
@@ -3426,7 +3427,7 @@ PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, v
3426
3427
3427
3428
done :
3428
3429
if (iter ) {
3429
- iter -> funcs -> dtor (iter TSRMLS_CC );
3430
+ zend_iterator_dtor (iter TSRMLS_CC );
3430
3431
}
3431
3432
return EG (exception ) ? FAILURE : SUCCESS ;
3432
3433
}
0 commit comments