Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 23, 2024
1 parent 0168ebe commit f6fcafb
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 75 deletions.
2 changes: 1 addition & 1 deletion ext-src/swoole_admin_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static json get_socket_info(int fd) {
{"rcv_space", info.tcpi_rcv_space},
{"total_retrans", info.tcpi_total_retrans},
};
#endif // defined(__FreeBSD__) || defined(__NetBSD__)
#endif // defined(__FreeBSD__) || defined(__NetBSD__)
return jinfo;
}
#endif
Expand Down
42 changes: 21 additions & 21 deletions ext-src/swoole_async_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ void php_swoole_async_coro_rshutdown() {
void php_swoole_set_aio_option(HashTable *vht) {
zval *ztmp;
/* AIO */
if (php_swoole_array_get_value(vht, "aio_core_worker_num", ztmp)) {
zend_long v = zval_get_long(ztmp);
v = SW_MAX(1, SW_MIN(v, UINT32_MAX));
SwooleG.aio_core_worker_num = v;
}
if (php_swoole_array_get_value(vht, "aio_worker_num", ztmp)) {
zend_long v = zval_get_long(ztmp);
v = SW_MAX(1, SW_MIN(v, UINT32_MAX));
SwooleG.aio_worker_num = v;
}
if (php_swoole_array_get_value(vht, "aio_max_wait_time", ztmp)) {
SwooleG.aio_max_wait_time = zval_get_double(ztmp);
}
if (php_swoole_array_get_value(vht, "aio_max_idle_time", ztmp)) {
SwooleG.aio_max_idle_time = zval_get_double(ztmp);
}
if (php_swoole_array_get_value(vht, "aio_core_worker_num", ztmp)) {
zend_long v = zval_get_long(ztmp);
v = SW_MAX(1, SW_MIN(v, UINT32_MAX));
SwooleG.aio_core_worker_num = v;
}
if (php_swoole_array_get_value(vht, "aio_worker_num", ztmp)) {
zend_long v = zval_get_long(ztmp);
v = SW_MAX(1, SW_MIN(v, UINT32_MAX));
SwooleG.aio_worker_num = v;
}
if (php_swoole_array_get_value(vht, "aio_max_wait_time", ztmp)) {
SwooleG.aio_max_wait_time = zval_get_double(ztmp);
}
if (php_swoole_array_get_value(vht, "aio_max_idle_time", ztmp)) {
SwooleG.aio_max_idle_time = zval_get_double(ztmp);
}
#if defined(__linux__) && defined(SW_USE_IOURING)
if (php_swoole_array_get_value(vht, "iouring_entries", ztmp)) {
zend_long v = zval_get_long(ztmp);
SwooleG.iouring_entries = SW_MAX(0, SW_MIN(v, UINT32_MAX));
}
if (php_swoole_array_get_value(vht, "iouring_entries", ztmp)) {
zend_long v = zval_get_long(ztmp);
SwooleG.iouring_entries = SW_MAX(0, SW_MIN(v, UINT32_MAX));
}
#endif
}

Expand Down Expand Up @@ -183,5 +183,5 @@ PHP_FUNCTION(swoole_async_dns_lookup_coro) {
}
memcpy(cache->address, Z_STRVAL_P(return_value), Z_STRLEN_P(return_value));
cache->address[Z_STRLEN_P(return_value)] = '\0';
cache->update_time = Timer::get_absolute_msec() + (int64_t)(SwooleG.dns_cache_refresh_time * 1000);
cache->update_time = Timer::get_absolute_msec() + (int64_t) (SwooleG.dns_cache_refresh_time * 1000);
}
2 changes: 1 addition & 1 deletion ext-src/swoole_client_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void client_coro_free_object(zend_object *object) {
}

#define CLIENT_CORO_GET_SOCKET_SAFE(__sock) \
SW_CLIENT_GET_SOCKET_SAFE(__sock, &client_coro_get_client(ZEND_THIS)->zsocket); \
SW_CLIENT_GET_SOCKET_SAFE(__sock, &client_coro_get_client(ZEND_THIS)->zsocket); \
if (!__sock) { \
php_swoole_socket_set_error_properties( \
ZEND_THIS, SW_ERROR_CLIENT_NO_CONNECTION, swoole_strerror(SW_ERROR_CLIENT_NO_CONNECTION)); \
Expand Down
29 changes: 13 additions & 16 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,40 +859,38 @@ void PHPCoroutine::fiber_context_switch_try_notify(PHPContext *from, PHPContext
#endif /* SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT */

#ifdef ZEND_CHECK_STACK_LIMIT
void* PHPCoroutine::stack_limit(PHPContext *ctx)
{
void *PHPCoroutine::stack_limit(PHPContext *ctx) {
#ifdef SW_USE_THREAD_CONTEXT
return nullptr;
#else
zend_ulong reserve = EG(reserved_stack_size);
zend_ulong reserve = EG(reserved_stack_size);

#ifdef __APPLE__
/* On Apple Clang, the stack probing function ___chkstk_darwin incorrectly
* probes a location that is twice the entered function's stack usage away
* from the stack pointer, when using an alternative stack.
* https://openradar.appspot.com/radar?id=5497722702397440
*/
reserve = reserve * 2;
/* On Apple Clang, the stack probing function ___chkstk_darwin incorrectly
* probes a location that is twice the entered function's stack usage away
* from the stack pointer, when using an alternative stack.
* https://openradar.appspot.com/radar?id=5497722702397440
*/
reserve = reserve * 2;
#endif

if (!ctx->co) {
return nullptr;
}

/* stack->pointer is the end of the stack */
return (int8_t*)ctx->co->get_ctx().get_stack() + reserve;
/* stack->pointer is the end of the stack */
return (int8_t *) ctx->co->get_ctx().get_stack() + reserve;
#endif
}
void* PHPCoroutine::stack_base(PHPContext *ctx)
{
void *PHPCoroutine::stack_base(PHPContext *ctx) {
#ifdef SW_USE_THREAD_CONTEXT
return nullptr;
#else
if (!ctx->co) {
return nullptr;
}

return (void*)((uintptr_t)ctx->co->get_ctx().get_stack() + ctx->co->get_ctx().get_stack_size());
return (void *) ((uintptr_t) ctx->co->get_ctx().get_stack() + ctx->co->get_ctx().get_stack_size());
#endif
}
#endif /* ZEND_CHECK_STACK_LIMIT */
Expand All @@ -911,8 +909,7 @@ struct AutoloadQueue {
std::queue<AutoloadContext *> *queue;
};

static zend_class_entry *swoole_coroutine_autoload(zend_string *name, zend_string *lc_name)
{
static zend_class_entry *swoole_coroutine_autoload(zend_string *name, zend_string *lc_name) {
auto current = Coroutine::get_current();
if (!current) {
return original_zend_autoload(name, lc_name);
Expand Down
9 changes: 2 additions & 7 deletions ext-src/swoole_http2_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,8 @@ static bool http2_server_is_static_file(Server *serv, HttpContext *ctx) {
if (1 == tasks.size()) {
if (SW_HTTP_PARTIAL_CONTENT == handler.status_code) {
std::stringstream content_range;
content_range << "bytes "
<< tasks[0].offset
<< "-"
<< (tasks[0].length + tasks[0].offset - 1)
<< "/"
<< handler.get_filesize()
<< "\r\n";
content_range << "bytes " << tasks[0].offset << "-" << (tasks[0].length + tasks[0].offset - 1) << "/"
<< handler.get_filesize() << "\r\n";
auto content_range_str = content_range.str();
ctx->set_header(ZEND_STRL("Content-Range"), content_range_str.c_str(), content_range_str.length(), 0);
} else {
Expand Down
18 changes: 9 additions & 9 deletions ext-src/swoole_http_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -997,33 +997,33 @@ static void php_swoole_http_response_cookie(INTERNAL_FUNCTION_PARAMETERS, const
}

char *cookie = nullptr, *date = nullptr;
size_t cookie_size = name_len + 1; // add 1 for null char
cookie_size += 50; // strlen("; expires=Fri, 31-Dec-9999 23:59:59 GMT; Max-Age=0")
size_t cookie_size = name_len + 1; // add 1 for null char
cookie_size += 50; // strlen("; expires=Fri, 31-Dec-9999 23:59:59 GMT; Max-Age=0")
if (value_len == 0) {
cookie_size += 8; // strlen("=deleted")
cookie_size += 8; // strlen("=deleted")
}
if (expires > 0) {
// Max-Age will be no longer than 12 digits since the
// maximum expires is Fri, 31-Dec-9999 23:59:59 GMT.
cookie_size += 11;
}
if (path_len > 0) {
cookie_size += path_len + 7; // strlen("; path=")
cookie_size += path_len + 7; // strlen("; path=")
}
if (domain_len > 0) {
cookie_size += domain_len + 9; // strlen("; domain=")
cookie_size += domain_len + 9; // strlen("; domain=")
}
if (secure) {
cookie_size += 8; // strlen("; secure")
cookie_size += 8; // strlen("; secure")
}
if (httponly) {
cookie_size += 10; // strlen("; httponly")
cookie_size += 10; // strlen("; httponly")
}
if (samesite_len > 0) {
cookie_size += samesite_len + 11; // strlen("; samesite=")
cookie_size += samesite_len + 11; // strlen("; samesite=")
}
if (priority_len > 0) {
cookie_size += priority_len + 11; // strlen("; priority=")
cookie_size += priority_len + 11; // strlen("; priority=")
}

if (value_len == 0) {
Expand Down
3 changes: 1 addition & 2 deletions ext-src/swoole_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ void swoole_http_server_onAfterResponse(HttpContext *ctx) {
swoole_trace("serv->gs->concurrency=%u, max_concurrency=%u", serv->gs->concurrency, serv->gs->max_concurrency);
if (!queued_http_contexts.empty()) {
HttpContext *ctx = queued_http_contexts.front();
swoole_trace(
"[POP 1] concurrency=%u, ctx=%p, request=%p", sw_worker()->concurrency, ctx, ctx->request.zobject);
swoole_trace("[POP 1] concurrency=%u, ctx=%p, request=%p", sw_worker()->concurrency, ctx, ctx->request.zobject);
queued_http_contexts.pop();
swoole_event_defer(
[](void *private_data) {
Expand Down
3 changes: 1 addition & 2 deletions ext-src/swoole_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ static PHP_METHOD(swoole_lock, __construct) {
lock = new Mutex(Mutex::PROCESS_SHARED);
break;
default:
zend_throw_exception(
swoole_exception_ce, "lock type[%d] is not support", type);
zend_throw_exception(swoole_exception_ce, "lock type[%d] is not support", type);
RETURN_FALSE;
break;
}
Expand Down
9 changes: 6 additions & 3 deletions ext-src/swoole_oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ sword swoole_oci_stmt_prepare(
OCIStmt *stmtp, OCIError *errhp, const OraText *stmt, ub4 stmt_len, ub4 language, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_prepare");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });

return result;
}
Expand All @@ -64,7 +65,8 @@ sword swoole_oci_stmt_execute(OCISvcCtx *svchp,
ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_execute");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });

return result;
}
Expand All @@ -80,7 +82,8 @@ sword swoole_oci_stmt_fetch(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orie
sword swoole_oci_stmt_fetch2(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, sb4 scrollOffset, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_fetch2");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });

return result;
}
Expand Down
3 changes: 2 additions & 1 deletion ext-src/swoole_pgsql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void swoole_pgsql_set_blocking(bool blocking) {
}

void php_swoole_pgsql_minit(int module_id) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("PGSQL_ATTR_DISABLE_PREPARES")) == nullptr) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("PGSQL_ATTR_DISABLE_PREPARES")) ==
nullptr) {
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_ATTR_DISABLE_PREPARES", PDO_PGSQL_ATTR_DISABLE_PREPARES);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_IDLE", (zend_long) PGSQL_TRANSACTION_IDLE);
REGISTER_PDO_CLASS_CONST_LONG("PGSQL_TRANSACTION_ACTIVE", (zend_long) PGSQL_TRANSACTION_ACTIVE);
Expand Down
6 changes: 3 additions & 3 deletions ext-src/swoole_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1927,11 +1927,11 @@ static PHP_METHOD(swoole_server, __construct) {
Z_PARAM_LONG(sock_type)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

if (serv_mode != Server::MODE_BASE && serv_mode != Server::MODE_PROCESS
#ifdef SW_THREAD
if (serv_mode != Server::MODE_BASE && serv_mode != Server::MODE_PROCESS && serv_mode != Server::MODE_THREAD) {
#else
if (serv_mode != Server::MODE_BASE && serv_mode != Server::MODE_PROCESS) {
&& serv_mode != Server::MODE_THREAD
#endif
) {
zend_throw_error(NULL, "invalid $mode parameters %d", (int) serv_mode);
RETURN_FALSE;
}
Expand Down
4 changes: 1 addition & 3 deletions ext-src/swoole_server_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ static ssize_t php_swoole_server_length_func(const Protocol *protocol, network::
ssize_t ret = -1;

ZVAL_STRINGL(&zdata, pl->buf, pl->buf_size);
HOOK_PHP_CALL_STACK(
auto call_result = sw_zend_call_function_ex(nullptr, fci_cache, 1, &zdata, &retval);
);
HOOK_PHP_CALL_STACK(auto call_result = sw_zend_call_function_ex(nullptr, fci_cache, 1, &zdata, &retval););
if (UNEXPECTED(call_result) != SUCCESS) {
php_swoole_fatal_error(E_WARNING, "length function handler error");
} else {
Expand Down
14 changes: 9 additions & 5 deletions ext-src/swoole_thread_atomic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static zend_object_handlers swoole_thread_atomic_handlers;
zend_class_entry *swoole_thread_atomic_long_ce;
static zend_object_handlers swoole_thread_atomic_long_handlers;

struct AtomicResource: public ThreadResource {
struct AtomicResource : public ThreadResource {
sw_atomic_t value;
};

Expand Down Expand Up @@ -70,7 +70,7 @@ static zend_object *php_swoole_thread_atomic_create_object(zend_class_entry *ce)
return &atomic->std;
}

struct AtomicLongResource: public ThreadResource {
struct AtomicLongResource : public ThreadResource {
sw_atomic_long_t value;
};

Expand Down Expand Up @@ -162,10 +162,14 @@ void php_swoole_thread_atomic_minit(int module_number) {
zend_declare_property_long(swoole_thread_atomic_ce, ZEND_STRL("id"), 0, ZEND_ACC_PUBLIC);
SW_SET_CLASS_CLONEABLE(swoole_thread_atomic, sw_zend_class_clone_deny);
SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_thread_atomic, sw_zend_class_unset_property_deny);
SW_SET_CLASS_CUSTOM_OBJECT(
swoole_thread_atomic, php_swoole_thread_atomic_create_object, php_swoole_thread_atomic_free_object, AtomicObject, std);
SW_SET_CLASS_CUSTOM_OBJECT(swoole_thread_atomic,
php_swoole_thread_atomic_create_object,
php_swoole_thread_atomic_free_object,
AtomicObject,
std);

SW_INIT_CLASS_ENTRY(swoole_thread_atomic_long, "Swoole\\Thread\\Atomic\\Long", nullptr, swoole_thread_atomic_long_methods);
SW_INIT_CLASS_ENTRY(
swoole_thread_atomic_long, "Swoole\\Thread\\Atomic\\Long", nullptr, swoole_thread_atomic_long_methods);
zend_declare_property_long(swoole_thread_atomic_long_ce, ZEND_STRL("id"), 0, ZEND_ACC_PUBLIC);
SW_SET_CLASS_CLONEABLE(swoole_thread_atomic_long, sw_zend_class_clone_deny);
SW_SET_CLASS_UNSET_PROPERTY_HANDLER(swoole_thread_atomic_long, sw_zend_class_unset_property_deny);
Expand Down
1 change: 0 additions & 1 deletion ext-src/swoole_thread_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ void php_swoole_thread_map_minit(int module_number) {
zend_declare_property_long(swoole_thread_map_ce, ZEND_STRL("id"), 0, ZEND_ACC_PUBLIC);
}


static PHP_METHOD(swoole_thread_map, __construct) {
auto mo = thread_map_fetch_object(Z_OBJ_P(ZEND_THIS));
mo->map = new ZendArray();
Expand Down

0 comments on commit f6fcafb

Please sign in to comment.