Skip to content

Commit 2319a5b

Browse files
kooldevtrowski
authored andcommitted
Rearranged some code, added comment and simplified access to caller.
1 parent 5493fcc commit 2319a5b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Zend/zend_fibers.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,21 @@ ZEND_API zend_fiber_context *zend_fiber_switch_context(zend_fiber_context *to)
270270

271271
EG(current_fiber) = from;
272272

273-
zend_fiber_restore_vm_state(&state);
274-
275273
zend_fiber_context *previous = transfer.data;
276274
previous->handle = transfer.context;
277275

278-
if (UNEXPECTED(previous->flags & ZEND_FIBER_FLAG_BAILOUT)) {
279-
// zend_bailout() was called in the fiber, so call it again in the previous fiber or {main}.
280-
zend_bailout();
281-
}
276+
zend_fiber_restore_vm_state(&state);
282277

278+
/* Destroy context first to ensure it does not leak if some extension does custom bailout handling. */
283279
if (previous->status == ZEND_FIBER_STATUS_DEAD) {
284280
zend_fiber_destroy_context(previous);
285281
}
286282

283+
/* Propagate bailout to current fiber / main. */
284+
if (UNEXPECTED(previous->flags & ZEND_FIBER_FLAG_BAILOUT)) {
285+
zend_bailout();
286+
}
287+
287288
return previous;
288289
}
289290

@@ -493,7 +494,7 @@ ZEND_METHOD(Fiber, suspend)
493494
fiber->execute_data = EG(current_execute_data);
494495
fiber->stack_bottom->prev_execute_data = NULL;
495496

496-
zend_fiber_switch_context(zend_fiber_get_context(fiber)->caller);
497+
zend_fiber_switch_context(fiber->caller);
497498

498499
if (fiber->flags & ZEND_FIBER_FLAG_DESTROYED) {
499500
// This occurs when the fiber is GC'ed while suspended.

0 commit comments

Comments
 (0)