diff --git a/builtin-functions/kphp-light/functions.txt b/builtin-functions/kphp-light/functions.txt index 5f73fe5f1c..8f81433d6d 100644 --- a/builtin-functions/kphp-light/functions.txt +++ b/builtin-functions/kphp-light/functions.txt @@ -3,9 +3,11 @@ require_once __DIR__ . '/array.txt'; require_once __DIR__ . '/confdata.txt'; require_once __DIR__ . '/crypto.txt'; -require_once __DIR__ . '/rpc.txt'; require_once __DIR__ . '/hash.txt'; require_once __DIR__ . '/job-workers.txt'; +require_once __DIR__ . '/rpc.txt'; +require_once __DIR__ . '/string.txt'; +require_once __DIR__ . '/kphp-toggles.txt'; /** defined in runtime-core.h **/ function likely ($x ::: bool) ::: bool; diff --git a/builtin-functions/kphp-light/job-workers.txt b/builtin-functions/kphp-light/job-workers.txt index 60d498a4fc..ced0644ab6 100644 --- a/builtin-functions/kphp-light/job-workers.txt +++ b/builtin-functions/kphp-light/job-workers.txt @@ -45,17 +45,17 @@ function get_job_workers_number(): int; // === Job Worker Old API ================================================================================= -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start(KphpJobWorkerRequest $request, float $timeout): future | false; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start_no_reply(KphpJobWorkerRequest $request, float $timeout): bool; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_start_multi(KphpJobWorkerRequest[] $request, float $timeout): (future | false)[]; -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_fetch_request() ::: KphpJobWorkerRequest; // returns 0 on success, < 0 - on errors. All possible error codes are constants like KphpJobWorkerResponseError::JOB_STORE_RESPONSE_* -/** @kphp-extern-func-info generate-stub */ +/** @kphp-extern-func-info interruptible generate-stub */ function kphp_job_worker_store_response(KphpJobWorkerResponse $response) ::: int; diff --git a/builtin-functions/kphp-light/unsupported/kphp-toggles.txt b/builtin-functions/kphp-light/kphp-toggles.txt similarity index 93% rename from builtin-functions/kphp-light/unsupported/kphp-toggles.txt rename to builtin-functions/kphp-light/kphp-toggles.txt index b37589f6dc..f3465b94a4 100644 --- a/builtin-functions/kphp-light/unsupported/kphp-toggles.txt +++ b/builtin-functions/kphp-light/kphp-toggles.txt @@ -1,10 +1,9 @@ is_output_mode_k2()) { + k2_lexer_init(); + } OpInfo::init_static(); MultiKey::init_static(); TypeData::init_static(); diff --git a/compiler/lexer.cpp b/compiler/lexer.cpp index aee442b81a..0d6844893b 100644 --- a/compiler/lexer.cpp +++ b/compiler/lexer.cpp @@ -1018,7 +1018,8 @@ bool TokenLexerComment::parse(LexerData *lexer_data) const { } bool TokenLexerIfndefComment::parse(LexerData *lexer_data) const { - kphp_assert(lexer_data->get_code_view().starts_with("#ifndef KPHP")); + kphp_assert(lexer_data->get_code_view().starts_with("#ifndef KPHP") + || lexer_data->get_code_view().starts_with("#ifndef K2")); auto endif_pos = lexer_data->get_code_view().find("#endif"); if (endif_pos == vk::string_view::npos) { @@ -1251,6 +1252,11 @@ void lexer_init() { vk::singleton::get().init(); } +void k2_lexer_init() { + auto & h = vk::singleton::get().h; + h->add_simple_rule("#ifndef K2", &vk::singleton::get()); +} + std::vector php_text_to_tokens(vk::string_view text) { static TokenLexerGlobal lexer; diff --git a/compiler/lexer.h b/compiler/lexer.h index 0665247f76..6b9042ba7f 100644 --- a/compiler/lexer.h +++ b/compiler/lexer.h @@ -200,5 +200,6 @@ struct TokenLexerGlobal final : TokenLexer { }; void lexer_init(); +void k2_lexer_init(); std::vector php_text_to_tokens(vk::string_view text); std::vector phpdoc_to_tokens(vk::string_view text); diff --git a/compiler/stats.cpp b/compiler/stats.cpp index 4d2b687882..b37816525f 100644 --- a/compiler/stats.cpp +++ b/compiler/stats.cpp @@ -44,6 +44,9 @@ void Stats::on_function_processed(FunctionPtr function) { if (function->is_resumable) { ++total_resumable_functions_; } + if (function->is_interruptible) { + ++total_interruptible_functions_; + } if (function->is_inline) { ++total_inline_functions_; } @@ -78,6 +81,7 @@ void Stats::write_to(std::ostream &out, bool with_indent) const { out << indent << "functions.total_inline: " << total_inline_functions_ << std::endl; out << indent << "functions.total_throwing: " << total_throwing_functions_ << std::endl; out << indent << "functions.total_resumable: " << total_resumable_functions_ << std::endl; + out << indent << "functions.total_interruptible: " << total_interruptible_functions_ << std::endl; out << block_sep; out << indent << "memory.rss: " << memory_rss_ * 1024 << std::endl; out << indent << "memory.rss_peak: " << memory_rss_peak_ * 1024 << std::endl; diff --git a/compiler/stats.h b/compiler/stats.h index fa78c56df9..ca3ef4707e 100644 --- a/compiler/stats.h +++ b/compiler/stats.h @@ -43,6 +43,7 @@ class Stats { std::atomic total_functions_{0u}; std::atomic total_throwing_functions_{0u}; std::atomic total_resumable_functions_{0u}; + std::atomic total_interruptible_functions_{0u}; std::atomic total_inline_functions_{0u}; std::atomic memory_rss_{0}; diff --git a/runtime-common/stdlib/math/math-functions.cpp b/runtime-common/stdlib/math/math-functions.cpp new file mode 100644 index 0000000000..7a1f4b8c41 --- /dev/null +++ b/runtime-common/stdlib/math/math-functions.cpp @@ -0,0 +1,35 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2024 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#include "runtime-common/stdlib/math/math-functions.h" + +#include + +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) noexcept { + return std::abs(v); +} + +double f$abs(double v) noexcept { + return std::abs(v); +} + +int64_t f$abs(const Optional &v) noexcept { + return f$abs(val(v)); +} + +int64_t f$abs(const Optional &v) noexcept { + return f$abs(static_cast(val(v))); +} + +double f$abs(const Optional &v) noexcept { + return f$abs(val(v)); +} diff --git a/runtime-common/stdlib/math/math-functions.h b/runtime-common/stdlib/math/math-functions.h new file mode 100644 index 0000000000..9c62fd5208 --- /dev/null +++ b/runtime-common/stdlib/math/math-functions.h @@ -0,0 +1,155 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2024 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-common/core/runtime-core.h" + +inline double f$ceil(double v) noexcept; + +inline double f$cos(double v) noexcept; + +inline double f$deg2rad(double v) noexcept; + +inline double f$floor(double v) noexcept; + +inline double f$log(double v) noexcept; + +inline double f$log(double v, double base) noexcept; + +template +inline T f$min(const array &a) noexcept; + +template +inline T f$max(const array &a) noexcept; + +template +inline T f$min(const T &arg1) noexcept; + +template +inline T f$min(const T &arg1, const T &arg2, Args &&...args) noexcept; + +template +inline T f$max(const T &arg1) noexcept; + +template +inline T f$max(const T &arg1, const T &arg2, Args &&...args) noexcept; + +inline double f$pi() noexcept; + +inline double f$round(double v, int64_t precision = 0) noexcept; + +inline double f$sqrt(double v) noexcept; + +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 &v) noexcept; +int64_t f$abs(const Optional &v) noexcept; +double f$abs(const Optional &v) noexcept; + +inline double f$ceil(double v) noexcept { + return ceil(v); +} + +inline double f$cos(double v) noexcept { + return cos(v); +} + +inline double f$deg2rad(double v) noexcept { + return v * M_PI / 180; +} + +inline double f$floor(double v) noexcept { + return floor(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) noexcept { + if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) { + return 0.0; + } + return log(v) / log(base); +} + +template +T f$min(const array &a) noexcept { + if (a.count() == 0) { + php_warning("Empty array specified to function min"); + return T(); + } + + typename array::const_iterator p = a.begin(); + T res = p.get_value(); + for (++p; p != a.end(); ++p) { + if (lt(p.get_value(), res)) { + res = p.get_value(); + } + } + return res; +} + +template +T f$max(const array &a) noexcept { + if (a.count() == 0) { + php_warning("Empty array specified to function max"); + return T(); + } + + typename array::const_iterator p = a.begin(); + T res = p.get_value(); + for (++p; p != a.end(); ++p) { + if (lt(res, p.get_value())) { + res = p.get_value(); + } + } + return res; +} + +template +T f$min(const T &arg1) noexcept { + return arg1; +} + +template +T f$min(const T &arg1, const T &arg2, Args &&...args) noexcept { + return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); +} + +template +T f$max(const T &arg1) noexcept { + return arg1; +} + +template +T f$max(const T &arg1, const T &arg2, Args &&...args) noexcept { + return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); +} + +inline double f$pi() noexcept { + return M_PI; +} + +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; + } + + double mul = pow(10.0, (double)precision); + return round(v * mul) / mul; +} + +inline double f$sqrt(double v) noexcept { + if (v < 0) { + return 0.0; + } + return sqrt(v); +} diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index 7b4e259f9c..05a109ae7f 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -1,4 +1,5 @@ prepend(STDLIB_STRING stdlib/string/ string-functions.cpp mbstring-functions.cpp) +prepend(STDLIB_MATH stdlib/math/ math-functions.cpp) -set(STDLIB_SRC "${STDLIB_STRING}") +set(STDLIB_SRC ${STDLIB_STRING} ${STDLIB_MATH}) diff --git a/runtime-light/allocator/runtime-light-allocator.cpp b/runtime-light/allocator/runtime-light-allocator.cpp index 6002b78ca2..9823a9bca4 100644 --- a/runtime-light/allocator/runtime-light-allocator.cpp +++ b/runtime-light/allocator/runtime-light-allocator.cpp @@ -103,6 +103,10 @@ void *RuntimeAllocator::realloc_script_memory(void *mem, size_t new_size, size_t void RuntimeAllocator::free_script_memory(void *mem, size_t size) noexcept { php_assert(size); + if (unlikely(!is_script_allocator_available())) { + free_global_memory(mem, size); + return; + } ComponentState &rt_ctx = *get_component_context(); rt_ctx.runtime_allocator.memory_resource.deallocate(mem, size); diff --git a/runtime-light/stdlib/job-worker/job-worker-api.cpp b/runtime-light/stdlib/job-worker/job-worker-api.cpp index 2d593f54be..78213eac37 100644 --- a/runtime-light/stdlib/job-worker/job-worker-api.cpp +++ b/runtime-light/stdlib/job-worker/job-worker-api.cpp @@ -84,17 +84,17 @@ task_t kphp_job_worker_start_impl(string request, double timeout, bool // ================================================================================================ -task_t> f$k2_job_worker_start(string request, double timeout) noexcept { +task_t> f$job_worker_send_request(string request, double timeout) noexcept { const auto fork_id{co_await kphp_job_worker_start_impl(std::move(request), timeout, false)}; co_return fork_id != INVALID_FORK_ID ? fork_id : false; } -task_t f$k2_job_worker_start_no_reply(string request, double timeout) noexcept { +task_t f$job_worker_send_noreply_request(string request, double timeout) noexcept { const auto fork_id{co_await kphp_job_worker_start_impl(std::move(request), timeout, true)}; co_return fork_id != INVALID_FORK_ID; } -task_t>> f$k2_job_worker_start_multi(array requests, double timeout) noexcept { +task_t>> f$job_worker_send_multi_request(array requests, double timeout) noexcept { array> fork_ids{requests.size()}; for (const auto &it : requests) { const auto fork_id{co_await kphp_job_worker_start_impl(it.get_value(), timeout, false)}; @@ -105,7 +105,7 @@ task_t>> f$k2_job_worker_start_multi(array reque // ================================================================================================ -task_t f$k2_job_worker_fetch_request() noexcept { +task_t f$job_worker_fetch_request() noexcept { if (!f$is_kphp_job_workers_enabled()) { php_warning("couldn't fetch job worker request: job workers are disabled"); co_return string{}; @@ -119,7 +119,7 @@ task_t f$k2_job_worker_fetch_request() noexcept { co_return std::exchange(jw_server_ctx.body, string{}); } -task_t f$k2_job_worker_store_response(string response) noexcept { +task_t f$job_worker_store_response(string response) noexcept { auto &component_ctx{*get_component_context()}; auto &jw_server_ctx{JobWorkerServerComponentContext::get()}; if (!f$is_kphp_job_workers_enabled()) { // workers are enabled diff --git a/runtime-light/stdlib/job-worker/job-worker-api.h b/runtime-light/stdlib/job-worker/job-worker-api.h index 839cb001e8..f9c36a3339 100644 --- a/runtime-light/stdlib/job-worker/job-worker-api.h +++ b/runtime-light/stdlib/job-worker/job-worker-api.h @@ -13,17 +13,17 @@ // === Client ===================================================================================== -task_t> f$k2_job_worker_start(string request, double timeout) noexcept; +task_t> f$job_worker_send_request(string request, double timeout) noexcept; -task_t f$k2_job_worker_start_no_reply(string request, double timeout) noexcept; +task_t f$job_worker_send_noreply_request(string request, double timeout) noexcept; -task_t>> f$k2_job_worker_start_multi(array requests, double timeout) noexcept; +task_t>> f$job_worker_send_multi_request(array requests, double timeout) noexcept; // === Server ===================================================================================== -task_t f$k2_job_worker_fetch_request() noexcept; +task_t f$job_worker_fetch_request() noexcept; -task_t f$k2_job_worker_store_response(string response) noexcept; +task_t f$job_worker_store_response(string response) noexcept; // === Misc ======================================================================================= diff --git a/runtime-light/stdlib/math/math.h b/runtime-light/stdlib/math/math.h deleted file mode 100644 index a559a18228..0000000000 --- a/runtime-light/stdlib/math/math.h +++ /dev/null @@ -1,61 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2024 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#pragma once - -#include "runtime-common/core/runtime-core.h" - -inline mixed f$abs(const mixed &v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(int64_t v) { - php_critical_error("call to unsupported function"); -} - -inline double f$abs(double v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -inline int64_t f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -inline double f$abs(const Optional &v) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const array &a) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const array &a) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const T &arg1) { - php_critical_error("call to unsupported function"); -} - -template -T f$min(const T &arg1, const T &arg2, Args&&... args) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const T &arg1) { - php_critical_error("call to unsupported function"); -} - -template -T f$max(const T &arg1, const T &arg2, Args&&... args) { - php_critical_error("call to unsupported function"); -} diff --git a/runtime-light/stdlib/math/random-functions.h b/runtime-light/stdlib/math/random-functions.h deleted file mode 100644 index ba5dfa3ecb..0000000000 --- a/runtime-light/stdlib/math/random-functions.h +++ /dev/null @@ -1,7 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2024 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#include -#include - diff --git a/runtime-light/stdlib/output/output-buffer.cpp b/runtime-light/stdlib/output/output-buffer.cpp index 4529abd8e6..91675a1645 100644 --- a/runtime-light/stdlib/output/output-buffer.cpp +++ b/runtime-light/stdlib/output/output-buffer.cpp @@ -60,7 +60,7 @@ Optional f$ob_get_clean() noexcept { return httpResponse.output_buffers[httpResponse.current_buffer].str(); } -string f$ob_get_content() { +string f$ob_get_contents() noexcept { Response &httpResponse{get_component_context()->response}; return httpResponse.output_buffers[httpResponse.current_buffer].str(); } diff --git a/runtime-light/stdlib/rpc/rpc-api.cpp b/runtime-light/stdlib/rpc/rpc-api.cpp index 5b7d561a65..de2e113d5e 100644 --- a/runtime-light/stdlib/rpc/rpc-api.cpp +++ b/runtime-light/stdlib/rpc/rpc-api.cpp @@ -358,7 +358,7 @@ string f$fetch_string() noexcept { // === Rpc Query ================================================================================== -task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_objects, double timeout, bool ignore_answer, +task_t> f$rpc_send_requests(string actor, array tl_objects, double timeout, bool ignore_answer, class_instance 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"); @@ -380,7 +380,7 @@ task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_obje co_return query_ids; } -task_t>> f$k2_kphp_rpc_tl_query_result(array query_ids) noexcept { +task_t>> f$rpc_fetch_responses(array query_ids) noexcept { array> 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())); diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index 3cd4869bff..44e6de255a 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -59,11 +59,11 @@ string f$fetch_string() noexcept; // === Rpc Query ================================================================================== - task_t> f$k2_kphp_rpc_tl_query(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, + task_t> f$rpc_send_requests(string actor, array tl_objects, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept; template rpc_function_t, std::same_as rpc_request_t = KphpRpcRequest> -task_t> f$k2_kphp_typed_rpc_tl_query(string actor, array> query_functions, double timeout = -1.0, +task_t> f$rpc_send_typed_query_requests(string actor, array> query_functions, double timeout = -1.0, bool ignore_answer = false, class_instance requests_extra_info = {}, bool need_responses_extra_info = false) noexcept { if (ignore_answer && need_responses_extra_info) { @@ -87,11 +87,11 @@ task_t> f$k2_kphp_typed_rpc_tl_query(string actor, array>> f$k2_kphp_rpc_tl_query_result(array query_ids) noexcept; +task_t>> f$rpc_fetch_responses(array query_ids) noexcept; template query_id_t = int64_t, std::same_as error_factory_t = RpcResponseErrorFactory> requires std::default_initializable task_t>> -f$k2_kphp_typed_rpc_tl_query_result(array query_ids) noexcept { +f$rpc_fetch_typed_responses(array query_ids) noexcept { array> 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{})); diff --git a/runtime-light/utils/panic.cpp b/runtime-light/utils/panic.cpp index bec6d7aa52..0416135fc3 100644 --- a/runtime-light/utils/panic.cpp +++ b/runtime-light/utils/panic.cpp @@ -13,11 +13,10 @@ void critical_error_handler() { constexpr const char *message = "script panic"; const auto &platform_ctx = *get_platform_context(); - auto &component_ctx = *get_component_context(); platform_ctx.log(Debug, strlen(message), message); - if (component_ctx.poll_status != PollStatus::PollFinishedOk && component_ctx.poll_status != PollStatus::PollFinishedError) { - component_ctx.poll_status = PollStatus::PollFinishedError; + if (get_component_context() != nullptr) { + get_component_context()->poll_status = PollStatus::PollFinishedError; } platform_ctx.abort(); exit(1); diff --git a/runtime/math_functions.cpp b/runtime/math_functions.cpp index 928b5ad87a..9c312c1b5f 100644 --- a/runtime/math_functions.cpp +++ b/runtime/math_functions.cpp @@ -267,35 +267,6 @@ Optional f$random_bytes(int64_t length) noexcept { return str; } -mixed f$abs(const mixed &v) { - 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) { - return std::abs(v); -} - -double f$abs(double v) { - return std::abs(v); -} - -int64_t f$abs(const Optional &v) { - return f$abs(val(v)); -} - -int64_t f$abs(const Optional &v) { - return f$abs(static_cast(val(v))); -} - -double f$abs(const Optional &v) { - return f$abs(val(v)); -} - - string f$base_convert(const string &number, int64_t frombase, int64_t tobase) { if (frombase < 2 || frombase > 36) { @@ -358,16 +329,6 @@ string f$base_convert(const string &number, int64_t frombase, int64_t tobase) { return result; } -double f$round(double v, int64_t precision) { - if (std::abs(precision) > 100) { - php_warning("Wrong parameter precision (%" PRIi64 ") in function round", precision); - return v; - } - - double mul = pow(10.0, (double)precision); - return round(v * mul) / mul; -} - void init_math_functions() noexcept { MTRandGenerator::get().lazy_init(); } diff --git a/runtime/math_functions.h b/runtime/math_functions.h index 9102d45fbb..4da9b71a0b 100644 --- a/runtime/math_functions.h +++ b/runtime/math_functions.h @@ -5,6 +5,7 @@ #pragma once #include "runtime-common/core/runtime-core.h" +#include "runtime-common/stdlib/math/math-functions.h" int64_t f$bindec(const string &number) noexcept; @@ -38,43 +39,12 @@ Optional f$random_int(int64_t l, int64_t r) noexcept; Optional f$random_bytes(int64_t length) noexcept; - -template -inline T f$min(const array &a); - -template -inline T f$max(const array &a); - -template -inline T f$min(const T &arg1); - -template -inline T f$min(const T &arg1, const T &arg2, Args&&... args); - -template -inline T f$max(const T &arg1); - -template -inline T f$max(const T &arg1, const T &arg2, Args&&... args); - // TODO REMOVE? constexpr int64_t PHP_ROUND_HALF_UP = 123423141; constexpr int64_t PHP_ROUND_HALF_DOWN = 123423144; constexpr int64_t PHP_ROUND_HALF_EVEN = 123423145; constexpr int64_t PHP_ROUND_HALF_ODD = 123423146; -mixed f$abs(const mixed &v); - -int64_t f$abs(int64_t v); - -double f$abs(double v); - -int64_t f$abs(const Optional &v); - -int64_t f$abs(const Optional &v); - -double f$abs(const Optional &v); - inline double f$acos(double v); inline double f$atan(double v); @@ -83,20 +53,12 @@ inline double f$atan2(double y, double x); string f$base_convert(const string &number, int64_t frombase, int64_t tobase); -inline double f$ceil(double v); - -inline double f$cos(double v); - inline double f$cosh(double v); inline double f$acosh(double v); -inline double f$deg2rad(double v); - inline double f$exp(double v); -inline double f$floor(double v); - inline double f$fmod(double x, double y); inline bool f$is_finite(double v); @@ -105,20 +67,10 @@ inline bool f$is_infinite(double v); inline bool f$is_nan(double v); -inline double f$log(double v); - -inline double f$log(double v, double base); - -inline double f$pi(); - -double f$round(double v, int64_t precision = 0); - inline double f$sin(double v); inline double f$sinh(double v); -inline double f$sqrt(double v); - inline double f$tan(double v); inline double f$asin(double v); @@ -135,61 +87,6 @@ void init_math_functions() noexcept; * */ - -template -T f$min(const array &a) { - if (a.count() == 0) { - php_warning("Empty array specified to function min"); - return T(); - } - - typename array::const_iterator p = a.begin(); - T res = p.get_value(); - for (++p; p != a.end(); ++p) { - if (lt(p.get_value(), res)) { - res = p.get_value(); - } - } - return res; -} - -template -T f$max(const array &a) { - if (a.count() == 0) { - php_warning("Empty array specified to function max"); - return T(); - } - - typename array::const_iterator p = a.begin(); - T res = p.get_value(); - for (++p; p != a.end(); ++p) { - if (lt(res, p.get_value())) { - res = p.get_value(); - } - } - return res; -} - -template -T f$min(const T &arg1) { - return arg1; -} - -template -T f$min(const T &arg1, const T &arg2, Args&& ...args) { - return f$min(lt(arg1, arg2) ? arg1 : arg2, std::forward(args)...); -} - -template -T f$max(const T &arg1) { - return arg1; -} - -template -T f$max(const T &arg1, const T &arg2, Args&& ...args) { - return f$max(lt(arg2, arg1) ? arg1 : arg2, std::forward(args)...); -} - double f$acos(double v) { return acos(v); } @@ -202,14 +99,6 @@ double f$atan2(double y, double x) { return atan2(y, x); } -double f$ceil(double v) { - return ceil(v); -} - -double f$cos(double v) { - return cos(v); -} - double f$cosh(double v) { return cosh(v); } @@ -218,18 +107,10 @@ double f$acosh(double v) { return acosh(v); } -double f$deg2rad(double v) { - return v * M_PI / 180; -} - double f$exp(double v) { return exp(v); } -double f$floor(double v) { - return floor(v); -} - double f$fmod(double x, double y) { if (fabs(x) > 1e100 || fabs(y) < 1e-100) { return 0.0; @@ -250,24 +131,6 @@ bool f$is_nan(double v) { return (std::fpclassify(v) == FP_NAN); } -double f$log(double v) { - if (v <= 0.0) { - return 0.0; - } - return log(v); -} - -double f$log(double v, double base) { - if (v <= 0.0 || base <= 0.0 || fabs(base - 1.0) < 1e-9) { - return 0.0; - } - return log(v) / log(base); -} - -double f$pi() { - return M_PI; -} - double f$sin(double v) { return sin(v); } @@ -276,13 +139,6 @@ double f$sinh(double v) { return sinh(v); } -double f$sqrt(double v) { - if (v < 0) { - return 0.0; - } - return sqrt(v); -} - double f$tan(double v) { return tan(v); } diff --git a/tests/k2-components/test_rpc_memcached.php b/tests/k2-components/test_rpc_memcached.php index 254db83f1a..9b5a68ec06 100644 --- a/tests/k2-components/test_rpc_memcached.php +++ b/tests/k2-components/test_rpc_memcached.php @@ -1,24 +1,24 @@ "memcache.get", "key" => "xxx"]]); - $response = rpc_fetch_response($ids)[0]; + $ids = rpc_send_requests("mc_main", [["_" => "memcache.get", "key" => "xxx"]], -1, false, null, false); + $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"]], -1, false, null, false); + $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"]], -1, false, null, false); + $response = rpc_fetch_responses($ids)[0]; $result = $response["result"]; if ($result["_"] !== "memcache.strvalue" || $result["value"] !== "bar") { warning("\"bar\" expected");