Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime-light/stdlib/rpc/rpc-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline bool f$store_byte(int64_t v) noexcept {
}

inline bool f$store_int(int64_t v) noexcept {
if (!std::in_range<int32_t>(v)) [[unlikely]] {
if (tl::is_int32_overflow(v)) [[unlikely]] {
kphp::log::warning("integer {} overflows int32, it will be cast to {}", v, static_cast<int32_t>(v));
}
tl::i32{.value = static_cast<int32_t>(v)}.store(RpcServerInstanceState::get().tl_storer);
Expand Down Expand Up @@ -243,7 +243,7 @@ inline bool f$rpc_parse(const Optional<string>& new_rpc_data) noexcept {
class_instance<C$VK$TL$RpcFunction> f$rpc_server_fetch_request() noexcept;

inline kphp::coro::task<bool> f$store_error(int64_t error_code, string error_msg) noexcept {
if (!std::in_range<int32_t>(error_code)) [[unlikely]] {
if (tl::is_int32_overflow(error_code)) [[unlikely]] {
kphp::log::warning("error_code overflows int32, {} will be stored", static_cast<int32_t>(error_code));
}

Expand Down
6 changes: 2 additions & 4 deletions runtime-light/stdlib/rpc/rpc-tl-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

#include "runtime-light/stdlib/rpc/rpc-tl-builtins.h"

#include <cstdint>
#include <utility>

#include "runtime-light/server/rpc/rpc-server-state.h"
#include "runtime-light/stdlib/diagnostics/logs.h"
#include "runtime-light/tl/tl-core.h"

mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64_t precomputed_hash) noexcept {
auto& cur_query{CurrentTlQuery::get()};
Expand All @@ -30,7 +28,7 @@ mixed tl_arr_get(const mixed& arr, const string& str_key, int64_t num_key, int64

int32_t t_Int::prepare_int_for_storing(int64_t v) noexcept {
auto v32{static_cast<int32_t>(v)};
if (!std::in_range<int32_t>(v)) [[unlikely]] {
if (tl::is_int32_overflow(v)) [[unlikely]] {
if (RpcServerInstanceState::get().fail_rpc_on_int32_overflow) {
CurrentTlQuery::get().raise_storing_error("Got int32 overflow with value '%" PRIi64 "'. Serialization will fail.", v);
} else {
Expand Down
6 changes: 6 additions & 0 deletions runtime-light/tl/tl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
#include <span>
#include <utility>

#include "common/algorithms/find.h"
#include "runtime-common/core/allocator/script-allocator.h"
#include "runtime-common/core/std/containers.h"
#include "runtime-light/metaprogramming/concepts.h"
#include "runtime-light/stdlib/diagnostics/logs.h"

namespace tl {

inline bool is_int32_overflow(int64_t v) noexcept {
const auto v32{static_cast<int32_t>(v)};
return vk::none_of_equal(v, int64_t{v32}, int64_t{static_cast<uint32_t>(v32)});
}

class storer {
static constexpr auto DEFAULT_BUFFER_CAPACITY = 1024;

Expand Down
Loading