diff --git a/ext-src/php_swoole.cc b/ext-src/php_swoole.cc index 3d8d6e4c0e..c9329bc3ca 100644 --- a/ext-src/php_swoole.cc +++ b/ext-src/php_swoole.cc @@ -91,7 +91,7 @@ static PHP_FUNCTION(swoole_mime_type_list); static PHP_FUNCTION(swoole_substr_unserialize); static PHP_FUNCTION(swoole_substr_json_decode); static PHP_FUNCTION(swoole_internal_call_user_shutdown_begin); -static PHP_FUNCTION(swoole_test_fn); // only for unit tests +static PHP_FUNCTION(swoole_implicit_fn); SW_EXTERN_C_END // clang-format off @@ -130,8 +130,9 @@ const zend_function_entry swoole_functions[] = { PHP_FE(swoole_clear_dns_cache, arginfo_swoole_clear_dns_cache) PHP_FE(swoole_substr_unserialize, arginfo_swoole_substr_unserialize) PHP_FE(swoole_substr_json_decode, arginfo_swoole_substr_json_decode) - PHP_FE(swoole_test_fn, arginfo_swoole_test_fn) PHP_FE(swoole_internal_call_user_shutdown_begin, arginfo_swoole_internal_call_user_shutdown_begin) + // for test + PHP_FE(swoole_implicit_fn, arginfo_swoole_implicit_fn) // for admin server ZEND_FE(swoole_get_objects, arginfo_swoole_get_objects) ZEND_FE(swoole_get_vm_status, arginfo_swoole_get_vm_status) @@ -1497,24 +1498,32 @@ static PHP_FUNCTION(swoole_substr_json_decode) { zend::json_decode(return_value, str + offset, length, options, depth); } -static PHP_FUNCTION(swoole_test_fn) { - char *test_case; - size_t test_case_len; - ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(test_case, test_case_len) +/** + * The implicit functions are intended solely for internal testing and will not be documented. + * These functions are unsafe, do not use if you are not an internal developer. + */ +static PHP_FUNCTION(swoole_implicit_fn) { + char *fn; + size_t l_fn; + zval *zargs = nullptr; + + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(fn, l_fn) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL(zargs) ZEND_PARSE_PARAMETERS_END(); - if (SW_STRCASEEQ(test_case, test_case_len, "fatal_error")) { + if (SW_STRCASEEQ(fn, l_fn, "fatal_error")) { swoole_fatal_error(SW_ERROR_FOR_TEST, "test"); php_printf("never be executed here\n"); - } else if (SW_STRCASEEQ(test_case, test_case_len, "bailout")) { - EG(exit_status) = 95; + } else if (SW_STRCASEEQ(fn, l_fn, "bailout")) { + EG(exit_status) = zargs ? zval_get_long(zargs) : 95; #ifdef SW_THREAD php_swoole_thread_bailout(); #else zend_bailout(); #endif - } else if (SW_STRCASEEQ(test_case, test_case_len, "abort")) { + } else if (SW_STRCASEEQ(fn, l_fn, "abort")) { abort(); } } diff --git a/ext-src/stubs/php_swoole.stub.php b/ext-src/stubs/php_swoole.stub.php index 4310b78d4c..b29dd75dfd 100644 --- a/ext-src/stubs/php_swoole.stub.php +++ b/ext-src/stubs/php_swoole.stub.php @@ -121,7 +121,7 @@ function swoole_internal_call_user_shutdown_begin(): bool } -function swoole_test_fn(string $case): void +function swoole_implicit_fn(string $fn, mixed $args = null): void { } diff --git a/ext-src/stubs/php_swoole_arginfo.h b/ext-src/stubs/php_swoole_arginfo.h index 865a16a353..5872be8359 100644 --- a/ext-src/stubs/php_swoole_arginfo.h +++ b/ext-src/stubs/php_swoole_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ac43701147665b52de0dce97b7581d37183158a1 */ + * Stub hash: f3b5724446b5118d9223c66a1045729c7c3ceff7 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_version, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -130,6 +130,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_internal_call_user_shutdown_begin, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_test_fn, 0, 1, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(0, case, IS_STRING, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_implicit_fn, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, fn, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, args, IS_MIXED, 0, "null") ZEND_END_ARG_INFO() diff --git a/tests/swoole_thread/fatal_error_1.phpt b/tests/swoole_thread/fatal_error_1.phpt index e15eaf1c81..d4d02eb611 100644 --- a/tests/swoole_thread/fatal_error_1.phpt +++ b/tests/swoole_thread/fatal_error_1.phpt @@ -21,7 +21,7 @@ $pm = ProcessManager::exec(function () { } else { Co\run(function () { (function () { - swoole_test_fn('fatal_error'); + swoole_implicit_fn('fatal_error'); })(); }); } diff --git a/tests/swoole_thread/fatal_error_2.phpt b/tests/swoole_thread/fatal_error_2.phpt index c9833c61df..234a317528 100644 --- a/tests/swoole_thread/fatal_error_2.phpt +++ b/tests/swoole_thread/fatal_error_2.phpt @@ -19,7 +19,7 @@ $pm = ProcessManager::exec(function () { echo "stop thread exited\n"; } else { (function () { - swoole_test_fn('fatal_error'); + swoole_implicit_fn('fatal_error'); })(); } echo "DONE\n"; diff --git a/tests/swoole_thread/server/exit.phpt b/tests/swoole_thread/server/exit.phpt index 2ac7769673..4187c037d9 100644 --- a/tests/swoole_thread/server/exit.phpt +++ b/tests/swoole_thread/server/exit.phpt @@ -12,7 +12,7 @@ require __DIR__ . '/../../include/bootstrap.php'; use Swoole\Thread; use Swoole\Http\Server; -const CODE = 95; +const CODE = 235; const SIZE = 2 * 1024 * 1024; $port = get_constant_port(__FILE__); @@ -46,7 +46,7 @@ $serv->on('WorkerStop', function (Server $serv, $workerId) { }); $serv->on('Request', function ($req, $resp) use ($serv) { if ($req->server['request_uri'] == '/exit') { - swoole_test_fn('bailout'); + swoole_implicit_fn('exit', CODE); } }); $serv->on('shutdown', function () { diff --git a/tests/swoole_thread/server/reset_concurrency.phpt b/tests/swoole_thread/server/reset_concurrency.phpt index 92f997c4fb..e7e33434df 100644 --- a/tests/swoole_thread/server/reset_concurrency.phpt +++ b/tests/swoole_thread/server/reset_concurrency.phpt @@ -45,7 +45,7 @@ $serv->on('WorkerStop', function (Server $serv, $workerId) { echo 'WORKER STOP', PHP_EOL; }); $serv->on('pipeMessage', function (Server $serv, $wid, $msg) { - swoole_test_fn('bailout'); + swoole_implicit_fn('bailout'); }); $serv->on('Request', function (Request $req, Response $resp) use ($serv) { [$queue, $atomic1, $atomic2] = Thread::getArguments(); @@ -61,7 +61,7 @@ $serv->on('Request', function (Request $req, Response $resp) use ($serv) { $serv->sendMessage('error', $i); } } - swoole_test_fn('bailout'); + swoole_implicit_fn('bailout'); } else { $stats = $serv->stats(); Assert::eq($stats['concurrency'], 1);