Skip to content

Commit 226130c

Browse files
committed
Enhance Fiber coroutine handling by initializing result storage and clarifying ownership in comments
1 parent 29b8243 commit 226130c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Zend/zend_fibers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,9 @@ static zend_object *zend_fiber_object_create(zend_class_entry *ce)
12101210
ZEND_COROUTINE_SET_FIBER(fiber->coroutine);
12111211
fiber->coroutine->extended_data = fiber;
12121212
fiber->coroutine->internal_entry = coroutine_entry_point;
1213+
1214+
/* Initialize coroutine result storage for fiber */
1215+
ZVAL_UNDEF(&fiber->coroutine->result);
12131216
}
12141217

12151218
zend_async_scope_t *scope = ZEND_ASYNC_CURRENT_SCOPE;

Zend/zend_fibers.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,27 @@ struct _zend_fiber {
129129
/* Fiber that suspended us. */
130130
zend_fiber_context *previous;
131131

132-
/* Callback and info / cache to be used when fiber is started. */
132+
/*
133+
* Callback and info / cache to be used when fiber is started.
134+
* IMPORTANT: When fiber->coroutine != NULL, these fields are NOT USED.
135+
* Instead, fiber->fcall is used (see below).
136+
* Only used for non-coroutine path (fiber->coroutine == NULL).
137+
*/
133138
zend_fcall_info fci;
134139
zend_fcall_info_cache fci_cache;
135140

141+
/*
142+
* Pointer to allocated zend_fcall_t structure for coroutine path.
143+
* OWNERSHIP:
144+
* - Fiber allocates on creation and TEMPORARILY owns it
145+
* - coroutine_entry_point TAKES ownership (sets fiber->fcall to NULL)
146+
* - coroutine_entry_point FREES it at the end
147+
* NULL when:
148+
* - fiber->coroutine == NULL (non-coroutine path)
149+
* - Ownership already taken by coroutine_entry_point
150+
*/
151+
zend_fcall_t *fcall;
152+
136153
/* Current Zend VM execute data being run by the fiber. */
137154
zend_execute_data *execute_data;
138155

@@ -142,7 +159,12 @@ struct _zend_fiber {
142159
/* Active fiber vm stack. */
143160
zend_vm_stack vm_stack;
144161

145-
/* Storage for fiber return value. */
162+
/*
163+
* Storage for fiber return value.
164+
* IMPORTANT: When fiber->coroutine != NULL, this field is NOT USED.
165+
* Result is stored in coroutine->result instead.
166+
* Only used for non-coroutine path (fiber->coroutine == NULL).
167+
*/
146168
zval result;
147169
};
148170

0 commit comments

Comments
 (0)