Skip to content

Commit

Permalink
[test] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 16, 2024
1 parent 1594cf5 commit 20eec88
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
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 @@ -16,7 +16,7 @@ function swoole_async_dns_lookup_coro(string $domain_name, float $timeout = 60,
{
}

function swoole_async_set(array $settings): void
function swoole_async_set(array $settings): bool
{
}

Expand Down
4 changes: 2 additions & 2 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: 20f9cbe81acd5771dbf8e18dd8af8952540ead91 */
* Stub hash: 1ab45a47bad71a13ad16c3d92dcb8612920ae84c */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_version, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
Expand All @@ -15,7 +15,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_async_dns_lookup_coro, 0,
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "AF_INET")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_async_set, 0, 1, IS_VOID, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_async_set, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, settings, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

Expand Down
1 change: 1 addition & 0 deletions ext-src/swoole_async_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ PHP_FUNCTION(swoole_async_set) {
if (php_swoole_array_get_value(vht, "enable_coroutine", ztmp)) {
SwooleG.enable_coroutine = zval_is_true(ztmp);
}
RETURN_TRUE;
}

PHP_FUNCTION(swoole_async_dns_lookup_coro) {
Expand Down
38 changes: 25 additions & 13 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ struct NetStream {
bool blocking;
};

static bool runtime_hook_init = false;
static int runtime_hook_flags = 0;

static struct {
php_stream_transport_factory tcp;
php_stream_transport_factory udp;
Expand Down Expand Up @@ -172,9 +169,15 @@ static zend_internal_arg_info *get_arginfo(const char *name, size_t l_name) {
#define SW_HOOK_LIBRARY_FE(name, arg_info) \
ZEND_RAW_FENTRY("swoole_hook_" #name, PHP_FN(swoole_user_func_handler), arg_info, 0)

static SW_THREAD_LOCAL bool runtime_hook_init = false;
static SW_THREAD_LOCAL int runtime_hook_flags = 0;
static SW_THREAD_LOCAL zend_array *tmp_function_table = nullptr;
static SW_THREAD_LOCAL std::unordered_map<std::string, zend_class_entry *> child_class_entries;

#ifdef SW_THREAD
static std::unordered_map<std::string, zif_handler> ori_func_handlers;
#endif

SW_EXTERN_C_BEGIN
#include "ext/standard/file.h"
#include "thirdparty/php/streams/plain_wrapper.c"
Expand Down Expand Up @@ -1956,6 +1959,10 @@ static void hook_func(const char *name, size_t l_name, zif_handler handler, zend
zf->internal_function.arg_info = arg_info;
}

#ifdef SW_THREAD
ori_func_handlers[std::string(zf->common.function_name->val, zf->common.function_name->len)] = rf->ori_handler;
#endif

if (use_php_func) {
char func[128];
memcpy(func, ZEND_STRL("swoole_"));
Expand Down Expand Up @@ -2051,17 +2058,22 @@ static PHP_FUNCTION(swoole_stream_socket_pair) {
}

static PHP_FUNCTION(swoole_user_func_handler) {
zend_fcall_info fci;
fci.size = sizeof(fci);
fci.object = nullptr;
ZVAL_UNDEF(&fci.function_name);
fci.retval = return_value;
fci.param_count = ZEND_NUM_ARGS();
fci.params = ZEND_CALL_ARG(execute_data, 1);
fci.named_params = NULL;

real_func *rf = (real_func *) zend_hash_find_ptr(tmp_function_table, execute_data->func->common.function_name);
zend_call_function(&fci, rf->fci_cache);
if (rf) {
zend_fcall_info fci;
fci.size = sizeof(fci);
fci.object = nullptr;
fci.retval = return_value;
fci.param_count = ZEND_NUM_ARGS();
fci.params = ZEND_CALL_ARG(execute_data, 1);
fci.named_params = NULL;
ZVAL_UNDEF(&fci.function_name);
zend_call_function(&fci, rf->fci_cache);
} else {
zend_string *fn_str = execute_data->func->common.function_name;
auto ori_handler = ori_func_handlers[std::string(fn_str->val, fn_str->len)];
ori_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}
}

zend_class_entry *find_class_entry(const char *name, size_t length) {
Expand Down

0 comments on commit 20eec88

Please sign in to comment.