@@ -4459,7 +4459,24 @@ ZEND_API void zend_cleanup_unfinished_execution(zend_execute_data *execute_data,
44594459 cleanup_live_vars (execute_data , op_num , catch_op_num );
44604460}
44614461
4462- ZEND_API HashTable * zend_unfinished_execution_gc (zend_execute_data * execute_data , zend_execute_data * call , zend_get_gc_buffer * gc_buffer )
4462+ ZEND_API ZEND_ATTRIBUTE_DEPRECATED HashTable * zend_unfinished_execution_gc (zend_execute_data * execute_data , zend_execute_data * call , zend_get_gc_buffer * gc_buffer )
4463+ {
4464+ bool suspended_by_yield = false;
4465+
4466+ if (Z_TYPE_INFO (EX (This )) & ZEND_CALL_GENERATOR ) {
4467+ ZEND_ASSERT (EX (return_value ));
4468+
4469+ /* The generator object is stored in EX(return_value) */
4470+ zend_generator * generator = (zend_generator * ) EX (return_value );
4471+ ZEND_ASSERT (execute_data == generator -> execute_data );
4472+
4473+ suspended_by_yield = !(generator -> flags & ZEND_GENERATOR_CURRENTLY_RUNNING );
4474+ }
4475+
4476+ return zend_unfinished_execution_gc_ex (execute_data , call , gc_buffer , suspended_by_yield );
4477+ }
4478+
4479+ ZEND_API HashTable * zend_unfinished_execution_gc_ex (zend_execute_data * execute_data , zend_execute_data * call , zend_get_gc_buffer * gc_buffer , bool suspended_by_yield )
44634480{
44644481 if (!EX (func ) || !ZEND_USER_CODE (EX (func )-> common .type )) {
44654482 return NULL ;
@@ -4495,8 +4512,15 @@ ZEND_API HashTable *zend_unfinished_execution_gc(zend_execute_data *execute_data
44954512 }
44964513
44974514 if (call ) {
4498- /* -1 required because we want the last run opcode, not the next to-be-run one. */
4499- uint32_t op_num = execute_data -> opline - op_array -> opcodes - 1 ;
4515+ uint32_t op_num = execute_data -> opline - op_array -> opcodes ;
4516+ if (suspended_by_yield ) {
4517+ /* When the execution was suspended by yield, EX(opline) points to
4518+ * next opline to execute. Otherwise, it points to the opline that
4519+ * suspended execution. */
4520+ op_num -- ;
4521+ ZEND_ASSERT (EX (func )-> op_array .opcodes [op_num ].opcode == ZEND_YIELD
4522+ || EX (func )-> op_array .opcodes [op_num ].opcode == ZEND_YIELD_FROM );
4523+ }
45004524 zend_unfinished_calls_gc (execute_data , call , op_num , gc_buffer );
45014525 }
45024526
0 commit comments