Skip to content

Commit 0480661

Browse files
committed
Rearranged some code, added comment and simplified access to caller.
1 parent 9e7295c commit 0480661

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
@@ -269,20 +269,21 @@ ZEND_API zend_fiber_context *zend_fiber_switch_context(zend_fiber_context *to)
269269

270270
EG(current_fiber) = from;
271271

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

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

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

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

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

495-
zend_fiber_switch_context(zend_fiber_get_context(fiber)->caller);
496+
zend_fiber_switch_context(fiber->caller);
496497

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

0 commit comments

Comments
 (0)