Skip to content

Commit

Permalink
Fix warnings and PHP8 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Apr 15, 2019
1 parent 48381ae commit 2634da4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
10 changes: 7 additions & 3 deletions php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ int php_coroutine_reactor_can_exit(swReactor *reactor);
void php_swoole_client_check_ssl_setting(swClient *cli, zval *zset);
#endif

void php_swoole_class_unset_property_deny(zval *zobject, zval *member, void **cache_slot);
#if PHP_VERSION_ID < 80000
void php_swoole_class_unset_property_deny(zval *zobject, zval *zmember, void **cache_slot);
#else
void php_swoole_class_unset_property_deny(zend_object *object, zend_string *member, void **cache_slot);
#endif

ZEND_BEGIN_MODULE_GLOBALS(swoole)
zend_bool display_errors;
Expand Down Expand Up @@ -674,8 +678,8 @@ static sw_inline void sw_zval_free(zval *val)
#define SW_REGISTER_BOOL_CONSTANT(name, value) REGISTER_BOOL_CONSTANT(name, value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_LONG_CONSTANT(name, value) REGISTER_LONG_CONSTANT(name, value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_DOUBLE_CONSTANT(name, value) REGISTER_DOUBLE_CONSTANT(name, value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_STRING_CONSTANT(name, value) REGISTER_STRING_CONSTANT(name, value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_STRINGL_CONSTANT(name, value) REGISTER_STRINGL_CONSTANT(name, value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_STRING_CONSTANT(name, value) REGISTER_STRING_CONSTANT(name, (char *) value, CONST_CS | CONST_PERSISTENT)
#define SW_REGISTER_STRINGL_CONSTANT(name, value) REGISTER_STRINGL_CONSTANT(name, (char *) value, CONST_CS | CONST_PERSISTENT)

//----------------------------------String API-----------------------------------

Expand Down
12 changes: 12 additions & 0 deletions swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ static void php_swoole_init_globals(zend_swoole_globals *swoole_globals)
swoole_globals->rshutdown_functions = NULL;
}

#if PHP_VERSION_ID < 80000
void php_swoole_class_unset_property_deny(zval *zobject, zval *zmember, void **cache_slot)
{
if (EXPECTED(zend_hash_find(&(Z_OBJCE_P(zobject)->properties_info), Z_STR_P(zmember))))
Expand All @@ -293,6 +294,17 @@ void php_swoole_class_unset_property_deny(zval *zobject, zval *zmember, void **c
}
std_object_handlers.unset_property(zobject, zmember, cache_slot);
}
#else
void php_swoole_class_unset_property_deny(zend_object *object, zend_string *member, void **cache_slot)
{
if (EXPECTED(zend_hash_find(object->properties, member)))
{
zend_throw_error(NULL, "Property %s of class %s cannot be unset", ZSTR_VAL(member), ZSTR_VAL(object->ce->name));
return;
}
std_object_handlers.unset_property(object, member, cache_slot);
}
#endif

ssize_t php_swoole_length_func(swProtocol *protocol, swConnection *conn, char *data, uint32_t length)
{
Expand Down
17 changes: 17 additions & 0 deletions swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,27 @@ void PHPCoroutine::create_func(void *arg)
call = (zend_execute_data *) (EG(vm_stack_top));
task = (php_coro_task *) EG(vm_stack_top);
EG(vm_stack_top) = (zval *) ((char *) call + PHP_CORO_TASK_SLOT * sizeof(zval));


#if PHP_VERSION_ID < 80000
call = zend_vm_stack_push_call_frame(
ZEND_CALL_TOP_FUNCTION | ZEND_CALL_ALLOCATED,
func, argc, fci_cache.called_scope, fci_cache.object
);
#else
do {
uint32_t call_info;
void *object_or_called_scope;
if ((func->common.fn_flags & ZEND_ACC_STATIC) || !fci_cache.object) {
object_or_called_scope = fci_cache.called_scope;
call_info = ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC;
} else {
object_or_called_scope = fci_cache.object;
call_info = ZEND_CALL_TOP_FUNCTION | ZEND_CALL_DYNAMIC | ZEND_CALL_HAS_THIS;
}
call = zend_vm_stack_push_call_frame(call_info, func, argc, object_or_called_scope);
} while (0);
#endif

SW_SET_EG_SCOPE(func->common.scope);

Expand Down
2 changes: 1 addition & 1 deletion swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ static inline int socket_xport_api(php_stream *stream, Socket *sock, php_stream_
break;
default:
#ifdef SW_DEBUG
swoole_php_fatal_error(E_WARNING, "socket_xport_api: unsupported option", xparam->op);
swoole_php_fatal_error(E_WARNING, "socket_xport_api: unsupported option %d", xparam->op);
#endif
break;
}
Expand Down
8 changes: 4 additions & 4 deletions swoole_socket_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ static PHP_METHOD(swoole_socket_coro, getOption)
optlen = sizeof(if_addr);
if (getsockopt(sock->socket->get_fd(), level, optname, (char*) &if_addr, &optlen) != 0)
{
swoole_php_sys_error(E_WARNING, "getsockopt(%d, %ld, %ld)", sock->socket->get_fd(), level, optname);
swoole_php_sys_error(E_WARNING, "getsockopt(%d, " ZEND_LONG_FMT ", " ZEND_LONG_FMT ")", sock->socket->get_fd(), level, optname);
RETURN_FALSE;
}
if (php_add4_to_if_index(&if_addr, sock->socket, &if_index) == SUCCESS)
Expand Down Expand Up @@ -1352,7 +1352,7 @@ static PHP_METHOD(swoole_socket_coro, getOption)

if (getsockopt(sock->socket->get_fd(), level, optname, (char*) &linger_val, &optlen) != 0)
{
swoole_php_sys_error(E_WARNING, "getsockopt(%d, %ld, %ld)", sock->socket->get_fd(), level, optname);
swoole_php_sys_error(E_WARNING, "getsockopt(%d, " ZEND_LONG_FMT ", " ZEND_LONG_FMT ")", sock->socket->get_fd(), level, optname);
RETURN_FALSE;
}

Expand All @@ -1367,7 +1367,7 @@ static PHP_METHOD(swoole_socket_coro, getOption)

if (getsockopt(sock->socket->get_fd(), level, optname, (char*) &tv, &optlen) != 0)
{
swoole_php_sys_error(E_WARNING, "getsockopt(%d, %ld, %ld)", sock->socket->get_fd(), level, optname);
swoole_php_sys_error(E_WARNING, "getsockopt(%d, " ZEND_LONG_FMT ", " ZEND_LONG_FMT ")", sock->socket->get_fd(), level, optname);
RETURN_FALSE;
}

Expand All @@ -1382,7 +1382,7 @@ static PHP_METHOD(swoole_socket_coro, getOption)

if (getsockopt(sock->socket->get_fd(), level, optname, (char*) &other_val, &optlen) != 0)
{
swoole_php_sys_error(E_WARNING, "getsockopt(%d, %ld, %ld)", sock->socket->get_fd(), level, optname);
swoole_php_sys_error(E_WARNING, "getsockopt(%d, " ZEND_LONG_FMT ", " ZEND_LONG_FMT ")", sock->socket->get_fd(), level, optname);
RETURN_FALSE;
}
if (optlen == 1)
Expand Down
8 changes: 8 additions & 0 deletions swoole_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,19 @@ static int trace_dump(swWorker *worker, FILE *slowlog)
return -__LINE__;
}

#if PHP_VERSION_ID < 80000
if (ZEND_CALL_KIND_EX((*call_info) >> ZEND_CALL_INFO_SHIFT) == ZEND_CALL_TOP_CODE)
#else
if (ZEND_CALL_KIND_EX(*call_info) == ZEND_CALL_TOP_CODE)
#endif
{
return 0;
}
#if PHP_VERSION_ID < 80000
else if (ZEND_CALL_KIND_EX(*(call_info) >> ZEND_CALL_INFO_SHIFT) == ZEND_CALL_NESTED_CODE)
#else
else if (ZEND_CALL_KIND_EX(*call_info) == ZEND_CALL_NESTED_CODE)
#endif
{
memcpy(buf, "[INCLUDE_OR_EVAL]", sizeof("[INCLUDE_OR_EVAL]"));
}
Expand Down
2 changes: 0 additions & 2 deletions tests/include/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
// PHP settings
error_reporting(E_ALL ^ E_DEPRECATED);
ini_set('memory_limit', '1024M');
ini_set('assert.active', 1);
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
assert_options(ASSERT_BAIL, 0);
assert_options(ASSERT_QUIET_EVAL, 0);

// Swoole settings
swoole_async_set([
Expand Down

0 comments on commit 2634da4

Please sign in to comment.