@@ -199,7 +199,7 @@ static ZEND_NORETURN void zend_fiber_trampoline(transfer_t transfer)
199
199
abort ();
200
200
}
201
201
202
- ZEND_API bool zend_fiber_init_context (zend_fiber_context * context , zend_fiber_coroutine coroutine , size_t stack_size )
202
+ ZEND_API bool zend_fiber_init_context (zend_fiber_context * context , void * kind , zend_fiber_coroutine coroutine , size_t stack_size )
203
203
{
204
204
if (UNEXPECTED (!zend_fiber_stack_allocate (& context -> stack , stack_size ))) {
205
205
return false;
@@ -211,6 +211,7 @@ ZEND_API bool zend_fiber_init_context(zend_fiber_context *context, zend_fiber_co
211
211
context -> handle = make_fcontext (stack , context -> stack .size , zend_fiber_trampoline );
212
212
ZEND_ASSERT (context -> handle != NULL && "make_fcontext() never returns NULL" );
213
213
214
+ context -> kind = kind ;
214
215
context -> function = coroutine ;
215
216
216
217
return true;
@@ -256,7 +257,7 @@ static void zend_fiber_suspend_from(zend_fiber *fiber)
256
257
ZEND_ASSERT (fiber -> caller && "Fiber has no caller" );
257
258
258
259
zend_fiber_capture_vm_state (& state );
259
- zend_fiber_switch_context (zend_fiber_get_context ( fiber -> caller ) );
260
+ zend_fiber_switch_context (fiber -> caller );
260
261
zend_fiber_restore_vm_state (& state );
261
262
}
262
263
@@ -267,7 +268,7 @@ static void zend_fiber_switch_to(zend_fiber *fiber)
267
268
268
269
zend_observer_fiber_switch_notify (EG (current_fiber ), context );
269
270
270
- fiber -> caller = zend_fiber_from_context ( EG (current_fiber ) );
271
+ fiber -> caller = EG (current_fiber );
271
272
272
273
zend_fiber_capture_vm_state (& state );
273
274
zend_fiber_switch_context (context );
@@ -352,7 +353,7 @@ static ZEND_STACK_ALIGNED zend_fiber_context *zend_fiber_execute(zend_fiber_cont
352
353
fiber -> execute_data = NULL ;
353
354
fiber -> stack_bottom = NULL ;
354
355
355
- return zend_fiber_get_context ( fiber -> caller ) ;
356
+ return fiber -> caller ;
356
357
}
357
358
358
359
static zend_object * zend_fiber_object_create (zend_class_entry * ce )
@@ -451,7 +452,7 @@ ZEND_API void zend_fiber_start(zend_fiber *fiber, zval *params, uint32_t param_c
451
452
fiber -> fci .param_count = param_count ;
452
453
fiber -> fci .named_params = named_params ;
453
454
454
- if (!zend_fiber_init_context (zend_fiber_get_context (fiber ), zend_fiber_execute , EG (fiber_stack_size ))) {
455
+ if (!zend_fiber_init_context (zend_fiber_get_context (fiber ), zend_ce_fiber , zend_fiber_execute , EG (fiber_stack_size ))) {
455
456
RETURN_THROWS ();
456
457
}
457
458
@@ -481,7 +482,7 @@ ZEND_METHOD(Fiber, start)
481
482
482
483
ZEND_API void zend_fiber_suspend (zval * value , zval * return_value )
483
484
{
484
- if (UNEXPECTED (EG (current_fiber ) == EG ( main_fiber ) )) {
485
+ if (UNEXPECTED (EG (current_fiber )-> kind != zend_ce_fiber )) {
485
486
zend_throw_error (zend_ce_fiber_error , "Cannot suspend outside of a fiber" );
486
487
RETURN_THROWS ();
487
488
}
@@ -692,7 +693,7 @@ ZEND_METHOD(Fiber, this)
692
693
{
693
694
ZEND_PARSE_PARAMETERS_NONE ();
694
695
695
- if (EG (current_fiber ) == EG ( main_fiber ) ) {
696
+ if (EG (current_fiber )-> kind != zend_ce_fiber ) {
696
697
RETURN_NULL ();
697
698
}
698
699
0 commit comments