Skip to content

Commit 70dd6e6

Browse files
committed
Review
1 parent 42b363f commit 70dd6e6

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Zend/zend_generators.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ static void zend_generator_dtor_storage(zend_object *object) /* {{{ */
328328
Z_OBJ_P(fast_call) = NULL;
329329
Z_OPLINE_NUM_P(fast_call) = (uint32_t)-1;
330330

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;
332333
generator->flags |= ZEND_GENERATOR_FORCED_CLOSE;
333334
zend_generator_resume(generator);
334335

@@ -814,20 +815,17 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
814815
zend_generator_restore_call_stack(generator);
815816
}
816817

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++;
831829
generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING;
832830
if (!ZEND_OBSERVER_ENABLED) {
833831
zend_execute_ex(generator->execute_data);

0 commit comments

Comments
 (0)