Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Fix some functions that have been replaced #5480

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,18 @@ SW_API bool php_swoole_is_enable_coroutine() {

SW_API zend_long php_swoole_parse_to_size(zval *zv) {
if (ZVAL_IS_STRING(zv)) {
#if PHP_VERSION_ID >= 80200
zend_string *errstr;
auto size = zend_ini_parse_quantity(Z_STR_P(zv), &errstr);
if (errstr) {
php_swoole_fatal_error(
E_ERROR, "failed to parse '%s' to size, Error: %s", Z_STRVAL_P(zv), ZSTR_VAL(errstr));
zend_string_release(errstr);
}
return size;
#else
return zend_atol(Z_STRVAL_P(zv), Z_STRLEN_P(zv));
#endif
} else {
return zval_get_long(zv);
}
Expand Down
2 changes: 2 additions & 0 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ static int coro_exit_handler(zend_execute_data *execute_data) {
return ZEND_USER_OPCODE_DISPATCH;
}
#else
SW_EXTERN_C_BEGIN
extern ZEND_FUNCTION(exit);
PHP_FUNCTION(swoole_exit) {
zend_string *message = NULL;
Expand Down Expand Up @@ -259,6 +260,7 @@ PHP_FUNCTION(swoole_exit) {
ZEND_FN(exit)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}
SW_EXTERN_C_END
#endif

static int coro_begin_silence_handler(zend_execute_data *execute_data) {
Expand Down
12 changes: 12 additions & 0 deletions ext-src/swoole_redis_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ int php_swoole_redis_server_onReceive(Server *serv, RecvData *req) {

char _command[SW_REDIS_MAX_COMMAND_SIZE];
size_t _command_len = sw_snprintf(_command, sizeof(_command), "_handler_%.*s", command_len, command);
#if PHP_VERSION_ID >= 80400
zend_str_tolower(_command, _command_len);
#else
php_strtolower(_command, _command_len);
#endif

auto i = redis_handlers.find(std::string(_command, _command_len));
if (i == redis_handlers.end()) {
Expand Down Expand Up @@ -214,7 +218,11 @@ static PHP_METHOD(swoole_redis_server, setHandler) {

char _command[SW_REDIS_MAX_COMMAND_SIZE];
size_t _command_len = sw_snprintf(_command, sizeof(_command), "_handler_%s", command);
#if PHP_VERSION_ID >= 80400
zend_str_tolower(_command, _command_len);
#else
php_strtolower(_command, _command_len);
#endif

zend_update_property(swoole_redis_server_ce, SW_Z8_OBJ_P(ZEND_THIS), _command, _command_len, zcallback);

Expand All @@ -240,7 +248,11 @@ static PHP_METHOD(swoole_redis_server, getHandler) {

char _command[SW_REDIS_MAX_COMMAND_SIZE];
size_t _command_len = sw_snprintf(_command, sizeof(_command), "_handler_%s", command);
#if PHP_VERSION_ID >= 80400
zend_str_tolower(_command, _command_len);
#else
php_strtolower(_command, _command_len);
#endif

zval rv;
zval *handler = zend_read_property(swoole_redis_server_ce, SW_Z8_OBJ_P(ZEND_THIS), _command, _command_len, 1, &rv);
Expand Down
23 changes: 23 additions & 0 deletions tests/swoole_server/parse_option_to_size.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
swoole_server: parse option value to size
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要排除8.2以下版本

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

use Swoole\Server;

$server = new Server('127.0.0.1', SWOOLE_BASE);
$server->set([
'buffer_output_size' => '2M',
]);
$server->set([
'buffer_output_size' => 2 * 1024 * 1024,
]);
$server->set([
'buffer_output_size' => 'xxx--2M',
]);
?>
--EXPECTF--
Fatal error: Swoole\Server::set(): failed to parse 'xxx--2M' to size, Error: Invalid quantity "xxx--2M": no valid leading digits, interpreting as "0" for backwards compatibility in %s on line %d
Loading