Skip to content

Commit

Permalink
Rename the swoole_test_fn function to swoole_implicit_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Oct 16, 2024
1 parent 6957d64 commit 4fe3e4b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
31 changes: 20 additions & 11 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion ext-src/stubs/php_swoole.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

}
7 changes: 4 additions & 3 deletions ext-src/stubs/php_swoole_arginfo.h
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/swoole_thread/fatal_error_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $pm = ProcessManager::exec(function () {
} else {
Co\run(function () {
(function () {
swoole_test_fn('fatal_error');
swoole_implicit_fn('fatal_error');
})();
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_thread/fatal_error_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions tests/swoole_thread/server/exit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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__);

Expand Down Expand Up @@ -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 () {
Expand Down
4 changes: 2 additions & 2 deletions tests/swoole_thread/server/reset_concurrency.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 4fe3e4b

Please sign in to comment.