Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Sadokhov committed Nov 6, 2024
1 parent 112af4a commit d4ac1c9
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
8 changes: 4 additions & 4 deletions builtin-functions/kphp-light/rpc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ final class KphpRpcRequestsExtraInfo {
}

/** @kphp-extern-func-info interruptible */
function rpc_send_request($actor ::: string, $arr ::: array, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];
function rpc_send_requests($actor ::: string, $arr ::: array, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_send_typed_query_request($actor ::: string, @tl\RpcFunction[] $query_functions, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];
function rpc_send_typed_query_requests($actor ::: string, @tl\RpcFunction[] $query_functions, $timeout ::: float, $ignore_answer ::: bool, \KphpRpcRequestsExtraInfo $requests_extra_info, $need_responses_extra_info ::: bool) ::: int[];

/** @kphp-extern-func-info interruptible */
function rpc_fetch_response($query_ids ::: array) ::: mixed[][];
function rpc_fetch_responses($query_ids ::: array) ::: mixed[][];

/** @kphp-extern-func-info interruptible */
function rpc_fetch_typed_response(int[] $query_ids) ::: @tl\RpcResponse[];
function rpc_fetch_typed_responses(int[] $query_ids) ::: @tl\RpcResponse[];

/** @kphp-extern-func-info can_throw */
function fetch_int () ::: int;
Expand Down
12 changes: 6 additions & 6 deletions runtime-common/stdlib/math/math-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@

#include <cstdlib>

mixed f$abs(const mixed &v) {
mixed f$abs(const mixed &v) noexcept {
mixed num = v.to_numeric();
if (num.is_int()) {
return std::abs(num.to_int());
}
return fabs(num.to_float());
}

int64_t f$abs(int64_t v) {
int64_t f$abs(int64_t v) noexcept {
return std::abs(v);
}

double f$abs(double v) {
double f$abs(double v) noexcept {
return std::abs(v);
}

int64_t f$abs(const Optional<int64_t> &v) {
int64_t f$abs(const Optional<int64_t> &v) noexcept {
return f$abs(val(v));
}

int64_t f$abs(const Optional<bool> &v) {
int64_t f$abs(const Optional<bool> &v) noexcept {
return f$abs(static_cast<int64_t>(val(v)));
}

double f$abs(const Optional<double> &v) {
double f$abs(const Optional<double> &v) noexcept {
return f$abs(val(v));
}

Expand Down
72 changes: 36 additions & 36 deletions runtime-common/stdlib/math/math-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,81 @@

#include "runtime-common/core/runtime-core.h"

inline double f$ceil(double v);
inline double f$ceil(double v) noexcept;

inline double f$cos(double v);
inline double f$cos(double v) noexcept;

inline double f$deg2rad(double v);
inline double f$deg2rad(double v) noexcept;

inline double f$floor(double v);
inline double f$floor(double v) noexcept;

inline double f$log(double v);
inline double f$log(double v) noexcept;

inline double f$log(double v, double base);
inline double f$log(double v, double base) noexcept;

template<class T>
inline T f$min(const array<T> &a);
inline T f$min(const array<T> &a) noexcept;

template<class T>
inline T f$max(const array<T> &a);
inline T f$max(const array<T> &a) noexcept;

template<class T>
inline T f$min(const T &arg1);
inline T f$min(const T &arg1) noexcept;

template<class T, class... Args>
inline T f$min(const T &arg1, const T &arg2, Args&&... args);
inline T f$min(const T &arg1, const T &arg2, Args&&... args) noexcept;

template<class T>
inline T f$max(const T &arg1);
inline T f$max(const T &arg1) noexcept;

template<class T, class... Args>
inline T f$max(const T &arg1, const T &arg2, Args&&... args);
inline T f$max(const T &arg1, const T &arg2, Args&&... args) noexcept;

inline double f$pi();
inline double f$pi() noexcept;

inline double f$round(double v, int64_t precision = 0);
inline double f$round(double v, int64_t precision = 0) noexcept;

inline double f$sqrt(double v);
inline double f$sqrt(double v) noexcept;

mixed f$abs(const mixed &v);
int64_t f$abs(int64_t v);
double f$abs(double v);
int64_t f$abs(const Optional<int64_t> &v);
int64_t f$abs(const Optional<bool> &v);
double f$abs(const Optional<double> &v);
mixed f$abs(const mixed &v) noexcept;
int64_t f$abs(int64_t v) noexcept;
double f$abs(double v) noexcept;
int64_t f$abs(const Optional<int64_t> &v) noexcept;
int64_t f$abs(const Optional<bool> &v) noexcept;
double f$abs(const Optional<double> &v) noexcept;

inline double f$ceil(double v) {
inline double f$ceil(double v) noexcept {
return ceil(v);
}

inline double f$cos(double v) {
inline double f$cos(double v) noexcept {
return cos(v);
}

inline double f$deg2rad(double v) {
inline double f$deg2rad(double v) noexcept {
return v * M_PI / 180;
}

inline double f$floor(double v) {
inline double f$floor(double v) noexcept {
return floor(v);
}

inline double f$log(double v) {
inline double f$log(double v) noexcept {
if (v <= 0.0) {
return 0.0;
}
return log(v);
}

inline double f$log(double v, double base) {
inline double f$log(double v, double base) noexcept {
if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) {
return 0.0;
}
return log(v) / log(base);
}

template<class T>
T f$min(const array<T> &a) {
T f$min(const array<T> &a) noexcept {
if (a.count() == 0) {
php_warning("Empty array specified to function min");
return T();
Expand All @@ -97,7 +97,7 @@ T f$min(const array<T> &a) {
}

template<class T>
T f$max(const array<T> &a) {
T f$max(const array<T> &a) noexcept {
if (a.count() == 0) {
php_warning("Empty array specified to function max");
return T();
Expand All @@ -114,30 +114,30 @@ T f$max(const array<T> &a) {
}

template<class T>
T f$min(const T &arg1) {
T f$min(const T &arg1) noexcept {
return arg1;
}

template<class T, class ...Args>
T f$min(const T &arg1, const T &arg2, Args&& ...args) {
T f$min(const T &arg1, const T &arg2, Args&& ...args) noexcept {
return f$min<T>(lt(arg1, arg2) ? arg1 : arg2, std::forward<Args>(args)...);
}

template<class T>
T f$max(const T &arg1) {
T f$max(const T &arg1) noexcept {
return arg1;
}

template<class T, class ...Args>
T f$max(const T &arg1, const T &arg2, Args&& ...args) {
T f$max(const T &arg1, const T &arg2, Args&& ...args) noexcept {
return f$max<T>(lt(arg2, arg1) ? arg1 : arg2, std::forward<Args>(args)...);
}

inline double f$pi() {
inline double f$pi() noexcept {
return M_PI;
}

inline double f$round(double v, int64_t precision) {
inline double f$round(double v, int64_t precision) noexcept {
if (std::abs(precision) > 100) {
php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision);
return v;
Expand All @@ -147,7 +147,7 @@ inline double f$round(double v, int64_t precision) {
return round(v * mul) / mul;
}

inline double f$sqrt(double v) {
inline double f$sqrt(double v) noexcept {
if (v < 0) {
return 0.0;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime-light/stdlib/rpc/rpc-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ string f$fetch_string() noexcept {

// === Rpc Query ==================================================================================

task_t<array<int64_t>> f$rpc_send_request(string actor, array<mixed> tl_objects, double timeout, bool ignore_answer,
task_t<array<int64_t>> f$rpc_send_requests(string actor, array<mixed> tl_objects, double timeout, bool ignore_answer,
class_instance<C$KphpRpcRequestsExtraInfo> requests_extra_info, bool need_responses_extra_info) noexcept {
if (ignore_answer && need_responses_extra_info) {
php_warning("Both $ignore_answer and $need_responses_extra_info are 'true'. Can't collect metrics for ignored answers");
Expand All @@ -380,7 +380,7 @@ task_t<array<int64_t>> f$rpc_send_request(string actor, array<mixed> tl_objects,
co_return query_ids;
}

task_t<array<array<mixed>>> f$rpc_fetch_response(array<int64_t> query_ids) noexcept {
task_t<array<array<mixed>>> f$rpc_fetch_responses(array<int64_t> query_ids) noexcept {
array<array<mixed>> res{query_ids.size()};
for (const auto &it : query_ids) {
res.set_value(it.get_key(), co_await rpc_impl_::rpc_tl_query_result_one_impl(it.get_value()));
Expand Down
8 changes: 4 additions & 4 deletions runtime-light/stdlib/rpc/rpc-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ string f$fetch_string() noexcept;

// === Rpc Query ==================================================================================

task_t<array<int64_t>> f$rpc_send_request(string actor, array<mixed> tl_objects, double timeout = -1.0, bool ignore_answer = false,
task_t<array<int64_t>> f$rpc_send_requests(string actor, array<mixed> tl_objects, double timeout = -1.0, bool ignore_answer = false,
class_instance<C$KphpRpcRequestsExtraInfo> requests_extra_info = {}, bool need_responses_extra_info = false) noexcept;

template<std::derived_from<C$VK$TL$RpcFunction> rpc_function_t, std::same_as<KphpRpcRequest> rpc_request_t = KphpRpcRequest>
task_t<array<int64_t>> f$rpc_send_typed_query_request(string actor, array<class_instance<rpc_function_t>> query_functions, double timeout = -1.0,
task_t<array<int64_t>> f$rpc_send_typed_query_requests(string actor, array<class_instance<rpc_function_t>> query_functions, double timeout = -1.0,
bool ignore_answer = false, class_instance<C$KphpRpcRequestsExtraInfo> requests_extra_info = {},
bool need_responses_extra_info = false) noexcept {
if (ignore_answer && need_responses_extra_info) {
Expand All @@ -87,11 +87,11 @@ task_t<array<int64_t>> f$rpc_send_typed_query_request(string actor, array<class_
co_return query_ids;
}

task_t<array<array<mixed>>> f$rpc_fetch_response(array<int64_t> query_ids) noexcept;
task_t<array<array<mixed>>> f$rpc_fetch_responses(array<int64_t> query_ids) noexcept;

template<std::same_as<int64_t> query_id_t = int64_t, std::same_as<RpcResponseErrorFactory> error_factory_t = RpcResponseErrorFactory>
requires std::default_initializable<error_factory_t> task_t<array<class_instance<C$VK$TL$RpcResponse>>>
f$rpc_fetch_typed_response(array<query_id_t> query_ids) noexcept {
f$rpc_fetch_typed_responses(array<query_id_t> query_ids) noexcept {
array<class_instance<C$VK$TL$RpcResponse>> res{query_ids.size()};
for (const auto &it : query_ids) {
res.set_value(it.get_key(), co_await rpc_impl_::typed_rpc_tl_query_result_one_impl(it.get_value(), error_factory_t{}));
Expand Down
12 changes: 6 additions & 6 deletions tests/k2-components/test_rpc_memcached.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

function do_untyped_rpc() {
$ids = rpc_send_request("mc_main", [["_" => "memcache.get", "key" => "xxx"]]);
$response = rpc_fetch_response($ids)[0];
$ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "xxx"]]);
$response = rpc_fetch_responses($ids)[0];
$result = $response["result"];
if ($result["_"] !== "memcache.not_found") {
warning("memcache.not_found expected");
return false;
}

$ids = rpc_send_request("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]]);
$response = rpc_fetch_response($ids)[0];
$ids = rpc_send_requests("mc_main", [["_" => "memcache.set", "key" => "foo", "flags" => 0, "delay" => 0, "value" => "bar"]]);
$response = rpc_fetch_responses($ids)[0];
$result = $response["result"];
if ($result !== true) {
warning("true expected");
return false;
}

$ids = rpc_send_request("mc_main", [["_" => "memcache.get", "key" => "foo"]]);
$response = rpc_fetch_response($ids)[0];
$ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "foo"]]);
$response = rpc_fetch_responses($ids)[0];
$result = $response["result"];
if ($result["_"] !== "memcache.strvalue" || $result["value"] !== "bar") {
warning("\"bar\" expected");
Expand Down

0 comments on commit d4ac1c9

Please sign in to comment.