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
121 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_cleanup_unfinished_execution()
123 zend_execute_data *save_ex = generator->execute_data; in zend_generator_cleanup_unfinished_execution()
124 generator->execute_data = execute_data; in zend_generator_cleanup_unfinished_execution()
125 zend_generator_restore_call_stack(generator); in zend_generator_cleanup_unfinished_execution()
126 generator->execute_data = save_ex; in zend_generator_cleanup_unfinished_execution()
134 ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution) /* {{{ */ in zend_generator_close() argument
136 if (EXPECTED(generator->execute_data)) { in zend_generator_close()
137 zend_execute_data *execute_data = generator->execute_data; in zend_generator_close()
140 generator->execute_data = NULL; in zend_generator_close()
158 generator->execute_data = NULL; in zend_generator_close()
167 zend_generator_cleanup_unfinished_execution(generator, execute_data, 0); in zend_generator_close()
196 static zend_always_inline zend_generator *clear_link_to_leaf(zend_generator *generator) { in clear_link_to_leaf() argument
197 ZEND_ASSERT(!generator->node.parent); in clear_link_to_leaf()
198 zend_generator *leaf = generator->node.ptr.leaf; in clear_link_to_leaf()
201 generator->node.ptr.leaf = NULL; in clear_link_to_leaf()
207 static zend_always_inline void clear_link_to_root(zend_generator *generator) { in clear_link_to_root() argument
208 ZEND_ASSERT(generator->node.parent); in clear_link_to_root()
209 if (generator->node.ptr.root) { in clear_link_to_root()
210 generator->node.ptr.root->node.ptr.leaf = NULL; in clear_link_to_root()
211 generator->node.ptr.root = NULL; in clear_link_to_root()
216 static inline bool check_node_running_in_fiber(zend_generator *generator) { in check_node_running_in_fiber() argument
217 ZEND_ASSERT(generator->execute_data); in check_node_running_in_fiber()
219 if (EXPECTED(generator->flags & ZEND_GENERATOR_IN_FIBER)) { in check_node_running_in_fiber()
223 if (EXPECTED(generator->node.children == 0)) { in check_node_running_in_fiber()
227 if (generator->node.children == 1) { in check_node_running_in_fiber()
228 return check_node_running_in_fiber(generator->node.child.single); in check_node_running_in_fiber()
232 ZEND_HASH_FOREACH_PTR(generator->node.child.ht, child) { in check_node_running_in_fiber()
243 zend_generator *generator = (zend_generator*) object; in zend_generator_dtor_storage() local
244 zend_generator *current_generator = zend_generator_get_current(generator); in zend_generator_dtor_storage()
245 zend_execute_data *ex = generator->execute_data; in zend_generator_dtor_storage()
259 if (check_node_running_in_fiber(generator)) { in zend_generator_dtor_storage()
261 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
267 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_dtor_storage()
268 zval_ptr_dtor(&generator->values); in zend_generator_dtor_storage()
269 ZVAL_UNDEF(&generator->values); in zend_generator_dtor_storage()
272 zend_generator *parent = generator->node.parent; in zend_generator_dtor_storage()
274 zend_generator_remove_child(&parent->node, generator); in zend_generator_dtor_storage()
275 clear_link_to_root(generator); in zend_generator_dtor_storage()
276 generator->node.parent = NULL; in zend_generator_dtor_storage()
279 clear_link_to_leaf(generator); in zend_generator_dtor_storage()
284 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
311 zend_generator_cleanup_unfinished_execution(generator, ex, try_catch->finally_op); in zend_generator_dtor_storage()
320 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
321 zend_generator_resume(generator); in zend_generator_dtor_storage()
354 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
360 zend_generator *generator = (zend_generator*) object; in zend_generator_free_storage() local
362 zend_generator_close(generator, 0); in zend_generator_free_storage()
364 if (generator->func && (generator->func->common.fn_flags & ZEND_ACC_CLOSURE)) { in zend_generator_free_storage()
365 OBJ_RELEASE(ZEND_CLOSURE_OBJECT(generator->func)); in zend_generator_free_storage()
369 zval_ptr_dtor(&generator->value); in zend_generator_free_storage()
370 zval_ptr_dtor(&generator->key); in zend_generator_free_storage()
372 if (EXPECTED(!Z_ISUNDEF(generator->retval))) { in zend_generator_free_storage()
373 zval_ptr_dtor(&generator->retval); in zend_generator_free_storage()
376 if (UNEXPECTED(generator->node.children > 1)) { in zend_generator_free_storage()
377 zend_hash_destroy(generator->node.child.ht); in zend_generator_free_storage()
378 efree(generator->node.child.ht); in zend_generator_free_storage()
381 zend_object_std_dtor(&generator->std); in zend_generator_free_storage()
385 HashTable *zend_generator_frame_gc(zend_get_gc_buffer *gc_buffer, zend_generator *generator) in zend_generator_frame_gc() argument
387 zend_execute_data *execute_data = generator->execute_data; in zend_generator_frame_gc()
390 zend_get_gc_buffer_add_zval(gc_buffer, &generator->value); in zend_generator_frame_gc()
391 zend_get_gc_buffer_add_zval(gc_buffer, &generator->key); in zend_generator_frame_gc()
392 zend_get_gc_buffer_add_zval(gc_buffer, &generator->retval); in zend_generator_frame_gc()
393 zend_get_gc_buffer_add_zval(gc_buffer, &generator->values); in zend_generator_frame_gc()
395 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_frame_gc()
397 call = zend_generator_revert_call_stack(generator->frozen_call_stack); in zend_generator_frame_gc()
402 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_frame_gc()
406 if (generator->node.parent) { in zend_generator_frame_gc()
407 zend_get_gc_buffer_add_obj(gc_buffer, &generator->node.parent->std); in zend_generator_frame_gc()
415 zend_generator *generator = (zend_generator*)object; in zend_generator_get_gc() local
416 zend_execute_data *execute_data = generator->execute_data; in zend_generator_get_gc()
419 if (UNEXPECTED(generator->func->common.fn_flags & ZEND_ACC_CLOSURE)) { in zend_generator_get_gc()
421 zend_get_gc_buffer_add_zval(gc_buffer, &generator->value); in zend_generator_get_gc()
422 zend_get_gc_buffer_add_zval(gc_buffer, &generator->key); in zend_generator_get_gc()
423 zend_get_gc_buffer_add_zval(gc_buffer, &generator->retval); in zend_generator_get_gc()
424 zend_get_gc_buffer_add_obj(gc_buffer, ZEND_CLOSURE_OBJECT(generator->func)); in zend_generator_get_gc()
429 *table = &generator->value; in zend_generator_get_gc()
435 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_get_gc()
446 HashTable *ht = zend_generator_frame_gc(gc_buffer, generator); in zend_generator_get_gc()
455 zend_generator *generator = emalloc(sizeof(zend_generator)); in zend_generator_create() local
456 memset(generator, 0, sizeof(zend_generator)); in zend_generator_create()
459 generator->largest_used_integer_key = -1; in zend_generator_create()
461 ZVAL_UNDEF(&generator->retval); in zend_generator_create()
462 ZVAL_UNDEF(&generator->values); in zend_generator_create()
465 generator->node.parent = NULL; in zend_generator_create()
466 generator->node.children = 0; in zend_generator_create()
467 generator->node.ptr.root = NULL; in zend_generator_create()
469 zend_object_std_init(&generator->std, class_type); in zend_generator_create()
470 return (zend_object*)generator; in zend_generator_create()
486 zend_generator *generator = (zend_generator *) Z_OBJ(ptr->This); in zend_generator_check_placeholder_frame() local
488 ZEND_ASSERT(generator->node.parent && "Placeholder only used with delegation"); in zend_generator_check_placeholder_frame()
489 while (generator->node.parent->node.parent) { in zend_generator_check_placeholder_frame()
490 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
491 prev = generator->execute_data; in zend_generator_check_placeholder_frame()
492 generator = generator->node.parent; in zend_generator_check_placeholder_frame()
494 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
495 ptr = generator->execute_data; in zend_generator_check_placeholder_frame()
501 static void zend_generator_throw_exception(zend_generator *generator, zval *exception) in zend_generator_throw_exception() argument
507 EG(current_execute_data) = generator->execute_data; in zend_generator_throw_exception()
508 generator->execute_data->prev_execute_data = original_execute_data; in zend_generator_throw_exception()
517 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_throw_exception()
518 zval_ptr_dtor(&generator->values); in zend_generator_throw_exception()
519 ZVAL_UNDEF(&generator->values); in zend_generator_throw_exception()
525 static void zend_generator_add_child(zend_generator *generator, zend_generator *child) in zend_generator_add_child() argument
527 zend_generator_node *node = &generator->node; in zend_generator_add_child()
546 void zend_generator_yield_from(zend_generator *generator, zend_generator *from) in zend_generator_yield_from() argument
548 ZEND_ASSERT(!generator->node.parent && "Already has parent?"); in zend_generator_yield_from()
549 zend_generator *leaf = clear_link_to_leaf(generator); in zend_generator_yield_from()
554 generator->node.parent = from; in zend_generator_yield_from()
555 zend_generator_add_child(from, generator); in zend_generator_yield_from()
556 generator->flags |= ZEND_GENERATOR_DO_INIT; in zend_generator_yield_from()
559 ZEND_API zend_generator *zend_generator_update_root(zend_generator *generator) in zend_generator_update_root() argument
561 zend_generator *root = generator->node.parent; in zend_generator_update_root()
567 root->node.ptr.leaf = generator; in zend_generator_update_root()
568 generator->node.ptr.root = root; in zend_generator_update_root()
572 static zend_generator *get_new_root(zend_generator *generator, zend_generator *root) in get_new_root() argument
584 while (generator->node.parent->execute_data) { in get_new_root()
585 generator = generator->node.parent; in get_new_root()
588 return generator; in get_new_root()
591 ZEND_API zend_generator *zend_generator_update_current(zend_generator *generator) in zend_generator_update_current() argument
593 zend_generator *old_root = generator->node.ptr.root; in zend_generator_update_current()
596 zend_generator *new_root = get_new_root(generator, old_root); in zend_generator_update_current()
598 ZEND_ASSERT(old_root->node.ptr.leaf == generator); in zend_generator_update_current()
599 generator->node.ptr.root = new_root; in zend_generator_update_current()
600 new_root->node.ptr.leaf = generator; in zend_generator_update_current()
607 …if (EXPECTED(EG(exception) == NULL) && EXPECTED((OBJ_FLAGS(&generator->std) & IS_OBJ_DESTRUCTOR_CA… in zend_generator_update_current()
616 if (new_root == generator) { in zend_generator_update_current()
619 new_root->execute_data->prev_execute_data = &generator->execute_fake; in zend_generator_update_current()
620 generator->execute_fake.prev_execute_data = original_execute_data; in zend_generator_update_current()
630 zend_generator_resume(generator); in zend_generator_update_current()
631 return zend_generator_get_current(generator); in zend_generator_update_current()
647 static zend_result zend_generator_get_next_delegated_value(zend_generator *generator) /* {{{ */ in zend_generator_get_next_delegated_value() argument
650 if (Z_TYPE(generator->values) == IS_ARRAY) { in zend_generator_get_next_delegated_value()
651 HashTable *ht = Z_ARR(generator->values); in zend_generator_get_next_delegated_value()
652 HashPosition pos = Z_FE_POS(generator->values); in zend_generator_get_next_delegated_value()
665 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
666 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
668 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
669 ZVAL_LONG(&generator->key, pos - 1); in zend_generator_get_next_delegated_value()
684 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
685 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
687 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
689 ZVAL_STR_COPY(&generator->key, p->key); in zend_generator_get_next_delegated_value()
691 ZVAL_LONG(&generator->key, p->h); in zend_generator_get_next_delegated_value()
694 Z_FE_POS(generator->values) = pos; in zend_generator_get_next_delegated_value()
696 zend_object_iterator *iter = (zend_object_iterator *) Z_OBJ(generator->values); in zend_generator_get_next_delegated_value()
715 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
716 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
718 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
720 iter->funcs->get_current_key(iter, &generator->key); in zend_generator_get_next_delegated_value()
722 ZVAL_UNDEF(&generator->key); in zend_generator_get_next_delegated_value()
726 ZVAL_LONG(&generator->key, iter->index); in zend_generator_get_next_delegated_value()
733 zval_ptr_dtor(&generator->values); in zend_generator_get_next_delegated_value()
734 ZVAL_UNDEF(&generator->values); in zend_generator_get_next_delegated_value()
742 zend_generator *generator = zend_generator_get_current(orig_generator); in zend_generator_resume() local
745 if (UNEXPECTED(!generator->execute_data)) { in zend_generator_resume()
750 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_resume()
755 …if (UNEXPECTED((orig_generator->flags & ZEND_GENERATOR_DO_INIT) != 0 && !Z_ISUNDEF(generator->valu… in zend_generator_resume()
763 generator->flags |= ZEND_GENERATOR_IN_FIBER; in zend_generator_resume()
774 EG(current_execute_data) = generator->execute_data; in zend_generator_resume()
780 if (generator == orig_generator) { in zend_generator_resume()
781 generator->execute_data->prev_execute_data = original_execute_data; in zend_generator_resume()
785 generator->execute_data->prev_execute_data = &orig_generator->execute_fake; in zend_generator_resume()
790 if (UNEXPECTED(!Z_ISUNDEF(generator->values))) { in zend_generator_resume()
791 if (EXPECTED(zend_generator_get_next_delegated_value(generator) == SUCCESS)) { in zend_generator_resume()
797 generator->flags &= ~ZEND_GENERATOR_IN_FIBER; in zend_generator_resume()
804 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_resume()
806 zend_generator_restore_call_stack(generator); in zend_generator_resume()
810 ZEND_ASSERT(generator->execute_data->opline->opcode == ZEND_GENERATOR_CREATE in zend_generator_resume()
811 || generator->execute_data->opline->opcode == ZEND_YIELD in zend_generator_resume()
812 || generator->execute_data->opline->opcode == ZEND_YIELD_FROM in zend_generator_resume()
815 || generator->execute_data->opline->opcode == ZEND_HANDLE_EXCEPTION in zend_generator_resume()
818 || (generator->flags & ZEND_GENERATOR_FORCED_CLOSE)); in zend_generator_resume()
819 generator->execute_data->opline++; in zend_generator_resume()
820 generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING; in zend_generator_resume()
822 zend_execute_ex(generator->execute_data); in zend_generator_resume()
824 zend_observer_generator_resume(generator->execute_data); in zend_generator_resume()
825 zend_execute_ex(generator->execute_data); in zend_generator_resume()
826 if (generator->execute_data) { in zend_generator_resume()
828 zend_observer_fcall_end(generator->execute_data, &generator->value); in zend_generator_resume()
831 generator->flags &= ~(ZEND_GENERATOR_CURRENTLY_RUNNING | ZEND_GENERATOR_IN_FIBER); in zend_generator_resume()
833 generator->frozen_call_stack = NULL; in zend_generator_resume()
834 if (EXPECTED(generator->execute_data) && in zend_generator_resume()
835 UNEXPECTED(generator->execute_data->call)) { in zend_generator_resume()
837 generator->frozen_call_stack = zend_generator_freeze_call_stack(generator->execute_data); in zend_generator_resume()
849 if (generator == orig_generator) { in zend_generator_resume()
850 zend_generator_close(generator, 0); in zend_generator_resume()
858 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
859 zend_generator_throw_exception(generator, NULL); in zend_generator_resume()
866 …if (UNEXPECTED((generator != orig_generator && !Z_ISUNDEF(generator->retval)) || (generator->execu… in zend_generator_resume()
867 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
875 static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */ in zend_generator_ensure_initialized() argument
877 …if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPEC… in zend_generator_ensure_initialized()
878 zend_generator_resume(generator); in zend_generator_ensure_initialized()
879 generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD; in zend_generator_ensure_initialized()
884 static inline void zend_generator_rewind(zend_generator *generator) /* {{{ */ in zend_generator_rewind() argument
886 zend_generator_ensure_initialized(generator); in zend_generator_rewind()
888 if (!(generator->flags & ZEND_GENERATOR_AT_FIRST_YIELD)) { in zend_generator_rewind()
897 zend_generator *generator; in ZEND_METHOD() local
901 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
903 zend_generator_rewind(generator); in ZEND_METHOD()
910 zend_generator *generator; in ZEND_METHOD() local
914 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
916 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
918 zend_generator_get_current(generator); in ZEND_METHOD()
920 RETURN_BOOL(EXPECTED(generator->execute_data != NULL)); in ZEND_METHOD()
927 zend_generator *generator, *root; in ZEND_METHOD() local
931 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
933 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
935 root = zend_generator_get_current(generator); in ZEND_METHOD()
936 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->value) != IS_UNDEF)) { in ZEND_METHOD()
945 zend_generator *generator, *root; in ZEND_METHOD() local
949 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
951 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
953 root = zend_generator_get_current(generator); in ZEND_METHOD()
954 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->key) != IS_UNDEF)) { in ZEND_METHOD()
963 zend_generator *generator; in ZEND_METHOD() local
967 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
969 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
971 zend_generator_resume(generator); in ZEND_METHOD()
979 zend_generator *generator, *root; in ZEND_METHOD() local
985 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
987 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
990 if (UNEXPECTED(!generator->execute_data)) { in ZEND_METHOD()
994 root = zend_generator_get_current(generator); in ZEND_METHOD()
1000 zend_generator_resume(generator); in ZEND_METHOD()
1002 root = zend_generator_get_current(generator); in ZEND_METHOD()
1003 if (EXPECTED(generator->execute_data)) { in ZEND_METHOD()
1013 zend_generator *generator; in ZEND_METHOD() local
1021 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
1023 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
1025 if (generator->execute_data) { in ZEND_METHOD()
1026 zend_generator *root = zend_generator_get_current(generator); in ZEND_METHOD()
1030 zend_generator_resume(generator); in ZEND_METHOD()
1032 root = zend_generator_get_current(generator); in ZEND_METHOD()
1033 if (generator->execute_data) { in ZEND_METHOD()
1047 zend_generator *generator; in ZEND_METHOD() local
1051 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
1053 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
1058 if (Z_ISUNDEF(generator->retval)) { in ZEND_METHOD()
1065 ZVAL_COPY(return_value, &generator->retval); in ZEND_METHOD()
1071 zend_generator *generator; in ZEND_METHOD() local
1075 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
1079 zend_function *func = generator->func; in ZEND_METHOD()
1108 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_valid() local
1110 zend_generator_ensure_initialized(generator); in zend_generator_iterator_valid()
1112 zend_generator_get_current(generator); in zend_generator_iterator_valid()
1114 return generator->execute_data ? SUCCESS : FAILURE; in zend_generator_iterator_valid()
1120 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_data() local
1122 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_data()
1124 root = zend_generator_get_current(generator); in zend_generator_iterator_get_data()
1132 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_key() local
1134 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_key()
1136 root = zend_generator_get_current(generator); in zend_generator_iterator_get_key()
1150 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_move_forward() local
1152 zend_generator_ensure_initialized(generator); in zend_generator_iterator_move_forward()
1154 zend_generator_resume(generator); in zend_generator_iterator_move_forward()
1160 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_rewind() local
1162 zend_generator_rewind(generator); in zend_generator_iterator_rewind()
1189 zend_generator *generator = (zend_generator*)Z_OBJ_P(object); in zend_generator_get_iterator() local
1191 if (!generator->execute_data) { in zend_generator_get_iterator()
1196 …if (UNEXPECTED(by_ref) && !(generator->execute_data->func->op_array.fn_flags & ZEND_ACC_RETURN_REF… in zend_generator_get_iterator()