@@ -312,6 +312,7 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
312312{
313313 uint32_t i ;
314314 int t = -1 ;
315+ zend_class_iterator_funcs * funcs_ptr ;
315316
316317 if (class_type -> get_iterator ) {
317318 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
@@ -340,16 +341,21 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
340341 }
341342 }
342343 class_type -> get_iterator = zend_user_it_get_new_iterator ;
343- if (class_type -> iterator_funcs_ptr != NULL ) {
344- class_type -> iterator_funcs_ptr -> zf_new_iterator = NULL ;
345- } else if (class_type -> type == ZEND_INTERNAL_CLASS ) {
346- class_type -> iterator_funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
347- } else {
348- class_type -> iterator_funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
349- memset (class_type -> iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
350- }
344+ funcs_ptr = class_type -> iterator_funcs_ptr ;
351345 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
352- class_type -> iterator_funcs_ptr -> zf_new_iterator = zend_hash_str_find_ptr (& class_type -> function_table , "getiterator" , sizeof ("getiterator" ) - 1 );
346+ if (!funcs_ptr ) {
347+ funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
348+ class_type -> iterator_funcs_ptr = funcs_ptr ;
349+ }
350+ funcs_ptr -> zf_new_iterator = zend_hash_str_find_ptr (& class_type -> function_table , "getiterator" , sizeof ("getiterator" ) - 1 );
351+ } else {
352+ if (!funcs_ptr ) {
353+ funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
354+ class_type -> iterator_funcs_ptr = funcs_ptr ;
355+ memset (funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
356+ } else {
357+ funcs_ptr -> zf_new_iterator = NULL ;
358+ }
353359 }
354360 return SUCCESS ;
355361}
@@ -358,6 +364,8 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
358364/* {{{ zend_implement_iterator */
359365static int zend_implement_iterator (zend_class_entry * interface , zend_class_entry * class_type )
360366{
367+ zend_class_iterator_funcs * funcs_ptr ;
368+
361369 if (class_type -> get_iterator && class_type -> get_iterator != zend_user_it_get_iterator ) {
362370 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
363371 /* inheritance ensures the class has the necessary userland methods */
@@ -374,24 +382,30 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
374382 }
375383 }
376384 class_type -> get_iterator = zend_user_it_get_iterator ;
377- if (class_type -> iterator_funcs_ptr != NULL ) {
378- class_type -> iterator_funcs_ptr -> zf_valid = NULL ;
379- class_type -> iterator_funcs_ptr -> zf_current = NULL ;
380- class_type -> iterator_funcs_ptr -> zf_key = NULL ;
381- class_type -> iterator_funcs_ptr -> zf_next = NULL ;
382- class_type -> iterator_funcs_ptr -> zf_rewind = NULL ;
383- } else if (class_type -> type == ZEND_INTERNAL_CLASS ) {
384- class_type -> iterator_funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
385- } else {
386- class_type -> iterator_funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
387- memset (class_type -> iterator_funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
388- }
385+ funcs_ptr = class_type -> iterator_funcs_ptr ;
389386 if (class_type -> type == ZEND_INTERNAL_CLASS ) {
390- class_type -> iterator_funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
391- class_type -> iterator_funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
392- class_type -> iterator_funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
393- class_type -> iterator_funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
394- class_type -> iterator_funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
387+ if (!funcs_ptr ) {
388+ funcs_ptr = calloc (1 , sizeof (zend_class_iterator_funcs ));
389+ class_type -> iterator_funcs_ptr = funcs_ptr ;
390+ } else {
391+ funcs_ptr -> zf_rewind = zend_hash_str_find_ptr (& class_type -> function_table , "rewind" , sizeof ("rewind" ) - 1 );
392+ funcs_ptr -> zf_valid = zend_hash_str_find_ptr (& class_type -> function_table , "valid" , sizeof ("valid" ) - 1 );
393+ funcs_ptr -> zf_key = zend_hash_str_find_ptr (& class_type -> function_table , "key" , sizeof ("key" ) - 1 );
394+ funcs_ptr -> zf_current = zend_hash_str_find_ptr (& class_type -> function_table , "current" , sizeof ("current" ) - 1 );
395+ funcs_ptr -> zf_next = zend_hash_str_find_ptr (& class_type -> function_table , "next" , sizeof ("next" ) - 1 );
396+ }
397+ } else {
398+ if (!funcs_ptr ) {
399+ funcs_ptr = zend_arena_alloc (& CG (arena ), sizeof (zend_class_iterator_funcs ));
400+ class_type -> iterator_funcs_ptr = funcs_ptr ;
401+ memset (funcs_ptr , 0 , sizeof (zend_class_iterator_funcs ));
402+ } else {
403+ funcs_ptr -> zf_valid = NULL ;
404+ funcs_ptr -> zf_current = NULL ;
405+ funcs_ptr -> zf_key = NULL ;
406+ funcs_ptr -> zf_next = NULL ;
407+ funcs_ptr -> zf_rewind = NULL ;
408+ }
395409 }
396410 return SUCCESS ;
397411}
0 commit comments