@@ -328,7 +328,8 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
328
328
Z_OBJ_P (fast_call ) = NULL ;
329
329
Z_OPLINE_NUM_P (fast_call ) = (uint32_t )-1 ;
330
330
331
- ex -> opline = & ex -> func -> op_array .opcodes [try_catch -> finally_op ];
331
+ /* -1 because zend_generator_resume() will increment it */
332
+ ex -> opline = & ex -> func -> op_array .opcodes [try_catch -> finally_op ] - 1 ;
332
333
generator -> flags |= ZEND_GENERATOR_FORCED_CLOSE ;
333
334
zend_generator_resume (generator );
334
335
@@ -814,20 +815,17 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
814
815
zend_generator_restore_call_stack (generator );
815
816
}
816
817
817
- /* Resume execution
818
- *
819
- * Increment opline to point after the CREATE_GENERATOR / YIELD / YIELD_FROM
820
- * op, unless an exception was thrown (opline is EG(exception_op)), or the
821
- * generator is being force-closed (opline points to the start of a finally
822
- * block).
823
- */
824
- if (EXPECTED (generator -> execute_data -> opline -> opcode != ZEND_HANDLE_EXCEPTION
825
- && !(generator -> flags & ZEND_GENERATOR_FORCED_CLOSE ))) {
826
- ZEND_ASSERT (generator -> execute_data -> opline -> opcode == ZEND_GENERATOR_CREATE
827
- || generator -> execute_data -> opline -> opcode == ZEND_YIELD
828
- || generator -> execute_data -> opline -> opcode == ZEND_YIELD_FROM );
829
- generator -> execute_data -> opline ++ ;
830
- }
818
+ /* Resume execution */
819
+ ZEND_ASSERT (generator -> execute_data -> opline -> opcode == ZEND_GENERATOR_CREATE
820
+ || generator -> execute_data -> opline -> opcode == ZEND_YIELD
821
+ || generator -> execute_data -> opline -> opcode == ZEND_YIELD_FROM
822
+ /* opline points to EG(exception_op), which is a sequence of
823
+ * ZEND_HANDLE_EXCEPTION ops, so the following increment is safe */
824
+ || generator -> execute_data -> opline -> opcode == ZEND_HANDLE_EXCEPTION
825
+ /* opline points to the start of a finally block minus one op to
826
+ * account for the following increment */
827
+ || (generator -> flags & ZEND_GENERATOR_FORCED_CLOSE ));
828
+ generator -> execute_data -> opline ++ ;
831
829
generator -> flags |= ZEND_GENERATOR_CURRENTLY_RUNNING ;
832
830
if (!ZEND_OBSERVER_ENABLED ) {
833
831
zend_execute_ex (generator -> execute_data );
0 commit comments