Lines Matching refs:generator

37 ZEND_API void zend_generator_restore_call_stack(zend_generator *generator) /* {{{ */  in zend_generator_restore_call_stack()  argument
41 call = generator->frozen_call_stack; in zend_generator_restore_call_stack()
55 generator->execute_data->call = prev_call; in zend_generator_restore_call_stack()
56 efree(generator->frozen_call_stack); in zend_generator_restore_call_stack()
57 generator->frozen_call_stack = NULL; in zend_generator_restore_call_stack()
115 zend_generator *generator, zend_execute_data *execute_data, uint32_t catch_op_num) /* {{{ */ in zend_generator_cleanup_unfinished_execution() argument
122 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_cleanup_unfinished_execution()
124 zend_execute_data *save_ex = generator->execute_data; in zend_generator_cleanup_unfinished_execution()
125 generator->execute_data = execute_data; in zend_generator_cleanup_unfinished_execution()
126 zend_generator_restore_call_stack(generator); in zend_generator_cleanup_unfinished_execution()
127 generator->execute_data = save_ex; in zend_generator_cleanup_unfinished_execution()
135 ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution) /* {{{ */ in zend_generator_close() argument
137 if (EXPECTED(generator->execute_data)) { in zend_generator_close()
138 zend_execute_data *execute_data = generator->execute_data; in zend_generator_close()
141 generator->execute_data = NULL; in zend_generator_close()
159 generator->execute_data = NULL; in zend_generator_close()
168 zend_generator_cleanup_unfinished_execution(generator, execute_data, 0); in zend_generator_close()
202 static zend_always_inline zend_generator *clear_link_to_leaf(zend_generator *generator) { in clear_link_to_leaf() argument
203 ZEND_ASSERT(!generator->node.parent); in clear_link_to_leaf()
204 zend_generator *leaf = generator->node.ptr.leaf; in clear_link_to_leaf()
207 generator->node.ptr.leaf = NULL; in clear_link_to_leaf()
213 static zend_always_inline void clear_link_to_root(zend_generator *generator) { in clear_link_to_root() argument
214 ZEND_ASSERT(generator->node.parent); in clear_link_to_root()
215 if (generator->node.ptr.root) { in clear_link_to_root()
216 generator->node.ptr.root->node.ptr.leaf = NULL; in clear_link_to_root()
217 generator->node.ptr.root = NULL; in clear_link_to_root()
222 static inline bool check_node_running_in_fiber(zend_generator *generator) { in check_node_running_in_fiber() argument
223 ZEND_ASSERT(generator->execute_data); in check_node_running_in_fiber()
225 if (EXPECTED(generator->flags & ZEND_GENERATOR_IN_FIBER)) { in check_node_running_in_fiber()
229 if (EXPECTED(generator->node.children == 0)) { in check_node_running_in_fiber()
233 if (generator->node.children == 1) { in check_node_running_in_fiber()
234 return check_node_running_in_fiber(generator->node.child.single); in check_node_running_in_fiber()
238 ZEND_HASH_FOREACH_PTR(generator->node.child.ht, child) { in check_node_running_in_fiber()
249 zend_generator *generator = (zend_generator*) object; in zend_generator_dtor_storage() local
250 zend_generator *current_generator = zend_generator_get_current(generator); in zend_generator_dtor_storage()
251 zend_execute_data *ex = generator->execute_data; in zend_generator_dtor_storage()
265 if (check_node_running_in_fiber(generator)) { in zend_generator_dtor_storage()
267 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
273 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_dtor_storage()
274 zval_ptr_dtor(&generator->values); in zend_generator_dtor_storage()
275 ZVAL_UNDEF(&generator->values); in zend_generator_dtor_storage()
278 zend_generator *parent = generator->node.parent; in zend_generator_dtor_storage()
280 zend_generator_remove_child(&parent->node, generator); in zend_generator_dtor_storage()
281 clear_link_to_root(generator); in zend_generator_dtor_storage()
282 generator->node.parent = NULL; in zend_generator_dtor_storage()
285 clear_link_to_leaf(generator); in zend_generator_dtor_storage()
290 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
319 zend_generator_cleanup_unfinished_execution(generator, ex, try_catch->finally_op); in zend_generator_dtor_storage()
327 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
328 zend_generator_resume(generator); in zend_generator_dtor_storage()
361 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
367 zend_generator *generator = (zend_generator*) object; in zend_generator_free_storage() local
369 zend_generator_close(generator, 0); in zend_generator_free_storage()
372 zval_ptr_dtor(&generator->value); in zend_generator_free_storage()
373 zval_ptr_dtor(&generator->key); in zend_generator_free_storage()
375 if (EXPECTED(!Z_ISUNDEF(generator->retval))) { in zend_generator_free_storage()
376 zval_ptr_dtor(&generator->retval); in zend_generator_free_storage()
379 if (UNEXPECTED(generator->node.children > 1)) { in zend_generator_free_storage()
380 zend_hash_destroy(generator->node.child.ht); in zend_generator_free_storage()
381 efree(generator->node.child.ht); in zend_generator_free_storage()
384 zend_object_std_dtor(&generator->std); in zend_generator_free_storage()
388 HashTable *zend_generator_frame_gc(zend_get_gc_buffer *gc_buffer, zend_generator *generator) in zend_generator_frame_gc() argument
390 zend_execute_data *execute_data = generator->execute_data; in zend_generator_frame_gc()
393 zend_get_gc_buffer_add_zval(gc_buffer, &generator->value); in zend_generator_frame_gc()
394 zend_get_gc_buffer_add_zval(gc_buffer, &generator->key); in zend_generator_frame_gc()
395 zend_get_gc_buffer_add_zval(gc_buffer, &generator->retval); in zend_generator_frame_gc()
396 zend_get_gc_buffer_add_zval(gc_buffer, &generator->values); in zend_generator_frame_gc()
398 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_frame_gc()
400 call = zend_generator_revert_call_stack(generator->frozen_call_stack); in zend_generator_frame_gc()
405 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_frame_gc()
409 if (generator->node.parent) { in zend_generator_frame_gc()
410 zend_get_gc_buffer_add_obj(gc_buffer, &generator->node.parent->std); in zend_generator_frame_gc()
418 zend_generator *generator = (zend_generator*)object; in zend_generator_get_gc() local
419 zend_execute_data *execute_data = generator->execute_data; in zend_generator_get_gc()
424 *table = &generator->value; in zend_generator_get_gc()
429 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_get_gc()
440 HashTable *ht = zend_generator_frame_gc(gc_buffer, generator); in zend_generator_get_gc()
449 zend_generator *generator; in zend_generator_create() local
451 generator = emalloc(sizeof(zend_generator)); in zend_generator_create()
452 memset(generator, 0, sizeof(zend_generator)); in zend_generator_create()
455 generator->largest_used_integer_key = -1; in zend_generator_create()
457 ZVAL_UNDEF(&generator->retval); in zend_generator_create()
458 ZVAL_UNDEF(&generator->values); in zend_generator_create()
461 generator->node.parent = NULL; in zend_generator_create()
462 generator->node.children = 0; in zend_generator_create()
463 generator->node.ptr.root = NULL; in zend_generator_create()
465 zend_object_std_init(&generator->std, class_type); in zend_generator_create()
466 generator->std.handlers = &zend_generator_handlers; in zend_generator_create()
468 return (zend_object*)generator; in zend_generator_create()
484 zend_generator *generator = (zend_generator *) Z_OBJ(ptr->This); in zend_generator_check_placeholder_frame() local
486 ZEND_ASSERT(generator->node.parent && "Placeholder only used with delegation"); in zend_generator_check_placeholder_frame()
487 while (generator->node.parent->node.parent) { in zend_generator_check_placeholder_frame()
488 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
489 prev = generator->execute_data; in zend_generator_check_placeholder_frame()
490 generator = generator->node.parent; in zend_generator_check_placeholder_frame()
492 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
493 ptr = generator->execute_data; in zend_generator_check_placeholder_frame()
499 static void zend_generator_throw_exception(zend_generator *generator, zval *exception) in zend_generator_throw_exception() argument
505 EG(current_execute_data) = generator->execute_data; in zend_generator_throw_exception()
506 generator->execute_data->opline--; in zend_generator_throw_exception()
507 ZEND_ASSERT(generator->execute_data->opline->opcode == ZEND_YIELD in zend_generator_throw_exception()
508 || generator->execute_data->opline->opcode == ZEND_YIELD_FROM); in zend_generator_throw_exception()
509 generator->execute_data->prev_execute_data = original_execute_data; in zend_generator_throw_exception()
517 generator->execute_data->opline++; in zend_generator_throw_exception()
520 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_throw_exception()
521 zval_ptr_dtor(&generator->values); in zend_generator_throw_exception()
522 ZVAL_UNDEF(&generator->values); in zend_generator_throw_exception()
528 static void zend_generator_add_child(zend_generator *generator, zend_generator *child) in zend_generator_add_child() argument
530 zend_generator_node *node = &generator->node; in zend_generator_add_child()
549 void zend_generator_yield_from(zend_generator *generator, zend_generator *from) in zend_generator_yield_from() argument
551 ZEND_ASSERT(!generator->node.parent && "Already has parent?"); in zend_generator_yield_from()
552 zend_generator *leaf = clear_link_to_leaf(generator); in zend_generator_yield_from()
557 generator->node.parent = from; in zend_generator_yield_from()
558 zend_generator_add_child(from, generator); in zend_generator_yield_from()
559 generator->flags |= ZEND_GENERATOR_DO_INIT; in zend_generator_yield_from()
562 ZEND_API zend_generator *zend_generator_update_root(zend_generator *generator) in zend_generator_update_root() argument
564 zend_generator *root = generator->node.parent; in zend_generator_update_root()
570 root->node.ptr.leaf = generator; in zend_generator_update_root()
571 generator->node.ptr.root = root; in zend_generator_update_root()
575 static zend_generator *get_new_root(zend_generator *generator, zend_generator *root) in get_new_root() argument
587 while (generator->node.parent->execute_data) { in get_new_root()
588 generator = generator->node.parent; in get_new_root()
591 return generator; in get_new_root()
594 ZEND_API zend_generator *zend_generator_update_current(zend_generator *generator) in zend_generator_update_current() argument
596 zend_generator *old_root = generator->node.ptr.root; in zend_generator_update_current()
599 zend_generator *new_root = get_new_root(generator, old_root); in zend_generator_update_current()
601 ZEND_ASSERT(old_root->node.ptr.leaf == generator); in zend_generator_update_current()
602 generator->node.ptr.root = new_root; in zend_generator_update_current()
603 new_root->node.ptr.leaf = generator; in zend_generator_update_current()
610 …if (EXPECTED(EG(exception) == NULL) && EXPECTED((OBJ_FLAGS(&generator->std) & IS_OBJ_DESTRUCTOR_CA… in zend_generator_update_current()
619 if (new_root == generator) { in zend_generator_update_current()
622 new_root->execute_data->prev_execute_data = &generator->execute_fake; in zend_generator_update_current()
623 generator->execute_fake.prev_execute_data = original_execute_data; in zend_generator_update_current()
632 if (!((old_root ? old_root : generator)->flags & ZEND_GENERATOR_CURRENTLY_RUNNING)) { in zend_generator_update_current()
635 zend_generator_resume(generator); in zend_generator_update_current()
636 return zend_generator_get_current(generator); in zend_generator_update_current()
652 static zend_result zend_generator_get_next_delegated_value(zend_generator *generator) /* {{{ */ in zend_generator_get_next_delegated_value() argument
655 if (Z_TYPE(generator->values) == IS_ARRAY) { in zend_generator_get_next_delegated_value()
656 HashTable *ht = Z_ARR(generator->values); in zend_generator_get_next_delegated_value()
657 HashPosition pos = Z_FE_POS(generator->values); in zend_generator_get_next_delegated_value()
670 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
671 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
673 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
674 ZVAL_LONG(&generator->key, pos - 1); in zend_generator_get_next_delegated_value()
689 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
690 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
692 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
694 ZVAL_STR_COPY(&generator->key, p->key); in zend_generator_get_next_delegated_value()
696 ZVAL_LONG(&generator->key, p->h); in zend_generator_get_next_delegated_value()
699 Z_FE_POS(generator->values) = pos; in zend_generator_get_next_delegated_value()
701 zend_object_iterator *iter = (zend_object_iterator *) Z_OBJ(generator->values); in zend_generator_get_next_delegated_value()
720 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
721 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
723 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
725 iter->funcs->get_current_key(iter, &generator->key); in zend_generator_get_next_delegated_value()
727 ZVAL_UNDEF(&generator->key); in zend_generator_get_next_delegated_value()
731 ZVAL_LONG(&generator->key, iter->index); in zend_generator_get_next_delegated_value()
738 zval_ptr_dtor(&generator->values); in zend_generator_get_next_delegated_value()
739 ZVAL_UNDEF(&generator->values); in zend_generator_get_next_delegated_value()
747 zend_generator *generator = zend_generator_get_current(orig_generator); in zend_generator_resume() local
750 if (UNEXPECTED(!generator->execute_data)) { in zend_generator_resume()
755 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_resume()
760 …if (UNEXPECTED((orig_generator->flags & ZEND_GENERATOR_DO_INIT) != 0 && !Z_ISUNDEF(generator->valu… in zend_generator_resume()
768 generator->flags |= ZEND_GENERATOR_IN_FIBER; in zend_generator_resume()
779 EG(current_execute_data) = generator->execute_data; in zend_generator_resume()
785 if (generator == orig_generator) { in zend_generator_resume()
786 generator->execute_data->prev_execute_data = original_execute_data; in zend_generator_resume()
790 generator->execute_data->prev_execute_data = &orig_generator->execute_fake; in zend_generator_resume()
795 if (UNEXPECTED(!Z_ISUNDEF(generator->values))) { in zend_generator_resume()
796 if (EXPECTED(zend_generator_get_next_delegated_value(generator) == SUCCESS)) { in zend_generator_resume()
802 generator->flags &= ~ZEND_GENERATOR_IN_FIBER; in zend_generator_resume()
808 if (generator->execute_data) { in zend_generator_resume()
809 ZEND_ASSERT(generator->execute_data->opline == EG(exception_op)); in zend_generator_resume()
818 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_resume()
820 zend_generator_restore_call_stack(generator); in zend_generator_resume()
824 generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; in zend_generator_resume()
826 zend_execute_ex(generator->execute_data); in zend_generator_resume()
828 zend_observer_generator_resume(generator->execute_data); in zend_generator_resume()
829 zend_execute_ex(generator->execute_data); in zend_generator_resume()
830 if (generator->execute_data) { in zend_generator_resume()
832 zend_observer_fcall_end(generator->execute_data, &generator->value); in zend_generator_resume()
835 generator->flags &= ~(ZEND_GENERATOR_CURRENTLY_RUNNING | ZEND_GENERATOR_IN_FIBER); in zend_generator_resume()
837 generator->frozen_call_stack = NULL; in zend_generator_resume()
838 if (EXPECTED(generator->execute_data) && in zend_generator_resume()
839 UNEXPECTED(generator->execute_data->call)) { in zend_generator_resume()
841 generator->frozen_call_stack = zend_generator_freeze_call_stack(generator->execute_data); in zend_generator_resume()
853 if (generator == orig_generator) { in zend_generator_resume()
854 zend_generator_close(generator, 0); in zend_generator_resume()
862 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
863 zend_generator_throw_exception(generator, NULL); in zend_generator_resume()
870 …if (UNEXPECTED((generator != orig_generator && !Z_ISUNDEF(generator->retval)) || (generator->execu… in zend_generator_resume()
871 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
879 static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */ in zend_generator_ensure_initialized() argument
881 …if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPEC… in zend_generator_ensure_initialized()
882 zend_generator_resume(generator); in zend_generator_ensure_initialized()
883 generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD; in zend_generator_ensure_initialized()
888 static inline void zend_generator_rewind(zend_generator *generator) /* {{{ */ in zend_generator_rewind() argument
890 zend_generator_ensure_initialized(generator); in zend_generator_rewind()
892 if (!(generator->flags & ZEND_GENERATOR_AT_FIRST_YIELD)) { in zend_generator_rewind()
901 zend_generator *generator; in ZEND_METHOD() local
905 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
907 zend_generator_rewind(generator); in ZEND_METHOD()
914 zend_generator *generator; in ZEND_METHOD() local
918 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
920 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
922 zend_generator_get_current(generator); in ZEND_METHOD()
924 RETURN_BOOL(EXPECTED(generator->execute_data != NULL)); in ZEND_METHOD()
931 zend_generator *generator, *root; in ZEND_METHOD() local
935 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
937 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
939 root = zend_generator_get_current(generator); in ZEND_METHOD()
940 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->value) != IS_UNDEF)) { in ZEND_METHOD()
949 zend_generator *generator, *root; in ZEND_METHOD() local
953 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
955 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
957 root = zend_generator_get_current(generator); in ZEND_METHOD()
958 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->key) != IS_UNDEF)) { in ZEND_METHOD()
967 zend_generator *generator; in ZEND_METHOD() local
971 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
973 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
975 zend_generator_resume(generator); in ZEND_METHOD()
983 zend_generator *generator, *root; in ZEND_METHOD() local
989 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
991 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
994 if (UNEXPECTED(!generator->execute_data)) { in ZEND_METHOD()
998 root = zend_generator_get_current(generator); in ZEND_METHOD()
1004 zend_generator_resume(generator); in ZEND_METHOD()
1006 root = zend_generator_get_current(generator); in ZEND_METHOD()
1007 if (EXPECTED(generator->execute_data)) { in ZEND_METHOD()
1017 zend_generator *generator; in ZEND_METHOD() local
1025 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
1027 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
1029 if (generator->execute_data) { in ZEND_METHOD()
1030 zend_generator *root = zend_generator_get_current(generator); in ZEND_METHOD()
1034 zend_generator_resume(generator); in ZEND_METHOD()
1036 root = zend_generator_get_current(generator); in ZEND_METHOD()
1037 if (generator->execute_data) { in ZEND_METHOD()
1051 zend_generator *generator; in ZEND_METHOD() local
1055 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
1057 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
1062 if (Z_ISUNDEF(generator->retval)) { in ZEND_METHOD()
1069 ZVAL_COPY(return_value, &generator->retval); in ZEND_METHOD()
1083 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_valid() local
1085 zend_generator_ensure_initialized(generator); in zend_generator_iterator_valid()
1087 zend_generator_get_current(generator); in zend_generator_iterator_valid()
1089 return generator->execute_data ? SUCCESS : FAILURE; in zend_generator_iterator_valid()
1095 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_data() local
1097 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_data()
1099 root = zend_generator_get_current(generator); in zend_generator_iterator_get_data()
1107 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_key() local
1109 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_key()
1111 root = zend_generator_get_current(generator); in zend_generator_iterator_get_key()
1125 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_move_forward() local
1127 zend_generator_ensure_initialized(generator); in zend_generator_iterator_move_forward()
1129 zend_generator_resume(generator); in zend_generator_iterator_move_forward()
1135 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_rewind() local
1137 zend_generator_rewind(generator); in zend_generator_iterator_rewind()
1164 zend_generator *generator = (zend_generator*)Z_OBJ_P(object); in zend_generator_get_iterator() local
1166 if (!generator->execute_data) { in zend_generator_get_iterator()
1171 …if (UNEXPECTED(by_ref) && !(generator->execute_data->func->op_array.fn_flags & ZEND_ACC_RETURN_REF… in zend_generator_get_iterator()