Skip to content

Commit

Permalink
Keep consistent EG(current_execute_data) after return from generator (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov authored Jun 8, 2023
1 parent 5604f7a commit 06d6873
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,8 @@ ZEND_VM_HANDLER(161, ZEND_GENERATOR_RETURN, CONST|TMP|VAR|CV, ANY, SPEC(OBSERVER

ZEND_OBSERVER_FCALL_END(generator->execute_data, &generator->retval);

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down Expand Up @@ -7837,6 +7839,7 @@ ZEND_VM_HELPER(zend_dispatch_try_catch_finally_helper, ANY, ANY, uint32_t try_ca
cleanup_live_vars(execute_data, op_num, 0);
if (UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_GENERATOR) != 0)) {
zend_generator *generator = zend_get_running_generator(EXECUTE_DATA_C);
EG(current_execute_data) = EX(prev_execute_data);
zend_generator_close(generator, 1);
ZEND_VM_RETURN();
} else {
Expand Down Expand Up @@ -7930,6 +7933,7 @@ ZEND_VM_HANDLER(150, ZEND_USER_OPCODE, ANY, ANY)
case ZEND_USER_OPCODE_RETURN:
if (UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_GENERATOR) != 0)) {
zend_generator *generator = zend_get_running_generator(EXECUTE_DATA_C);
EG(current_execute_data) = EX(prev_execute_data);
zend_generator_close(generator, 1);
ZEND_VM_RETURN();
} else {
Expand Down
12 changes: 12 additions & 0 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3061,6 +3061,7 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_dispatch_try
cleanup_live_vars(execute_data, op_num, 0);
if (UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_GENERATOR) != 0)) {
zend_generator *generator = zend_get_running_generator(EXECUTE_DATA_C);
EG(current_execute_data) = EX(prev_execute_data);
zend_generator_close(generator, 1);
ZEND_VM_RETURN();
} else {
Expand Down Expand Up @@ -3154,6 +3155,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_USER_OPCODE_SPEC_HANDLER(ZEND_
case ZEND_USER_OPCODE_RETURN:
if (UNEXPECTED((EX_CALL_INFO() & ZEND_CALL_GENERATOR) != 0)) {
zend_generator *generator = zend_get_running_generator(EXECUTE_DATA_C);
EG(current_execute_data) = EX(prev_execute_data);
zend_generator_close(generator, 1);
ZEND_VM_RETURN();
} else {
Expand Down Expand Up @@ -4517,6 +4519,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_RETURN_SPEC_CONST_HA
}
}

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down Expand Up @@ -4562,6 +4566,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_RETURN_SPEC_OBSERVER

zend_observer_fcall_end(generator->execute_data, &generator->retval);

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down Expand Up @@ -18954,6 +18960,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_RETURN_SPEC_TMP_HAND
}
}

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down Expand Up @@ -21612,6 +21620,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_RETURN_SPEC_VAR_HAND
}
}

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down Expand Up @@ -38480,6 +38490,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_GENERATOR_RETURN_SPEC_CV_HANDL
}
}

EG(current_execute_data) = EX(prev_execute_data);

/* Close the generator to free up resources */
zend_generator_close(generator, 1);

Expand Down

0 comments on commit 06d6873

Please sign in to comment.