From 1acde5fa1f37b8e4856f96aba092a38faaac737f Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 18 Jul 2024 14:18:39 +0200 Subject: just: Fix operation cache threshold exponent maximum value The threshold exponent cannot pass the log2 of the maximum internal map size, of type size_t, thus it cannot be larger than 63. Update the documentation and enforce the upper limit of this argument during parsing of the command line. --- src/buildtool/common/cli.hpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/buildtool/common/cli.hpp') diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index 57567cf7..d136756d 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,8 @@ #include "src/buildtool/main/build_utils.hpp" #include "src/utils/cpp/path.hpp" -constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000}; +inline constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000}; +inline constexpr auto kMaxOpCacheExponent = std::uint8_t{63}; /// \brief Arguments common to all commands. struct CommonArguments { @@ -171,7 +173,7 @@ struct ServiceArguments { std::optional info_file{std::nullopt}; std::optional interface{std::nullopt}; std::optional pid_file{std::nullopt}; - std::optional op_exponent; + std::optional op_exponent; }; struct ServeArguments { @@ -742,13 +744,23 @@ static inline auto SetupServiceArguments( "Write pid to this file in plain txt. If the file exists, it " "will be overwritten."); - app->add_option( + app->add_option_function( "--log-operations-threshold", - service_args->op_exponent, + [service_args](auto const& op_exponent) { + if (op_exponent > kMaxOpCacheExponent) { + Logger::Log(LogLevel::Warning, + "Ignoring invalid value {} for operations " + "threshold exponent.", + op_exponent); + } + else { + service_args->op_exponent = op_exponent; + } + }, "Once the number of operations stored exceeds twice 2^n, where n is " "given by the option --log-operations-threshold, at most 2^n " "operations will be removed, in a FIFO scheme. If unset, defaults to " - "14. Must be in the range [0,255]"); + "14. Must be in the range [0,63]"); } static inline auto SetupServeArguments( -- cgit v1.2.3