Skip to content

Commit

Permalink
Fix compatibility with PHP 8.1 (#4474)
Browse files Browse the repository at this point in the history
* Fix Swoole\WebSocket\Frame implements Stringable

* Fix Swoole\Connection\Iterator

* Fix Swoole\Table

* Fix
  • Loading branch information
Yurunsoft authored Nov 9, 2021
1 parent daa96ef commit 3d44328
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
4 changes: 4 additions & 0 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ static sw_inline zend_bool ZVAL_IS_OBJECT(zval *v) {
}
#endif

#ifndef IS_MIXED
#define IS_MIXED 0
#endif

static sw_inline zval *sw_malloc_zval() {
return (zval *) emalloc(sizeof(zval));
}
Expand Down
38 changes: 28 additions & 10 deletions ext-src/swoole_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,37 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_server_getClientList, 0, 0, 1)
ZEND_END_ARG_INFO()

//arginfo connection_iterator
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_iterator_offsetExists, 0, 0, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_offsetExists, 0, 1, _IS_BOOL, 0)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_iterator_offsetGet, 0, 0, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_offsetGet, 0, 1, IS_MIXED, 0)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_iterator_offsetUnset, 0, 0, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_offsetUnset, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, fd)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_connection_iterator_offsetSet, 0, 0, 2)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_connection_iterator_offsetSet, 0, 2, IS_VOID, 0)
ZEND_ARG_INFO(0, fd)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -619,12 +637,12 @@ static const zend_function_entry swoole_connection_iterator_methods[] =
{
PHP_ME(swoole_connection_iterator, __construct, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, __destruct, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, rewind, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, next, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, current, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, key, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, valid, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, count, arginfo_swoole_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, rewind, arginfo_swoole_connection_iterator_rewind, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, next, arginfo_swoole_connection_iterator_next, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, current, arginfo_swoole_connection_iterator_current, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, key, arginfo_swoole_connection_iterator_key, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, valid, arginfo_swoole_connection_iterator_valid, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, count, arginfo_swoole_connection_iterator_count, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, offsetExists, arginfo_swoole_connection_iterator_offsetExists, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, offsetGet, arginfo_swoole_connection_iterator_offsetGet, ZEND_ACC_PUBLIC)
PHP_ME(swoole_connection_iterator, offsetSet, arginfo_swoole_connection_iterator_offsetSet, ZEND_ACC_PUBLIC)
Expand Down
32 changes: 26 additions & 6 deletions ext-src/swoole_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_table_decr, 0, 0, 2)
ZEND_ARG_INFO(0, column)
ZEND_ARG_INFO(0, decrby)
ZEND_END_ARG_INFO()

//arginfo connection_iterator
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_rewind, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_key, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_table_iterator_count, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

// clang-format on

SW_EXTERN_C_BEGIN
Expand Down Expand Up @@ -200,7 +220,7 @@ static const zend_function_entry swoole_table_methods[] =
PHP_ME(swoole_table, destroy, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, set, arginfo_swoole_table_set, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, get, arginfo_swoole_table_get, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, count, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, count, arginfo_swoole_table_iterator_count, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, del, arginfo_swoole_table_del, ZEND_ACC_PUBLIC)
PHP_MALIAS(swoole_table, delete, del, arginfo_swoole_table_del, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, exists, arginfo_swoole_table_exists, ZEND_ACC_PUBLIC)
Expand All @@ -211,11 +231,11 @@ static const zend_function_entry swoole_table_methods[] =
PHP_ME(swoole_table, getMemorySize, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, stats, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
// implement Iterator
PHP_ME(swoole_table, rewind, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, valid, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, next, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, current, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, key, arginfo_swoole_table_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, rewind, arginfo_swoole_table_iterator_rewind, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, valid, arginfo_swoole_table_iterator_valid, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, next, arginfo_swoole_table_iterator_next, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, current, arginfo_swoole_table_iterator_current, ZEND_ACC_PUBLIC)
PHP_ME(swoole_table, key, arginfo_swoole_table_iterator_key, ZEND_ACC_PUBLIC)
PHP_FE_END
};
// clang-format on
Expand Down
8 changes: 7 additions & 1 deletion ext-src/swoole_websocket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_websocket_frame_void, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_websocket_frame___toString, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

const zend_function_entry swoole_websocket_server_methods[] =
{
PHP_ME(swoole_websocket_server, push, arginfo_swoole_websocket_server_push, ZEND_ACC_PUBLIC)
Expand All @@ -97,7 +100,7 @@ const zend_function_entry swoole_websocket_server_methods[] =

const zend_function_entry swoole_websocket_frame_methods[] =
{
PHP_ME(swoole_websocket_frame, __toString, arginfo_swoole_websocket_frame_void, ZEND_ACC_PUBLIC)
PHP_ME(swoole_websocket_frame, __toString, arginfo_swoole_websocket_frame___toString, ZEND_ACC_PUBLIC)
PHP_ME(swoole_websocket_server, pack, arginfo_swoole_websocket_server_pack, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(swoole_websocket_server, unpack, arginfo_swoole_websocket_server_unpack, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END
Expand Down Expand Up @@ -635,6 +638,9 @@ void php_swoole_websocket_server_minit(int module_number) {
"swoole_websocket_frame",
nullptr,
swoole_websocket_frame_methods);
#if PHP_VERSION_ID >= 80000
zend_class_implements(swoole_websocket_frame_ce, 1, zend_ce_stringable);
#endif
zend_declare_property_long(swoole_websocket_frame_ce, ZEND_STRL("fd"), 0, ZEND_ACC_PUBLIC);
zend_declare_property_string(swoole_websocket_frame_ce, ZEND_STRL("data"), "", ZEND_ACC_PUBLIC);
zend_declare_property_long(swoole_websocket_frame_ce, ZEND_STRL("opcode"), WebSocket::OPCODE_TEXT, ZEND_ACC_PUBLIC);
Expand Down

0 comments on commit 3d44328

Please sign in to comment.