From 3a01bede71213e78623e697c5f62b9bcd3a1d9b0 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Mon, 10 Nov 2025 17:44:43 +0300 Subject: [PATCH 01/16] add some builtins --- runtime-common/stdlib/rpc/rpc-parse.h | 28 +++++++++++++++++++ .../stdlib/diagnostics/exception-functions.h | 6 ++++ runtime-light/stdlib/memory/memory-usage.h | 19 +++++++++++-- runtime-light/stdlib/rpc/rpc-api.h | 13 +++++++-- .../stdlib/serialization/msgpack-functions.h | 22 ++++++++++++--- .../stdlib/string/string-functions.h | 15 ++++++++++ runtime/rpc.cpp | 17 ----------- runtime/rpc.h | 9 +----- 8 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 runtime-common/stdlib/rpc/rpc-parse.h create mode 100644 runtime-light/stdlib/string/string-functions.h diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h new file mode 100644 index 0000000000..f5a61ef57b --- /dev/null +++ b/runtime-common/stdlib/rpc/rpc-parse.h @@ -0,0 +1,28 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2025 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-common/core/runtime-core.h" +#include "runtime-common/core/core-types/decl/optional.h" + +bool f$rpc_parse(const string& new_rpc_data); + +bool f$rpc_parse(const mixed& new_rpc_data) { + if (!new_rpc_data.is_string()) { + php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); + return false; + } + + return f$rpc_parse(new_rpc_data.to_string()); +} + +bool f$rpc_parse(bool new_rpc_data) { + return f$rpc_parse(mixed{new_rpc_data}); +} + +bool f$rpc_parse(const Optional& new_rpc_data) { + auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; + return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); +} \ No newline at end of file diff --git a/runtime-light/stdlib/diagnostics/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h index fb2fda357a..3c163a8e40 100644 --- a/runtime-light/stdlib/diagnostics/exception-functions.h +++ b/runtime-light/stdlib/diagnostics/exception-functions.h @@ -6,6 +6,7 @@ #include #include +#include #include "runtime-common/core/runtime-core.h" #include "runtime-light/stdlib/diagnostics/exception-types.h" @@ -76,6 +77,11 @@ class_instance make_throwable(const string& file, int64_t line, int64_t code, return instance; } +template T> +class_instance make_throwable(const string& err_msg, int64_t code = 0, std::source_location loc = std::source_location::current()) noexcept { + return make_throwable(string{loc.file_name()}, loc.line(), code, err_msg); +} + } // namespace kphp::exception // ================================================================================================ diff --git a/runtime-light/stdlib/memory/memory-usage.h b/runtime-light/stdlib/memory/memory-usage.h index 61955b6b55..83477eb419 100644 --- a/runtime-light/stdlib/memory/memory-usage.h +++ b/runtime-light/stdlib/memory/memory-usage.h @@ -4,9 +4,11 @@ #pragma once -#include - #include "runtime-common/core/allocator/runtime-allocator.h" +#include "runtime-common/core/runtime-core.h" + +#include +#include inline int64_t f$memory_get_peak_usage(bool real_usage = false) noexcept { if (real_usage) { @@ -19,3 +21,16 @@ inline int64_t f$memory_get_peak_usage(bool real_usage = false) noexcept { inline int64_t f$memory_get_usage([[maybe_unused]] bool real_usage = false) noexcept { return static_cast(RuntimeAllocator::get().memory_resource.get_memory_stats().memory_used); } + +inline array f$memory_get_detailed_stats() { + const auto& stats = RuntimeAllocator::get().memory_resource.get_memory_stats(); + return array({std::make_pair(string{"memory_limit"}, static_cast(stats.memory_limit)), + std::make_pair(string{"real_memory_used"}, static_cast(stats.real_memory_used)), + std::make_pair(string{"memory_used"}, static_cast(stats.memory_used)), + std::make_pair(string{"max_real_memory_used"}, static_cast(stats.max_real_memory_used)), + std::make_pair(string{"max_memory_used"}, static_cast(stats.max_memory_used)), + std::make_pair(string{"defragmentation_calls"}, static_cast(stats.defragmentation_calls)), + std::make_pair(string{"huge_memory_pieces"}, static_cast(stats.huge_memory_pieces)), + std::make_pair(string{"small_memory_pieces"}, static_cast(stats.small_memory_pieces)), + std::make_pair(string{"heap_memory_used"}, static_cast(0))}); +} diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index f7b5913ce3..eee7b1493d 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -15,6 +15,7 @@ #include #include "runtime-common/core/runtime-core.h" +#include "runtime-common/stdlib/rpc/rpc-parse.h" #include "runtime-light/coroutine/task.h" #include "runtime-light/server/rpc/rpc-server-state.h" #include "runtime-light/stdlib/component/component-api.h" @@ -170,9 +171,15 @@ inline bool f$rpc_clean() noexcept { return true; } -template -bool f$rpc_parse(T /*unused*/) { - kphp::log::error("call to unsupported function"); +bool f$rpc_parse(const string& new_rpc_data) { + if (new_rpc_data.size() % sizeof(int) != 0) { + php_warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int)new_rpc_data.size()); + return false; + } + + const std::span spn{reinterpret_cast(new_rpc_data.c_str()), new_rpc_data.size()}; + RpcServerInstanceState::get().tl_storer.store_bytes(spn); + return true; } // f$rpc_server_fetch_request() definition is generated into the tl/rpc_server_fetch_request.cpp file. diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index c378719019..c668fc30a9 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -6,8 +6,10 @@ #include "runtime-common/core/runtime-core.h" #include "runtime-common/stdlib/msgpack/unpacker.h" +#include "runtime-light/stdlib/diagnostics/exception-functions.h" #include "runtime-light/stdlib/diagnostics/logs.h" #include "runtime-light/stdlib/serialization/serialization-state.h" +#include "runtime-common/stdlib/serialization/msgpack-functions.h" template ResultType f$msgpack_deserialize(const string& buffer, string* out_err_msg = nullptr) noexcept { @@ -51,11 +53,23 @@ ResultClass f$instance_deserialize(const string& buffer, const string& /*unused* } template -string f$instance_serialize_safe(const class_instance& /*instance*/) noexcept { - kphp::log::error("call to unsupported function"); +string f$instance_serialize_safe(const class_instance& instance) noexcept { + string err_msg; + auto result = msgpack_functions_impl_::common_instance_serialize(instance, &err_msg); + if (!err_msg.empty()) { + THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); + return {}; + } + return result.val(); } template -ResultClass f$instance_deserialize_safe(const string& /*buffer*/, const string& /*unused*/) noexcept { - kphp::log::error("call to unsupported function"); +ResultClass f$instance_deserialize_safe(const string& buffer, const string& /*unused*/) noexcept { + string err_msg; + auto res = f$msgpack_deserialize(buffer, &err_msg); + if (!err_msg.empty()) { + THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); + return {}; + } + return res; } diff --git a/runtime-light/stdlib/string/string-functions.h b/runtime-light/stdlib/string/string-functions.h new file mode 100644 index 0000000000..02b089802d --- /dev/null +++ b/runtime-light/stdlib/string/string-functions.h @@ -0,0 +1,15 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2025 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-common/core/core-types/decl/optional.h" +#include "runtime-common/core/runtime-core.h" +#include "runtime-light/k2-platform/k2-header.h" +#include + +Optional f$setlocale(int64_t category, const string& locale) noexcept { + const int32_t i32category = static_cast(category); + return k2_uselocale(i32category, locale.c_str()) ? false : k2_current_locale_name(i32category); +} diff --git a/runtime/rpc.cpp b/runtime/rpc.cpp index c9e947f0c3..c4a919972e 100644 --- a/runtime/rpc.cpp +++ b/runtime/rpc.cpp @@ -157,23 +157,6 @@ bool f$rpc_parse(const string& new_rpc_data) { return true; } -bool f$rpc_parse(const mixed& new_rpc_data) { - if (!new_rpc_data.is_string()) { - php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); - return false; - } - - return f$rpc_parse(new_rpc_data.to_string()); -} - -bool f$rpc_parse(bool new_rpc_data) { - return f$rpc_parse(mixed{new_rpc_data}); -} - -bool f$rpc_parse(const Optional& new_rpc_data) { - auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; - return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); -} int32_t rpc_get_pos() { return static_cast(rpc_data - rpc_data_begin); diff --git a/runtime/rpc.h b/runtime/rpc.h index 740c314115..fc0f15590d 100644 --- a/runtime/rpc.h +++ b/runtime/rpc.h @@ -11,6 +11,7 @@ #include "common/algorithms/hashes.h" #include "common/kprintf.h" #include "runtime-common/core/runtime-core.h" +#include "runtime-common/stdlib/rpc/rpc-parse.h" #include "runtime-common/stdlib/visitors/dummy-visitor-methods.h" #include "runtime/net_events.h" #include "runtime/resumable.h" @@ -65,14 +66,6 @@ void last_rpc_error_reset(); void rpc_parse(const int32_t* new_rpc_data, int32_t new_rpc_data_len); -bool f$rpc_parse(const string& new_rpc_data); - -bool f$rpc_parse(const mixed& new_rpc_data); - -bool f$rpc_parse(bool new_rpc_data); - -bool f$rpc_parse(const Optional& new_rpc_data); - int32_t rpc_get_pos(); bool rpc_set_pos(int32_t pos); From ef712a0bcb94d97ab5cc48f151560fe1fde99bac Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Mon, 10 Nov 2025 17:48:26 +0300 Subject: [PATCH 02/16] minifix --- runtime-common/stdlib/rpc/rpc-parse.h | 4 ++-- runtime-light/stdlib/serialization/msgpack-functions.h | 2 +- runtime/rpc.cpp | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h index f5a61ef57b..afec8d3bfc 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.h +++ b/runtime-common/stdlib/rpc/rpc-parse.h @@ -4,8 +4,8 @@ #pragma once -#include "runtime-common/core/runtime-core.h" #include "runtime-common/core/core-types/decl/optional.h" +#include "runtime-common/core/runtime-core.h" bool f$rpc_parse(const string& new_rpc_data); @@ -25,4 +25,4 @@ bool f$rpc_parse(bool new_rpc_data) { bool f$rpc_parse(const Optional& new_rpc_data) { auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); -} \ No newline at end of file +} diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index c668fc30a9..8917498674 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -6,10 +6,10 @@ #include "runtime-common/core/runtime-core.h" #include "runtime-common/stdlib/msgpack/unpacker.h" +#include "runtime-common/stdlib/serialization/msgpack-functions.h" #include "runtime-light/stdlib/diagnostics/exception-functions.h" #include "runtime-light/stdlib/diagnostics/logs.h" #include "runtime-light/stdlib/serialization/serialization-state.h" -#include "runtime-common/stdlib/serialization/msgpack-functions.h" template ResultType f$msgpack_deserialize(const string& buffer, string* out_err_msg = nullptr) noexcept { diff --git a/runtime/rpc.cpp b/runtime/rpc.cpp index c4a919972e..e750c33593 100644 --- a/runtime/rpc.cpp +++ b/runtime/rpc.cpp @@ -157,7 +157,6 @@ bool f$rpc_parse(const string& new_rpc_data) { return true; } - int32_t rpc_get_pos() { return static_cast(rpc_data - rpc_data_begin); } From ffed96e241aff6eff72547149b7e461517ed4c64 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Mon, 10 Nov 2025 18:16:59 +0300 Subject: [PATCH 03/16] add inline --- runtime-common/stdlib/rpc/rpc-parse.h | 8 ++++---- runtime-light/stdlib/rpc/rpc-api.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h index afec8d3bfc..68db3cd120 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.h +++ b/runtime-common/stdlib/rpc/rpc-parse.h @@ -7,9 +7,9 @@ #include "runtime-common/core/core-types/decl/optional.h" #include "runtime-common/core/runtime-core.h" -bool f$rpc_parse(const string& new_rpc_data); +inline bool f$rpc_parse(const string& new_rpc_data); -bool f$rpc_parse(const mixed& new_rpc_data) { +inline bool f$rpc_parse(const mixed& new_rpc_data) { if (!new_rpc_data.is_string()) { php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); return false; @@ -18,11 +18,11 @@ bool f$rpc_parse(const mixed& new_rpc_data) { return f$rpc_parse(new_rpc_data.to_string()); } -bool f$rpc_parse(bool new_rpc_data) { +inline bool f$rpc_parse(bool new_rpc_data) { return f$rpc_parse(mixed{new_rpc_data}); } -bool f$rpc_parse(const Optional& new_rpc_data) { +inline bool f$rpc_parse(const Optional& new_rpc_data) { auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); } diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index eee7b1493d..64839d20f3 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -171,7 +171,7 @@ inline bool f$rpc_clean() noexcept { return true; } -bool f$rpc_parse(const string& new_rpc_data) { +inline bool f$rpc_parse(const string& new_rpc_data) { if (new_rpc_data.size() % sizeof(int) != 0) { php_warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int)new_rpc_data.size()); return false; From b41ee5e0bddc0886a7b0d07c57fe33f9c9899f20 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Mon, 10 Nov 2025 19:40:32 +0300 Subject: [PATCH 04/16] minifix --- runtime-common/stdlib/rpc/rpc-parse.cpp | 23 +++++++++++++++++++++++ runtime-common/stdlib/rpc/rpc-parse.h | 20 ++++---------------- runtime-common/stdlib/stdlib.cmake | 7 ++++--- 3 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 runtime-common/stdlib/rpc/rpc-parse.cpp diff --git a/runtime-common/stdlib/rpc/rpc-parse.cpp b/runtime-common/stdlib/rpc/rpc-parse.cpp new file mode 100644 index 0000000000..770e4f0281 --- /dev/null +++ b/runtime-common/stdlib/rpc/rpc-parse.cpp @@ -0,0 +1,23 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2025 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#include "runtime-common/stdlib/rpc/rpc-parse.h" + +bool f$rpc_parse(const mixed& new_rpc_data) { + if (!new_rpc_data.is_string()) { + php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); + return false; + } + + return f$rpc_parse(new_rpc_data.to_string()); +} + +bool f$rpc_parse(bool new_rpc_data) { + return f$rpc_parse(mixed{new_rpc_data}); +} + +bool f$rpc_parse(const Optional& new_rpc_data) { + auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; + return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); +} diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h index 68db3cd120..5b8cd9ab97 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.h +++ b/runtime-common/stdlib/rpc/rpc-parse.h @@ -7,22 +7,10 @@ #include "runtime-common/core/core-types/decl/optional.h" #include "runtime-common/core/runtime-core.h" -inline bool f$rpc_parse(const string& new_rpc_data); +bool f$rpc_parse(const string& new_rpc_data); -inline bool f$rpc_parse(const mixed& new_rpc_data) { - if (!new_rpc_data.is_string()) { - php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); - return false; - } +bool f$rpc_parse(const mixed& new_rpc_data); - return f$rpc_parse(new_rpc_data.to_string()); -} +bool f$rpc_parse(bool new_rpc_data); -inline bool f$rpc_parse(bool new_rpc_data) { - return f$rpc_parse(mixed{new_rpc_data}); -} - -inline bool f$rpc_parse(const Optional& new_rpc_data) { - auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; - return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); -} +bool f$rpc_parse(const Optional& new_rpc_data); diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index 46b4f14cfd..e2341c9b64 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -4,6 +4,7 @@ prepend(STDLIB_MATH stdlib/math/ math-functions.cpp bcmath-functions.cpp math-context.cpp) prepend(STDLIB_MSGPACK stdlib/msgpack/ object_visitor.cpp packer.cpp parser.cpp unpacker.cpp zone.cpp) +prepend(STDLIB_RPC stdlib/rpc/ rpc-parse.cpp) prepend(STDLIB_SERIALIZATION stdlib/serialization/ json-functions.cpp json-writer.cpp serialize-functions.cpp) prepend(STDLIB_STRING stdlib/string/ mbstring-functions.cpp @@ -14,9 +15,9 @@ prepend(STDLIB_SERVER stdlib/server/ url-functions.cpp prepend(STDLIB_VKEXT stdlib/vkext/ string-processing.cpp vkext-functions.cpp vkext-stats.cpp) -if(COMPILER_CLANG) +if (COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) -endif() +endif () set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} - ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) + ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) From 5bb6d573eb178d7ce15fcf6f126a95bd677e7554 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 12:59:27 +0300 Subject: [PATCH 05/16] fixes --- runtime-common/stdlib/rpc/rpc-parse.cpp | 11 +++++++---- runtime-common/stdlib/rpc/rpc-parse.h | 9 ++++----- runtime-common/stdlib/stdlib.cmake | 2 +- runtime-light/stdlib/memory/memory-usage.h | 10 +++++----- runtime-light/stdlib/rpc/rpc-api.h | 6 +++--- .../stdlib/serialization/msgpack-functions.h | 4 ++-- runtime-light/stdlib/string/string-functions.h | 10 +++++----- runtime/rpc.cpp | 2 +- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/runtime-common/stdlib/rpc/rpc-parse.cpp b/runtime-common/stdlib/rpc/rpc-parse.cpp index 770e4f0281..f5b9087d6d 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.cpp +++ b/runtime-common/stdlib/rpc/rpc-parse.cpp @@ -4,20 +4,23 @@ #include "runtime-common/stdlib/rpc/rpc-parse.h" -bool f$rpc_parse(const mixed& new_rpc_data) { +#include "runtime-common/core/runtime-core.h" +#include "runtime-light/stdlib/diagnostics/logs.h" + +bool f$rpc_parse(const mixed& new_rpc_data) noexcept { if (!new_rpc_data.is_string()) { - php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); + kphp::log::warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); return false; } return f$rpc_parse(new_rpc_data.to_string()); } -bool f$rpc_parse(bool new_rpc_data) { +bool f$rpc_parse(bool new_rpc_data) noexcept { return f$rpc_parse(mixed{new_rpc_data}); } -bool f$rpc_parse(const Optional& new_rpc_data) { +bool f$rpc_parse(const Optional& new_rpc_data) noexcept { auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); } diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h index 5b8cd9ab97..40330ada0e 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.h +++ b/runtime-common/stdlib/rpc/rpc-parse.h @@ -4,13 +4,12 @@ #pragma once -#include "runtime-common/core/core-types/decl/optional.h" #include "runtime-common/core/runtime-core.h" -bool f$rpc_parse(const string& new_rpc_data); +bool f$rpc_parse(const string& new_rpc_data) noexcept; -bool f$rpc_parse(const mixed& new_rpc_data); +bool f$rpc_parse(const mixed& new_rpc_data) noexcept; -bool f$rpc_parse(bool new_rpc_data); +bool f$rpc_parse(bool new_rpc_data) noexcept; -bool f$rpc_parse(const Optional& new_rpc_data); +bool f$rpc_parse(const Optional& new_rpc_data) noexcept; diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index e2341c9b64..4c68ce62da 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -19,5 +19,5 @@ if (COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) endif () -set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} +set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_RPC} ${STDLIB_SERIALIZATION} ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) diff --git a/runtime-light/stdlib/memory/memory-usage.h b/runtime-light/stdlib/memory/memory-usage.h index 83477eb419..d43383c634 100644 --- a/runtime-light/stdlib/memory/memory-usage.h +++ b/runtime-light/stdlib/memory/memory-usage.h @@ -4,12 +4,12 @@ #pragma once -#include "runtime-common/core/allocator/runtime-allocator.h" -#include "runtime-common/core/runtime-core.h" - #include #include +#include "runtime-common/core/allocator/runtime-allocator.h" +#include "runtime-common/core/runtime-core.h" + inline int64_t f$memory_get_peak_usage(bool real_usage = false) noexcept { if (real_usage) { return static_cast(RuntimeAllocator::get().memory_resource.get_memory_stats().max_real_memory_used); @@ -22,8 +22,8 @@ inline int64_t f$memory_get_usage([[maybe_unused]] bool real_usage = false) noex return static_cast(RuntimeAllocator::get().memory_resource.get_memory_stats().memory_used); } -inline array f$memory_get_detailed_stats() { - const auto& stats = RuntimeAllocator::get().memory_resource.get_memory_stats(); +inline array f$memory_get_detailed_stats() noexcept { + const auto& stats{RuntimeAllocator::get().memory_resource.get_memory_stats()}; return array({std::make_pair(string{"memory_limit"}, static_cast(stats.memory_limit)), std::make_pair(string{"real_memory_used"}, static_cast(stats.real_memory_used)), std::make_pair(string{"memory_used"}, static_cast(stats.memory_used)), diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index 64839d20f3..cc8bde3bd4 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -171,9 +171,9 @@ inline bool f$rpc_clean() noexcept { return true; } -inline bool f$rpc_parse(const string& new_rpc_data) { - if (new_rpc_data.size() % sizeof(int) != 0) { - php_warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int)new_rpc_data.size()); +inline bool f$rpc_parse(const string& new_rpc_data) noexcept { + if (new_rpc_data.size() % sizeof(int32_t) != 0) { + kphp::log::warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int32_t)new_rpc_data.size()); return false; } diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index 8917498674..2ce1131804 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -55,7 +55,7 @@ ResultClass f$instance_deserialize(const string& buffer, const string& /*unused* template string f$instance_serialize_safe(const class_instance& instance) noexcept { string err_msg; - auto result = msgpack_functions_impl_::common_instance_serialize(instance, &err_msg); + auto result{msgpack_functions_impl_::common_instance_serialize(instance, &err_msg)}; if (!err_msg.empty()) { THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); return {}; @@ -66,7 +66,7 @@ string f$instance_serialize_safe(const class_instance& instance) template ResultClass f$instance_deserialize_safe(const string& buffer, const string& /*unused*/) noexcept { string err_msg; - auto res = f$msgpack_deserialize(buffer, &err_msg); + auto res{f$msgpack_deserialize(buffer, &err_msg)}; if (!err_msg.empty()) { THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); return {}; diff --git a/runtime-light/stdlib/string/string-functions.h b/runtime-light/stdlib/string/string-functions.h index 02b089802d..0f77c93533 100644 --- a/runtime-light/stdlib/string/string-functions.h +++ b/runtime-light/stdlib/string/string-functions.h @@ -4,12 +4,12 @@ #pragma once -#include "runtime-common/core/core-types/decl/optional.h" -#include "runtime-common/core/runtime-core.h" -#include "runtime-light/k2-platform/k2-header.h" #include +#include "runtime-common/core/runtime-core.h" +#include "runtime-light/k2-platform/k2-api.h" + Optional f$setlocale(int64_t category, const string& locale) noexcept { - const int32_t i32category = static_cast(category); - return k2_uselocale(i32category, locale.c_str()) ? false : k2_current_locale_name(i32category); + const int32_t i32category{static_cast(category)}; + return k2_uselocale(i32category, locale.c_str()) == k2::errno_ok ? false : k2_current_locale_name(i32category); } diff --git a/runtime/rpc.cpp b/runtime/rpc.cpp index e750c33593..118f022086 100644 --- a/runtime/rpc.cpp +++ b/runtime/rpc.cpp @@ -138,7 +138,7 @@ void rpc_parse(const int32_t* new_rpc_data, int32_t new_rpc_data_len) { rpc_data_len = new_rpc_data_len; } -bool f$rpc_parse(const string& new_rpc_data) { +bool f$rpc_parse(const string& new_rpc_data) noexcept { if (new_rpc_data.size() % sizeof(int) != 0) { php_warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int)new_rpc_data.size()); last_rpc_error = "Result's length is not divisible by 4"; From 076f535c2174d09012975b3081838fd71325fcf2 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 14:28:41 +0300 Subject: [PATCH 06/16] stub --- runtime-common/stdlib/stdlib.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index 4c68ce62da..e2341c9b64 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -19,5 +19,5 @@ if (COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) endif () -set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_RPC} ${STDLIB_SERIALIZATION} +set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) From 26a2367f61b885054a779a6f9908b81996fa324b Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 14:31:43 +0300 Subject: [PATCH 07/16] minifix --- runtime-common/stdlib/stdlib.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index e2341c9b64..ea914021a5 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -15,9 +15,9 @@ prepend(STDLIB_SERVER stdlib/server/ url-functions.cpp prepend(STDLIB_VKEXT stdlib/vkext/ string-processing.cpp vkext-functions.cpp vkext-stats.cpp) -if (COMPILER_CLANG) +if(COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) -endif () +endif() set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} - ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) + ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) From db178f3aadae4d6c3bf41d17a3059b64213ef68f Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 14:47:16 +0300 Subject: [PATCH 08/16] minifix --- runtime-common/stdlib/rpc/rpc-parse.cpp | 3 +-- runtime-common/stdlib/stdlib.cmake | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime-common/stdlib/rpc/rpc-parse.cpp b/runtime-common/stdlib/rpc/rpc-parse.cpp index f5b9087d6d..7954ce1b9e 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.cpp +++ b/runtime-common/stdlib/rpc/rpc-parse.cpp @@ -5,11 +5,10 @@ #include "runtime-common/stdlib/rpc/rpc-parse.h" #include "runtime-common/core/runtime-core.h" -#include "runtime-light/stdlib/diagnostics/logs.h" bool f$rpc_parse(const mixed& new_rpc_data) noexcept { if (!new_rpc_data.is_string()) { - kphp::log::warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); + php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); return false; } diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index ea914021a5..334a8b3967 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -19,5 +19,5 @@ if(COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) endif() -set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} +set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_RPC} ${STDLIB_SERIALIZATION} ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) From 2a1b570bf539344e6123b3f820f89fbe6e48f4fe Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 18:36:48 +0300 Subject: [PATCH 09/16] fixes --- runtime-common/stdlib/rpc/rpc-parse.cpp | 2 +- runtime-light/k2-platform/k2-api.h | 12 ++++++++++++ .../stdlib/diagnostics/exception-functions.h | 15 ++++++++------- runtime-light/stdlib/rpc/rpc-api.h | 2 +- .../stdlib/serialization/msgpack-functions.h | 5 +++-- runtime-light/stdlib/string/string-functions.h | 8 ++++++-- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/runtime-common/stdlib/rpc/rpc-parse.cpp b/runtime-common/stdlib/rpc/rpc-parse.cpp index 7954ce1b9e..f05a692eff 100644 --- a/runtime-common/stdlib/rpc/rpc-parse.cpp +++ b/runtime-common/stdlib/rpc/rpc-parse.cpp @@ -20,6 +20,6 @@ bool f$rpc_parse(bool new_rpc_data) noexcept { } bool f$rpc_parse(const Optional& new_rpc_data) noexcept { - auto rpc_parse_lambda = [](const auto& v) { return f$rpc_parse(v); }; + auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); } diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index 165e00286c..cb7732849d 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -292,6 +292,18 @@ inline struct tm* localtime_r(const time_t* timer, struct tm* result) noexcept { return k2_localtime_r(timer, result); } +inline int32_t uselocale(int32_t category, std::string_view locale) noexcept { + return k2_uselocale(category, locale.data()); +} + +inline std::optional current_locale_name(int32_t category) noexcept { + auto* name{k2_current_locale_name(category)}; + if (name) { + return name; + } + return std::nullopt; +} + inline int32_t udp_connect(k2::descriptor* descriptor, const char* host, size_t host_len) noexcept { return k2_udp_connect(descriptor, host, host_len); } diff --git a/runtime-light/stdlib/diagnostics/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h index 3c163a8e40..dfa8d794eb 100644 --- a/runtime-light/stdlib/diagnostics/exception-functions.h +++ b/runtime-light/stdlib/diagnostics/exception-functions.h @@ -66,20 +66,20 @@ namespace kphp::exception { template T> -class_instance make_throwable(const string& file, int64_t line, int64_t code, const string& desc) noexcept { +class_instance make_throwable(string file, int64_t line, int64_t code, string desc) noexcept { auto instance{make_instance()}; auto* instance_ptr{instance.get()}; - instance_ptr->$file = file; + instance_ptr->$file = std::move(file); instance_ptr->$line = line; instance_ptr->$code = code; - instance_ptr->$message = desc; + instance_ptr->$message = std::move(desc); return instance; } template T> -class_instance make_throwable(const string& err_msg, int64_t code = 0, std::source_location loc = std::source_location::current()) noexcept { - return make_throwable(string{loc.file_name()}, loc.line(), code, err_msg); +class_instance make_throwable(string err_msg, int64_t code = 0, std::source_location loc = std::source_location::current()) noexcept { + return make_throwable(string{loc.file_name()}, loc.line(), code, std::move(err_msg)); } } // namespace kphp::exception @@ -93,6 +93,7 @@ T f$_exception_set_location(const T& e, const string& file, int64_t line) noexce return e; } -inline Exception f$err(const string& file, int64_t line, const string& code, const string& desc = {}) noexcept { - return kphp::exception::make_throwable(file, line, 0, (RuntimeContext::get().static_SB.clean() << "ERR_" << code << ": " << desc).str()); +inline Exception f$err(string file, int64_t line, const string& code, const string& desc = {}) noexcept { + return kphp::exception::make_throwable(std::move(file), line, 0, + (RuntimeContext::get().static_SB.clean() << "ERR_" << code << ": " << desc).str()); } diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index cc8bde3bd4..e466b1ec38 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -173,7 +173,7 @@ inline bool f$rpc_clean() noexcept { inline bool f$rpc_parse(const string& new_rpc_data) noexcept { if (new_rpc_data.size() % sizeof(int32_t) != 0) { - kphp::log::warning("Wrong parameter \"new_rpc_data\" of len %d passed to function rpc_parse", (int32_t)new_rpc_data.size()); + kphp::log::warning("wrong parameter \"new_rpc_data\" of len {} passed to function rpc_parse", new_rpc_data.size()); return false; } diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index 2ce1131804..243c1dd2b7 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -57,9 +57,10 @@ string f$instance_serialize_safe(const class_instance& instance) string err_msg; auto result{msgpack_functions_impl_::common_instance_serialize(instance, &err_msg)}; if (!err_msg.empty()) { - THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); + THROW_EXCEPTION(kphp::exception::make_throwable(std::move(err_msg))); return {}; } + kphp::log::assertion(result.has_value()); return result.val(); } @@ -68,7 +69,7 @@ ResultClass f$instance_deserialize_safe(const string& buffer, const string& /*un string err_msg; auto res{f$msgpack_deserialize(buffer, &err_msg)}; if (!err_msg.empty()) { - THROW_EXCEPTION(kphp::exception::make_throwable(err_msg)); + THROW_EXCEPTION(kphp::exception::make_throwable(std::move(err_msg))); return {}; } return res; diff --git a/runtime-light/stdlib/string/string-functions.h b/runtime-light/stdlib/string/string-functions.h index 0f77c93533..bc79579c84 100644 --- a/runtime-light/stdlib/string/string-functions.h +++ b/runtime-light/stdlib/string/string-functions.h @@ -9,7 +9,11 @@ #include "runtime-common/core/runtime-core.h" #include "runtime-light/k2-platform/k2-api.h" -Optional f$setlocale(int64_t category, const string& locale) noexcept { +inline Optional f$setlocale(int64_t category, const string& locale) noexcept { const int32_t i32category{static_cast(category)}; - return k2_uselocale(i32category, locale.c_str()) == k2::errno_ok ? false : k2_current_locale_name(i32category); + if (k2::uselocale(i32category, locale.c_str()) != k2::errno_ok) { + return false; + } + const auto locale_name{k2::current_locale_name(i32category)}; + return locale_name.has_value() ? locale_name->data() : false; } From 4baa68eff42e9c13443eb29540680ec9490b80a7 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Tue, 11 Nov 2025 19:17:53 +0300 Subject: [PATCH 10/16] minifix --- runtime-light/k2-platform/k2-api.h | 6 +++--- runtime-light/stdlib/diagnostics/exception-functions.h | 1 + runtime-light/stdlib/serialization/msgpack-functions.h | 6 ++++-- runtime-light/stdlib/string/string-functions.h | 9 ++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/runtime-light/k2-platform/k2-api.h b/runtime-light/k2-platform/k2-api.h index cb7732849d..8884086177 100644 --- a/runtime-light/k2-platform/k2-api.h +++ b/runtime-light/k2-platform/k2-api.h @@ -298,10 +298,10 @@ inline int32_t uselocale(int32_t category, std::string_view locale) noexcept { inline std::optional current_locale_name(int32_t category) noexcept { auto* name{k2_current_locale_name(category)}; - if (name) { - return name; + if (name == nullptr) [[unlikely]] { + return std::nullopt; } - return std::nullopt; + return std::string_view{name}; } inline int32_t udp_connect(k2::descriptor* descriptor, const char* host, size_t host_len) noexcept { diff --git a/runtime-light/stdlib/diagnostics/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h index dfa8d794eb..3779a97d9f 100644 --- a/runtime-light/stdlib/diagnostics/exception-functions.h +++ b/runtime-light/stdlib/diagnostics/exception-functions.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "runtime-common/core/runtime-core.h" diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index 243c1dd2b7..1f4501e455 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "runtime-common/core/runtime-core.h" #include "runtime-common/stdlib/msgpack/unpacker.h" #include "runtime-common/stdlib/serialization/msgpack-functions.h" @@ -55,7 +57,7 @@ ResultClass f$instance_deserialize(const string& buffer, const string& /*unused* template string f$instance_serialize_safe(const class_instance& instance) noexcept { string err_msg; - auto result{msgpack_functions_impl_::common_instance_serialize(instance, &err_msg)}; + auto result{msgpack_functions_impl_::common_instance_serialize(instance, std::addressof(err_msg))}; if (!err_msg.empty()) { THROW_EXCEPTION(kphp::exception::make_throwable(std::move(err_msg))); return {}; @@ -67,7 +69,7 @@ string f$instance_serialize_safe(const class_instance& instance) template ResultClass f$instance_deserialize_safe(const string& buffer, const string& /*unused*/) noexcept { string err_msg; - auto res{f$msgpack_deserialize(buffer, &err_msg)}; + auto res{f$msgpack_deserialize(buffer, std::addressof(err_msg))}; if (!err_msg.empty()) { THROW_EXCEPTION(kphp::exception::make_throwable(std::move(err_msg))); return {}; diff --git a/runtime-light/stdlib/string/string-functions.h b/runtime-light/stdlib/string/string-functions.h index bc79579c84..28b7ad35c6 100644 --- a/runtime-light/stdlib/string/string-functions.h +++ b/runtime-light/stdlib/string/string-functions.h @@ -11,9 +11,12 @@ inline Optional f$setlocale(int64_t category, const string& locale) noexcept { const int32_t i32category{static_cast(category)}; - if (k2::uselocale(i32category, locale.c_str()) != k2::errno_ok) { + if (k2::uselocale(i32category, {locale.c_str(), locale.size()}) != k2::errno_ok) { return false; } - const auto locale_name{k2::current_locale_name(i32category)}; - return locale_name.has_value() ? locale_name->data() : false; + const auto opt_locale_name{k2::current_locale_name(i32category)}; + if (!opt_locale_name.has_value()) [[unlikely]] { + return false; + } + return opt_locale_name->data(); } From f112d6ce4363877e5d3d0a26dc5e6a0cc23a2adc Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 12:11:07 +0300 Subject: [PATCH 11/16] del runtime-common/stdlib/rpc --- runtime-common/stdlib/rpc/rpc-parse.cpp | 25 ------------------------- runtime-common/stdlib/rpc/rpc-parse.h | 15 --------------- runtime-common/stdlib/stdlib.cmake | 3 +-- runtime-light/stdlib/rpc/rpc-api.h | 19 ++++++++++++++++++- runtime/rpc.cpp | 18 ++++++++++++++++++ runtime/rpc.h | 9 ++++++++- 6 files changed, 45 insertions(+), 44 deletions(-) delete mode 100644 runtime-common/stdlib/rpc/rpc-parse.cpp delete mode 100644 runtime-common/stdlib/rpc/rpc-parse.h diff --git a/runtime-common/stdlib/rpc/rpc-parse.cpp b/runtime-common/stdlib/rpc/rpc-parse.cpp deleted file mode 100644 index f05a692eff..0000000000 --- a/runtime-common/stdlib/rpc/rpc-parse.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2025 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#include "runtime-common/stdlib/rpc/rpc-parse.h" - -#include "runtime-common/core/runtime-core.h" - -bool f$rpc_parse(const mixed& new_rpc_data) noexcept { - if (!new_rpc_data.is_string()) { - php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); - return false; - } - - return f$rpc_parse(new_rpc_data.to_string()); -} - -bool f$rpc_parse(bool new_rpc_data) noexcept { - return f$rpc_parse(mixed{new_rpc_data}); -} - -bool f$rpc_parse(const Optional& new_rpc_data) noexcept { - auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; - return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); -} diff --git a/runtime-common/stdlib/rpc/rpc-parse.h b/runtime-common/stdlib/rpc/rpc-parse.h deleted file mode 100644 index 40330ada0e..0000000000 --- a/runtime-common/stdlib/rpc/rpc-parse.h +++ /dev/null @@ -1,15 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2025 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#pragma once - -#include "runtime-common/core/runtime-core.h" - -bool f$rpc_parse(const string& new_rpc_data) noexcept; - -bool f$rpc_parse(const mixed& new_rpc_data) noexcept; - -bool f$rpc_parse(bool new_rpc_data) noexcept; - -bool f$rpc_parse(const Optional& new_rpc_data) noexcept; diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index 334a8b3967..46b4f14cfd 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -4,7 +4,6 @@ prepend(STDLIB_MATH stdlib/math/ math-functions.cpp bcmath-functions.cpp math-context.cpp) prepend(STDLIB_MSGPACK stdlib/msgpack/ object_visitor.cpp packer.cpp parser.cpp unpacker.cpp zone.cpp) -prepend(STDLIB_RPC stdlib/rpc/ rpc-parse.cpp) prepend(STDLIB_SERIALIZATION stdlib/serialization/ json-functions.cpp json-writer.cpp serialize-functions.cpp) prepend(STDLIB_STRING stdlib/string/ mbstring-functions.cpp @@ -19,5 +18,5 @@ if(COMPILER_CLANG) set_source_files_properties(${RUNTIME_COMMON_DIR}/stdlib/vkext/string-processing.cpp PROPERTIES COMPILE_FLAGS -Wno-invalid-source-encoding) endif() -set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_RPC} ${STDLIB_SERIALIZATION} +set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION} ${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_VKEXT}) diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index e466b1ec38..eff6479727 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -15,7 +15,6 @@ #include #include "runtime-common/core/runtime-core.h" -#include "runtime-common/stdlib/rpc/rpc-parse.h" #include "runtime-light/coroutine/task.h" #include "runtime-light/server/rpc/rpc-server-state.h" #include "runtime-light/stdlib/component/component-api.h" @@ -182,6 +181,24 @@ inline bool f$rpc_parse(const string& new_rpc_data) noexcept { return true; } +inline bool f$rpc_parse(const mixed& new_rpc_data) noexcept { + if (!new_rpc_data.is_string()) { + kphp::log::warning("Parameter 1 of function rpc_parse must be a string, {} is given", new_rpc_data.get_type_c_str()); + return false; + } + + return f$rpc_parse(new_rpc_data.to_string()); +} + +inline bool f$rpc_parse(bool new_rpc_data) noexcept { + return f$rpc_parse(mixed{new_rpc_data}); +} + +inline bool f$rpc_parse(const Optional& new_rpc_data) noexcept { + auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; + return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); +} + // f$rpc_server_fetch_request() definition is generated into the tl/rpc_server_fetch_request.cpp file. // It's composed of: // 1. fetching magic diff --git a/runtime/rpc.cpp b/runtime/rpc.cpp index 118f022086..a7ee823e32 100644 --- a/runtime/rpc.cpp +++ b/runtime/rpc.cpp @@ -157,6 +157,24 @@ bool f$rpc_parse(const string& new_rpc_data) noexcept { return true; } +bool f$rpc_parse(const mixed& new_rpc_data) noexcept { + if (!new_rpc_data.is_string()) { + php_warning("Parameter 1 of function rpc_parse must be a string, %s is given", new_rpc_data.get_type_c_str()); + return false; + } + + return f$rpc_parse(new_rpc_data.to_string()); +} + +bool f$rpc_parse(bool new_rpc_data) noexcept { + return f$rpc_parse(mixed{new_rpc_data}); +} + +bool f$rpc_parse(const Optional& new_rpc_data) noexcept { + auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; + return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); +} + int32_t rpc_get_pos() { return static_cast(rpc_data - rpc_data_begin); } diff --git a/runtime/rpc.h b/runtime/rpc.h index fc0f15590d..7fc2032c71 100644 --- a/runtime/rpc.h +++ b/runtime/rpc.h @@ -11,7 +11,6 @@ #include "common/algorithms/hashes.h" #include "common/kprintf.h" #include "runtime-common/core/runtime-core.h" -#include "runtime-common/stdlib/rpc/rpc-parse.h" #include "runtime-common/stdlib/visitors/dummy-visitor-methods.h" #include "runtime/net_events.h" #include "runtime/resumable.h" @@ -66,6 +65,14 @@ void last_rpc_error_reset(); void rpc_parse(const int32_t* new_rpc_data, int32_t new_rpc_data_len); +bool f$rpc_parse(const string& new_rpc_data) noexcept; + +bool f$rpc_parse(const mixed& new_rpc_data) noexcept; + +bool f$rpc_parse(bool new_rpc_data) noexcept; + +bool f$rpc_parse(const Optional& new_rpc_data) noexcept; + int32_t rpc_get_pos(); bool rpc_set_pos(int32_t pos); From 7423bfa3e284c75079ed13ff30bb77fb45795e07 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 14:05:17 +0300 Subject: [PATCH 12/16] change include --- runtime-light/stdlib/diagnostics/exception-functions.h | 2 +- runtime-light/stdlib/serialization/msgpack-functions.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime-light/stdlib/diagnostics/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h index 3779a97d9f..cca0422e86 100644 --- a/runtime-light/stdlib/diagnostics/exception-functions.h +++ b/runtime-light/stdlib/diagnostics/exception-functions.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include "runtime-common/core/runtime-core.h" diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index 1f4501e455..ef62cbac1c 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -4,7 +4,7 @@ #pragma once -#include +#include #include "runtime-common/core/runtime-core.h" #include "runtime-common/stdlib/msgpack/unpacker.h" From 29195aa9c4847a4e02aeaff65ac201b7e2a635fc Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 14:10:13 +0300 Subject: [PATCH 13/16] minifix --- runtime-light/stdlib/diagnostics/exception-functions.h | 2 +- runtime-light/stdlib/rpc/rpc-api.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime-light/stdlib/diagnostics/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h index cca0422e86..5acb20662b 100644 --- a/runtime-light/stdlib/diagnostics/exception-functions.h +++ b/runtime-light/stdlib/diagnostics/exception-functions.h @@ -6,8 +6,8 @@ #include #include -#include #include +#include #include "runtime-common/core/runtime-core.h" #include "runtime-light/stdlib/diagnostics/exception-types.h" diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index eff6479727..4c694df3d3 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -183,7 +183,7 @@ inline bool f$rpc_parse(const string& new_rpc_data) noexcept { inline bool f$rpc_parse(const mixed& new_rpc_data) noexcept { if (!new_rpc_data.is_string()) { - kphp::log::warning("Parameter 1 of function rpc_parse must be a string, {} is given", new_rpc_data.get_type_c_str()); + kphp::log::warning("parameter 1 of function rpc_parse must be a string, {} is given", new_rpc_data.get_type_c_str()); return false; } From 157edc04f1c378e3553df93fcb70e552cec85b57 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 14:19:12 +0300 Subject: [PATCH 14/16] minifix --- runtime-light/stdlib/rpc/rpc-api.h | 2 +- runtime-light/stdlib/serialization/msgpack-functions.h | 1 + runtime/rpc.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime-light/stdlib/rpc/rpc-api.h b/runtime-light/stdlib/rpc/rpc-api.h index 4c694df3d3..f10da91c60 100644 --- a/runtime-light/stdlib/rpc/rpc-api.h +++ b/runtime-light/stdlib/rpc/rpc-api.h @@ -195,7 +195,7 @@ inline bool f$rpc_parse(bool new_rpc_data) noexcept { } inline bool f$rpc_parse(const Optional& new_rpc_data) noexcept { - auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; + constexpr auto rpc_parse_lambda{[](const auto& v) noexcept { return f$rpc_parse(v); }}; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); } diff --git a/runtime-light/stdlib/serialization/msgpack-functions.h b/runtime-light/stdlib/serialization/msgpack-functions.h index ef62cbac1c..472d57d90e 100644 --- a/runtime-light/stdlib/serialization/msgpack-functions.h +++ b/runtime-light/stdlib/serialization/msgpack-functions.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "runtime-common/core/runtime-core.h" diff --git a/runtime/rpc.cpp b/runtime/rpc.cpp index a7ee823e32..ecfaf06853 100644 --- a/runtime/rpc.cpp +++ b/runtime/rpc.cpp @@ -171,7 +171,7 @@ bool f$rpc_parse(bool new_rpc_data) noexcept { } bool f$rpc_parse(const Optional& new_rpc_data) noexcept { - auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; + constexpr auto rpc_parse_lambda = [](const auto& v) noexcept { return f$rpc_parse(v); }; return call_fun_on_optional_value(rpc_parse_lambda, new_rpc_data); } From 03c1fa9fd1cb657520e28e8b0a901b5bdd26e206 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 14:24:26 +0300 Subject: [PATCH 15/16] fixes --- builtin-functions/kphp-light/stdlib/rpc.txt | 1 - builtin-functions/kphp-light/stdlib/serialize-functions.txt | 4 ++-- builtin-functions/kphp-light/stdlib/server-functions.txt | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/builtin-functions/kphp-light/stdlib/rpc.txt b/builtin-functions/kphp-light/stdlib/rpc.txt index 90211d0d7f..f471208846 100644 --- a/builtin-functions/kphp-light/stdlib/rpc.txt +++ b/builtin-functions/kphp-light/stdlib/rpc.txt @@ -121,7 +121,6 @@ function rpc_queue_next ($queue_id ::: int, $timeout ::: float = -1.0) ::: int | /** @kphp-extern-func-info interruptible stub generation-required */ function new_rpc_connection ($str ::: string, $port ::: int, $actor_id ::: mixed = 0, $timeout ::: float = 0.3, $connect_timeout ::: float = 0.3, $reconnect_timeout ::: float = 17.0) ::: \RpcConnection; // TODO: make actor_id int -/** @kphp-extern-func-info stub */ function rpc_parse ($data) ::: bool; /** @kphp-extern-func-info interruptible stub generation-required */ diff --git a/builtin-functions/kphp-light/stdlib/serialize-functions.txt b/builtin-functions/kphp-light/stdlib/serialize-functions.txt index e39aa0acb5..3524df5711 100644 --- a/builtin-functions/kphp-light/stdlib/serialize-functions.txt +++ b/builtin-functions/kphp-light/stdlib/serialize-functions.txt @@ -54,7 +54,7 @@ function msgpack_deserialize($v ::: string) ::: mixed; function msgpack_serialize_safe($v ::: mixed) ::: string; /** @kphp-extern-func-info can_throw stub generation-required */ function msgpack_deserialize_safe($v ::: string) ::: mixed; -/** @kphp-extern-func-info can_throw stub */ +/** @kphp-extern-func-info can_throw */ function instance_serialize_safe(object $instance) ::: string; -/** @kphp-extern-func-info cpp_template_call can_throw stub */ +/** @kphp-extern-func-info cpp_template_call can_throw */ function instance_deserialize_safe($serialized ::: string, $to_type ::: string) ::: instance<^2>; diff --git a/builtin-functions/kphp-light/stdlib/server-functions.txt b/builtin-functions/kphp-light/stdlib/server-functions.txt index 6318fd793b..d929916378 100644 --- a/builtin-functions/kphp-light/stdlib/server-functions.txt +++ b/builtin-functions/kphp-light/stdlib/server-functions.txt @@ -94,7 +94,7 @@ function inet_pton ($address ::: string) ::: string | false; function memory_get_total_usage() ::: int; /** @kphp-extern-func-info stub generation-required */ function memory_get_static_usage() ::: int; -/** @kphp-extern-func-info stub generation-required */ + function memory_get_detailed_stats() ::: int[]; /** @kphp-extern-func-info stub */ @@ -118,7 +118,6 @@ define('LC_NUMERIC', 1); define('LC_TIME', 2); define('LC_MESSAGES', 5); -/** @kphp-extern-func-info stub generation-required */ function setlocale ($category ::: int, $locale ::: string) ::: string | false; function debug_backtrace() ::: string[][]; From 995ac4fa49c9977bf56be4b43d9459edd23a1f1f Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Wed, 12 Nov 2025 14:35:57 +0300 Subject: [PATCH 16/16] minifix --- builtin-functions/kphp-light/stdlib/rpc.txt | 4 ++-- .../kphp-light/stdlib/serialize-functions.txt | 10 ++++++---- .../kphp-light/stdlib/server-functions.txt | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/builtin-functions/kphp-light/stdlib/rpc.txt b/builtin-functions/kphp-light/stdlib/rpc.txt index f471208846..9b64e6035f 100644 --- a/builtin-functions/kphp-light/stdlib/rpc.txt +++ b/builtin-functions/kphp-light/stdlib/rpc.txt @@ -113,6 +113,8 @@ function rpc_queue_push ($queue_id ::: int, $request_id ::: int) ::: void; function rpc_queue_empty ($queue_id ::: int) ::: bool; +function rpc_parse ($data) ::: bool; + /** @kphp-extern-func-info interruptible */ function rpc_queue_next ($queue_id ::: int, $timeout ::: float = -1.0) ::: int | false; @@ -121,8 +123,6 @@ function rpc_queue_next ($queue_id ::: int, $timeout ::: float = -1.0) ::: int | /** @kphp-extern-func-info interruptible stub generation-required */ function new_rpc_connection ($str ::: string, $port ::: int, $actor_id ::: mixed = 0, $timeout ::: float = 0.3, $connect_timeout ::: float = 0.3, $reconnect_timeout ::: float = 17.0) ::: \RpcConnection; // TODO: make actor_id int -function rpc_parse ($data) ::: bool; - /** @kphp-extern-func-info interruptible stub generation-required */ function store_finish() ::: bool; diff --git a/builtin-functions/kphp-light/stdlib/serialize-functions.txt b/builtin-functions/kphp-light/stdlib/serialize-functions.txt index 3524df5711..8e429a964a 100644 --- a/builtin-functions/kphp-light/stdlib/serialize-functions.txt +++ b/builtin-functions/kphp-light/stdlib/serialize-functions.txt @@ -48,13 +48,15 @@ function msgpack_serialize($v ::: mixed) ::: string | null; function msgpack_deserialize($v ::: string) ::: mixed; +/** @kphp-extern-func-info can_throw */ +function instance_serialize_safe(object $instance) ::: string; + +/** @kphp-extern-func-info cpp_template_call can_throw */ +function instance_deserialize_safe($serialized ::: string, $to_type ::: string) ::: instance<^2>; + // ===== UNSUPPORTED ===== /** @kphp-extern-func-info can_throw stub generation-required */ function msgpack_serialize_safe($v ::: mixed) ::: string; /** @kphp-extern-func-info can_throw stub generation-required */ function msgpack_deserialize_safe($v ::: string) ::: mixed; -/** @kphp-extern-func-info can_throw */ -function instance_serialize_safe(object $instance) ::: string; -/** @kphp-extern-func-info cpp_template_call can_throw */ -function instance_deserialize_safe($serialized ::: string, $to_type ::: string) ::: instance<^2>; diff --git a/builtin-functions/kphp-light/stdlib/server-functions.txt b/builtin-functions/kphp-light/stdlib/server-functions.txt index d929916378..5a62421a11 100644 --- a/builtin-functions/kphp-light/stdlib/server-functions.txt +++ b/builtin-functions/kphp-light/stdlib/server-functions.txt @@ -65,6 +65,10 @@ function memory_get_usage ($real_usage ::: bool = false) ::: int; function memory_get_peak_usage ($real_usage ::: bool = false) ::: int; +function setlocale ($category ::: int, $locale ::: string) ::: string | false; + +function memory_get_detailed_stats() ::: int[]; + // ===== UNSUPPORTED ===== /** @kphp-extern-func-info stub */ @@ -95,8 +99,6 @@ function memory_get_total_usage() ::: int; /** @kphp-extern-func-info stub generation-required */ function memory_get_static_usage() ::: int; -function memory_get_detailed_stats() ::: int[]; - /** @kphp-extern-func-info stub */ function kphp_extended_instance_cache_metrics_init(callable(string $key):string $normalization_function) ::: void; @@ -118,8 +120,6 @@ define('LC_NUMERIC', 1); define('LC_TIME', 2); define('LC_MESSAGES', 5); -function setlocale ($category ::: int, $locale ::: string) ::: string | false; - function debug_backtrace() ::: string[][]; /** @kphp-extern-func-info stub generation-required */