2727#include " zend_builtin_functions.h"
2828#include " ext/spl/spl_array.h"
2929
30- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
3130#include " zend_observer.h"
32- #endif
3331
3432#include < unordered_map>
3533#include < chrono>
@@ -45,17 +43,6 @@ using swoole::PHPCoroutine;
4543using swoole::coroutine::Socket;
4644using swoole::coroutine::System;
4745
48- #if PHP_VERSION_ID < 80100
49- static zend_always_inline zend_vm_stack zend_vm_stack_new_page (size_t size, zend_vm_stack prev) {
50- zend_vm_stack page = (zend_vm_stack) emalloc (size);
51-
52- page->top = ZEND_VM_STACK_ELEMENTS (page);
53- page->end = (zval *) ((char *) page + size);
54- page->prev = prev;
55- return page;
56- }
57- #endif
58-
5946enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1 , SW_EXIT_IN_SERVER = 1 << 2 };
6047
6148SW_THREAD_LOCAL bool PHPCoroutine::activated = false ;
@@ -302,9 +289,6 @@ static void coro_interrupt_function(zend_execute_data *execute_data) {
302289PHPContext *PHPCoroutine::create_context (Args *args) {
303290 PHPContext *ctx = (PHPContext *) emalloc (sizeof (PHPContext));
304291 ctx->output_ptr = nullptr ;
305- #if PHP_VERSION_ID < 80100
306- ctx->array_walk_fci = nullptr ;
307- #endif
308292 ctx->in_silence = false ;
309293
310294 ctx->co = Coroutine::get_current ();
@@ -317,10 +301,8 @@ PHPContext *PHPCoroutine::create_context(Args *args) {
317301 ctx->on_close = nullptr ;
318302 ctx->enable_scheduler = true ;
319303
320- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
321304 fiber_context_try_init (ctx);
322305 ctx->fiber_init_notified = false ;
323- #endif
324306
325307 EG (vm_stack) = zend_vm_stack_new_page (SW_DEFAULT_PHP_STACK_PAGE_SIZE, nullptr );
326308 EG (vm_stack_top) = EG (vm_stack)->top + ZEND_CALL_FRAME_SLOT;
@@ -522,15 +504,6 @@ inline void PHPCoroutine::save_vm_stack(PHPContext *ctx) {
522504 ctx->error_handling = EG (error_handling);
523505 ctx->exception_class = EG (exception_class);
524506 ctx->exception = EG (exception);
525- #if PHP_VERSION_ID < 80100
526- if (UNEXPECTED (BG (array_walk_fci).size != 0 )) {
527- if (!ctx->array_walk_fci ) {
528- ctx->array_walk_fci = (zend::Function *) emalloc (sizeof (*ctx->array_walk_fci ));
529- }
530- memcpy (ctx->array_walk_fci , &BG (array_walk_fci), sizeof (*ctx->array_walk_fci ));
531- memset (&BG (array_walk_fci), 0 , sizeof (*ctx->array_walk_fci ));
532- }
533- #endif
534507 if (UNEXPECTED (ctx->in_silence )) {
535508 ctx->tmp_error_reporting = EG (error_reporting);
536509 EG (error_reporting) = ctx->ori_error_reporting ;
@@ -552,12 +525,6 @@ inline void PHPCoroutine::restore_vm_stack(PHPContext *ctx) {
552525 EG (error_handling) = ctx->error_handling ;
553526 EG (exception_class) = ctx->exception_class ;
554527 EG (exception) = ctx->exception ;
555- #if PHP_VERSION_ID < 80100
556- if (UNEXPECTED (ctx->array_walk_fci && ctx->array_walk_fci ->fci .size != 0 )) {
557- memcpy (&BG (array_walk_fci), ctx->array_walk_fci , sizeof (*ctx->array_walk_fci ));
558- ctx->array_walk_fci ->fci .size = 0 ;
559- }
560- #endif
561528 if (UNEXPECTED (ctx->in_silence )) {
562529 EG (error_reporting) = ctx->tmp_error_reporting ;
563530 }
@@ -614,9 +581,7 @@ void PHPCoroutine::on_yield(void *arg) {
614581 PHPContext *ctx = (PHPContext *) arg;
615582 PHPContext *origin_ctx = get_origin_context (ctx);
616583
617- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
618584 fiber_context_switch_try_notify (ctx, origin_ctx);
619- #endif
620585 save_context (ctx);
621586 restore_context (origin_ctx);
622587
@@ -631,9 +596,7 @@ void PHPCoroutine::on_resume(void *arg) {
631596 PHPContext *ctx = (PHPContext *) arg;
632597 PHPContext *current_ctx = get_context ();
633598
634- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
635599 fiber_context_switch_try_notify (current_ctx, ctx);
636- #endif
637600 save_context (current_ctx);
638601 restore_context (ctx);
639602 record_last_msec (ctx);
@@ -676,11 +639,6 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
676639 php_output_activate ();
677640 SG (request_info).no_headers = no_headers;
678641 }
679- #if PHP_VERSION_ID < 80100
680- if (ctx->array_walk_fci ) {
681- efree (ctx->array_walk_fci );
682- }
683- #endif
684642
685643 if (ctx->defer_tasks ) {
686644 while (!ctx->defer_tasks ->empty ()) {
@@ -706,10 +664,8 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
706664
707665 Z_TRY_DELREF (ctx->return_value );
708666
709- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
710667 fiber_context_switch_try_notify (ctx, origin_ctx);
711668 fiber_context_try_destroy (ctx);
712- #endif
713669
714670 swoole_trace_log (SW_TRACE_COROUTINE,
715671 " coro close cid=%ld and resume to %ld, %zu remained. usage size: %zu. malloc size: %zu" ,
@@ -740,8 +696,7 @@ void PHPCoroutine::main_func(void *_args) {
740696 swoole_call_hook (SW_GLOBAL_HOOK_ON_CORO_START, ctx);
741697 }
742698
743- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
744- if (EXPECTED (SWOOLE_G (enable_fiber_mock) && ctx->fci_cache .function_handler ->type == ZEND_USER_FUNCTION)) {
699+ if (UNEXPECTED (SWOOLE_G (enable_fiber_mock) && ctx->fci_cache .function_handler ->type == ZEND_USER_FUNCTION)) {
745700 zend_execute_data *tmp = EG (current_execute_data);
746701 zend_execute_data call = {};
747702 EG (current_execute_data) = &call;
@@ -750,7 +705,7 @@ void PHPCoroutine::main_func(void *_args) {
750705 fiber_context_switch_try_notify (get_origin_context (ctx), ctx);
751706 EG (current_execute_data) = tmp;
752707 }
753- # endif
708+
754709 zend_call_function (&ctx->fci , &ctx->fci_cache );
755710
756711 // Catch exception in main function of the coroutine
@@ -828,8 +783,6 @@ void PHPCoroutine::defer(zend::Function *fci) {
828783 ctx->defer_tasks ->push (fci);
829784}
830785
831- #ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
832-
833786void PHPCoroutine::fiber_context_init (PHPContext *ctx) {
834787 zend_fiber_context *fiber_context = (zend_fiber_context *) emalloc (sizeof (*fiber_context));
835788 fiber_context->handle = (void *) -1 ;
@@ -907,7 +860,6 @@ void PHPCoroutine::fiber_context_switch_try_notify(PHPContext *from, PHPContext
907860 }
908861 fiber_context_switch_notify (from, to);
909862}
910- #endif /* SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT */
911863
912864#ifdef ZEND_CHECK_STACK_LIMIT
913865void *PHPCoroutine::stack_limit (PHPContext *ctx) {
0 commit comments