From 7429f2874edf6746a420f56d5477b7dc52d85d45 Mon Sep 17 00:00:00 2001 From: Jurijs Cerepanovs Date: Thu, 5 Mar 2026 22:46:32 +0200 Subject: [PATCH 1/2] Export zend_autoload original handler function pointer --- ext-src/php_swoole_private.h | 3 +++ ext-src/swoole_coroutine.cc | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ext-src/php_swoole_private.h b/ext-src/php_swoole_private.h index 5b5f1d23c2a..19f7a78214b 100644 --- a/ext-src/php_swoole_private.h +++ b/ext-src/php_swoole_private.h @@ -190,6 +190,9 @@ extern zend_class_entry *swoole_error_ce; extern zend_class_entry *swoole_resolve_context_ce; extern zend_object_handlers swoole_resolve_context_handlers; +// Export zend_autoload hook +extern zend_class_entry *(*swoole_hook_zend_autoload)(zend_string *name, zend_string *lc_name); + PHP_FUNCTION(swoole_clear_dns_cache); PHP_FUNCTION(swoole_last_error); PHP_FUNCTION(swoole_set_process_name); diff --git a/ext-src/swoole_coroutine.cc b/ext-src/swoole_coroutine.cc index 2fa34eb2507..41304164a15 100644 --- a/ext-src/swoole_coroutine.cc +++ b/ext-src/swoole_coroutine.cc @@ -953,8 +953,7 @@ void *PHPCoroutine::stack_base(PHPContext *ctx) { #endif /* ZEND_CHECK_STACK_LIMIT */ /* hook autoload */ - -static zend_class_entry *(*original_zend_autoload)(zend_string *name, zend_string *lc_name); +zend_class_entry *(*swoole_hook_zend_autoload)(zend_string *name, zend_string *lc_name) = nullptr; struct AutoloadContext { Coroutine *coroutine; @@ -969,7 +968,7 @@ struct AutoloadQueue { static zend_class_entry *swoole_coroutine_autoload(zend_string *name, zend_string *lc_name) { auto current = Coroutine::get_current(); if (!current) { - return original_zend_autoload(name, lc_name); + return swoole_hook_zend_autoload(name, lc_name); } ZEND_ASSERT(EG(in_autoload) != nullptr); @@ -998,7 +997,7 @@ static zend_class_entry *swoole_coroutine_autoload(zend_string *name, zend_strin queue.queue = &queue_object; zend_hash_add_ptr(SWOOLE_G(in_autoload), lc_name, &queue); - zend_class_entry *ce = original_zend_autoload(name, lc_name); + zend_class_entry *ce = swoole_hook_zend_autoload(name, lc_name); zend_hash_del(SWOOLE_G(in_autoload), lc_name); AutoloadContext *pending_context = nullptr; @@ -1066,7 +1065,7 @@ void php_swoole_coroutine_minit(int module_number) { } /* hook autoload */ - original_zend_autoload = zend_autoload; + swoole_hook_zend_autoload = zend_autoload; zend_autoload = swoole_coroutine_autoload; SWOOLE_G(in_autoload) = nullptr; } From 929efd4dc7e64fcc8f08f0325a39d554a37613fc Mon Sep 17 00:00:00 2001 From: Jurijs Cerepanovs Date: Fri, 20 Mar 2026 13:47:40 +0200 Subject: [PATCH 2/2] Add php_swoole_api.h header to installed extension headers --- config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.m4 b/config.m4 index d123062d3b5..65feaa6f185 100644 --- a/config.m4 +++ b/config.m4 @@ -1549,7 +1549,7 @@ EOF AC_MSG_RESULT([disabled]) fi - PHP_INSTALL_HEADERS([ext/swoole], [ext-src/*.h config.h php_swoole.h \ + PHP_INSTALL_HEADERS([ext/swoole], [ext-src/*.h config.h php_swoole.h php_swoole_api.h \ include/*.h \ stubs/*.h \ thirdparty/*.h \