aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-08-14 18:21:51 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-08-14 18:21:51 +0000
commitc2662559a47e8bf435eb86b34ef7444f97c7e7dc (patch)
treef996622988c830acfb06786322de309fa4da7f87 /library/cpp
parent207f84602fdcce806fc2b6f972cd4e7e7968a882 (diff)
parent0cde7699c40c90a05b1545e8f58abeb41cc4718e (diff)
downloadydb-c2662559a47e8bf435eb86b34ef7444f97c7e7dc.tar.gz
Merge branch 'rightlib' into mergelibs-240814-1820
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/cgiparam/cgiparam.cpp4
-rw-r--r--library/cpp/neh/http2.cpp2
-rw-r--r--library/cpp/tld/tlds-alpha-by-domain.txt2
-rw-r--r--library/cpp/yson/node/node.h1
-rw-r--r--library/cpp/yson/node/node_visitor.cpp1
-rw-r--r--library/cpp/yt/logging/logger-inl.h8
-rw-r--r--library/cpp/yt/memory/ref-inl.h5
-rw-r--r--library/cpp/yt/memory/ref.h5
-rw-r--r--library/cpp/yt/misc/cast-inl.h4
-rw-r--r--library/cpp/yt/misc/enum.h14
-rw-r--r--library/cpp/yt/string/enum-inl.h5
-rw-r--r--library/cpp/yt/string/format_analyser-inl.h112
-rw-r--r--library/cpp/yt/string/format_analyser.h133
-rw-r--r--library/cpp/yt/string/format_string.h7
-rw-r--r--library/cpp/yt/threading/notification_handle.cpp6
-rw-r--r--library/cpp/yt/threading/ya.make1
16 files changed, 171 insertions, 139 deletions
diff --git a/library/cpp/cgiparam/cgiparam.cpp b/library/cpp/cgiparam/cgiparam.cpp
index ddc24c1f95b..c2fb6e32aa5 100644
--- a/library/cpp/cgiparam/cgiparam.cpp
+++ b/library/cpp/cgiparam/cgiparam.cpp
@@ -159,7 +159,7 @@ void TCgiParameters::ScanAddAll(const TStringBuf query) {
TString TCgiParameters::Print() const {
TString res;
- res.reserve(PrintSize());
+ res.ReserveAndResize(PrintSize());
const char* end = Print(res.begin());
res.ReserveAndResize(end - res.data());
@@ -246,7 +246,7 @@ bool TCgiParameters::Has(const TStringBuf name, const TStringBuf value) const no
}
TQuickCgiParam::TQuickCgiParam(const TStringBuf cgiParamStr) {
- UnescapeBuf.reserve(CgiUnescapeBufLen(cgiParamStr.size()));
+ UnescapeBuf.ReserveAndResize(CgiUnescapeBufLen(cgiParamStr.size()));
char* buf = UnescapeBuf.begin();
auto f = [this, &buf](const TStringBuf key, const TStringBuf val) {
diff --git a/library/cpp/neh/http2.cpp b/library/cpp/neh/http2.cpp
index 766a344013b..f10fdc3b3e3 100644
--- a/library/cpp/neh/http2.cpp
+++ b/library/cpp/neh/http2.cpp
@@ -1230,7 +1230,7 @@ namespace {
void THttpRequest::OnResponse(TAutoPtr<THttpParser>& rsp) {
DBGOUT("THttpRequest::OnResponse()");
ReleaseConn();
- if (Y_LIKELY(((rsp->RetCode() >= 200 && rsp->RetCode() < (!THttp2Options::RedirectionNotError ? 300 : 400)) || THttp2Options::AnyResponseIsNotError))) {
+ if (Y_LIKELY(((rsp->RetCode() >= 200u && rsp->RetCode() < (!THttp2Options::RedirectionNotError ? 300u : 400u)) || THttp2Options::AnyResponseIsNotError))) {
NotifyResponse(rsp->DecodedContent(), rsp->FirstLine(), rsp->Headers());
} else {
TString message;
diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt
index b57e79a3a70..32b383b4ba2 100644
--- a/library/cpp/tld/tlds-alpha-by-domain.txt
+++ b/library/cpp/tld/tlds-alpha-by-domain.txt
@@ -1,4 +1,4 @@
-# Version 2024080400, Last Updated Sun Aug 4 07:07:01 2024 UTC
+# Version 2024080700, Last Updated Wed Aug 7 07:07:01 2024 UTC
AAA
AARP
ABB
diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h
index 05459ed4724..68c50deadd5 100644
--- a/library/cpp/yson/node/node.h
+++ b/library/cpp/yson/node/node.h
@@ -3,7 +3,6 @@
#include <util/generic/bt_exception.h>
#include <util/generic/cast.h>
#include <util/generic/hash.h>
-#include <util/generic/variant.h>
#include <util/generic/vector.h>
#include <util/generic/yexception.h>
#include <util/generic/ylimits.h>
diff --git a/library/cpp/yson/node/node_visitor.cpp b/library/cpp/yson/node/node_visitor.cpp
index 258afc21eaf..d697f54a088 100644
--- a/library/cpp/yson/node/node_visitor.cpp
+++ b/library/cpp/yson/node/node_visitor.cpp
@@ -1,7 +1,6 @@
#include "node_visitor.h"
#include <util/generic/algorithm.h>
-#include <util/string/printf.h>
namespace NYT {
diff --git a/library/cpp/yt/logging/logger-inl.h b/library/cpp/yt/logging/logger-inl.h
index 5c1f1b0b556..f3993a4c48a 100644
--- a/library/cpp/yt/logging/logger-inl.h
+++ b/library/cpp/yt/logging/logger-inl.h
@@ -181,12 +181,6 @@ struct TLogMessage
TStringBuf Anchor;
};
-template <class T>
-concept CLiteralLogFormat =
- requires (T& t) {
- [] (const char*) { } (t);
- };
-
template <class... TArgs>
TLogMessage BuildLogMessage(
const TLoggingContext& loggingContext,
@@ -200,7 +194,7 @@ TLogMessage BuildLogMessage(
}
template <CFormattable T>
- requires (!CLiteralLogFormat<std::remove_cvref_t<T>>)
+ requires (!CStringLiteral<std::remove_cvref_t<T>>)
TLogMessage BuildLogMessage(
const TLoggingContext& loggingContext,
const TLogger& logger,
diff --git a/library/cpp/yt/memory/ref-inl.h b/library/cpp/yt/memory/ref-inl.h
index c5756963823..7fcd91908cf 100644
--- a/library/cpp/yt/memory/ref-inl.h
+++ b/library/cpp/yt/memory/ref-inl.h
@@ -96,6 +96,11 @@ Y_FORCE_INLINE TMutableRef TMutableRef::FromString(TString& str)
return TMutableRef(str.begin(), str.length());
}
+Y_FORCE_INLINE TMutableRef TMutableRef::FromString(std::string& str)
+{
+ return TMutableRef(str.data(), str.length());
+}
+
Y_FORCE_INLINE TMutableRef TMutableRef::Slice(size_t startOffset, size_t endOffset) const
{
YT_ASSERT(endOffset >= startOffset && endOffset <= Size());
diff --git a/library/cpp/yt/memory/ref.h b/library/cpp/yt/memory/ref.h
index 2dfe861e759..78ea46675fc 100644
--- a/library/cpp/yt/memory/ref.h
+++ b/library/cpp/yt/memory/ref.h
@@ -90,10 +90,13 @@ public:
template <class T>
static TMutableRef FromPod(T& data);
- //! Creates a non-owning TMutableRef for a given string.
+ //! Creates a non-owning TMutableRef for a given TString.
//! Ensures that the string is not shared.
static TMutableRef FromString(TString& str);
+ //! Creates a non-owning TMutableRef for a given std::string.
+ static TMutableRef FromString(std::string& str);
+
//! Creates a TMutableRef for a part of existing range.
TMutableRef Slice(size_t startOffset, size_t endOffset) const;
};
diff --git a/library/cpp/yt/misc/cast-inl.h b/library/cpp/yt/misc/cast-inl.h
index a694394f88d..795682864fc 100644
--- a/library/cpp/yt/misc/cast-inl.h
+++ b/library/cpp/yt/misc/cast-inl.h
@@ -124,6 +124,10 @@ T CheckedEnumCast(S value)
{
T result;
if (!TryEnumCast<T>(value, &result)) {
+ if constexpr (TEnumHasDefaultValue<T>::value) {
+ return GetDefaultValue(T{});
+ }
+
throw TSimpleException(Sprintf("Error casting %s value \"%d\" to enum %s",
TypeName<S>().c_str(),
static_cast<int>(value),
diff --git a/library/cpp/yt/misc/enum.h b/library/cpp/yt/misc/enum.h
index 954b63cbc03..11e168948f4 100644
--- a/library/cpp/yt/misc/enum.h
+++ b/library/cpp/yt/misc/enum.h
@@ -197,6 +197,20 @@ constexpr bool None(E value) noexcept;
////////////////////////////////////////////////////////////////////////////////
+template <typename E, typename = void>
+ requires TEnumTraits<E>::IsEnum
+struct TEnumHasDefaultValue
+ : std::false_type
+{ };
+
+template <typename E>
+ requires TEnumTraits<E>::IsEnum
+struct TEnumHasDefaultValue<E, std::void_t<decltype(GetDefaultValue(std::declval<E>()))>>
+ : std::is_same<decltype(GetDefaultValue(std::declval<E>())), E>
+{ };
+
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
#define ENUM_INL_H_
diff --git a/library/cpp/yt/string/enum-inl.h b/library/cpp/yt/string/enum-inl.h
index 41f7197d156..19ba1f7fe54 100644
--- a/library/cpp/yt/string/enum-inl.h
+++ b/library/cpp/yt/string/enum-inl.h
@@ -87,6 +87,11 @@ T ParseEnum(TStringBuf value)
if (auto optionalResult = TryParseEnum<T>(value)) {
return *optionalResult;
}
+
+ if constexpr (TEnumHasDefaultValue<T>::value) {
+ return GetDefaultValue(T{});
+ }
+
NYT::NDetail::ThrowMalformedEnumValueException(TEnumTraits<T>::GetTypeName(), value);
}
diff --git a/library/cpp/yt/string/format_analyser-inl.h b/library/cpp/yt/string/format_analyser-inl.h
deleted file mode 100644
index 8a3dd897ffc..00000000000
--- a/library/cpp/yt/string/format_analyser-inl.h
+++ /dev/null
@@ -1,112 +0,0 @@
-#ifndef FORMAT_ANALYSER_INL_H_
-#error "Direct inclusion of this file is not allowed, include format_analyser.h"
-// For the sake of sane code completion.
-#include "format_analyser.h"
-#endif
-
-#include "format_arg.h"
-
-namespace NYT::NDetail {
-
-////////////////////////////////////////////////////////////////////////////////
-
-consteval bool Contains(std::string_view sv, char symbol)
-{
- return sv.find(symbol) != std::string_view::npos;
-}
-
-template <class... TArgs>
-consteval void TFormatAnalyser::ValidateFormat(std::string_view format)
-{
- std::array<std::string_view, sizeof...(TArgs)> markers = {};
- std::array<TSpecifiers, sizeof...(TArgs)> specifiers{GetSpecifiers<TArgs>()...};
-
- int markerCount = 0;
- int currentMarkerStart = -1;
-
- for (int index = 0; index < std::ssize(format); ++index) {
- auto symbol = format[index];
-
- // Parse verbatim text.
- if (currentMarkerStart == -1) {
- if (symbol == IntroductorySymbol) {
- // Marker maybe begins.
- currentMarkerStart = index;
- }
- continue;
- }
-
- // NB: We check for %% first since
- // in order to verify if symbol is a specifier
- // we need markerCount to be within range of our
- // specifier array.
- if (symbol == IntroductorySymbol) {
- if (currentMarkerStart + 1 != index) {
- // '%a% detected'
- CrashCompilerWrongTermination("You may not terminate flag sequence other than %% with \'%\' symbol");
- return;
- }
- // '%%' detected --- skip
- currentMarkerStart = -1;
- continue;
- }
-
- // We are inside of marker.
- if (markerCount == std::ssize(markers)) {
- // To many markers
- CrashCompilerNotEnoughArguments("Number of arguments supplied to format is smaller than the number of flag sequences");
- return;
- }
-
- if (Contains(specifiers[markerCount].Conversion, symbol)) {
- // Marker has finished.
-
- markers[markerCount]
- = std::string_view(format.begin() + currentMarkerStart, index - currentMarkerStart + 1);
- currentMarkerStart = -1;
- ++markerCount;
-
- continue;
- }
-
- if (!Contains(specifiers[markerCount].Flags, symbol)) {
- CrashCompilerWrongFlagSpecifier("Symbol is not a valid flag specifier; See FlagSpecifiers");
- }
- }
-
- if (currentMarkerStart != -1) {
- // Runaway marker.
- CrashCompilerMissingTermination("Unterminated flag sequence detected; Use \'%%\' to type plain %");
- return;
- }
-
- if (markerCount < std::ssize(markers)) {
- // Missing markers.
- CrashCompilerTooManyArguments("Number of arguments supplied to format is greater than the number of flag sequences");
- return;
- }
-
- // TODO(arkady-e1ppa): Consider per-type verification
- // of markers.
-}
-
-template <class TArg>
-consteval auto TFormatAnalyser::GetSpecifiers()
-{
- if constexpr (!CFormattable<TArg>) {
- CrashCompilerNotFormattable<TArg>("Your specialization of TFormatArg is broken");
- }
-
- return TSpecifiers{
- .Conversion = std::string_view{
- std::data(TFormatArg<TArg>::ConversionSpecifiers),
- std::size(TFormatArg<TArg>::ConversionSpecifiers)},
- .Flags = std::string_view{
- std::data(TFormatArg<TArg>::FlagSpecifiers),
- std::size(TFormatArg<TArg>::FlagSpecifiers)},
- };
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT::NDetail
diff --git a/library/cpp/yt/string/format_analyser.h b/library/cpp/yt/string/format_analyser.h
index 3dd1ba4cd38..e8287ea8f38 100644
--- a/library/cpp/yt/string/format_analyser.h
+++ b/library/cpp/yt/string/format_analyser.h
@@ -1,5 +1,7 @@
#pragma once
+#include "format_arg.h"
+
#include <util/generic/strbuf.h>
#include <array>
@@ -12,36 +14,143 @@ namespace NYT::NDetail {
struct TFormatAnalyser
{
public:
+ // TODO(arkady-e1ppa): Until clang-19 consteval functions
+ // defined out of line produce symbols in rare cases
+ // causing linker to crash.
template <class... TArgs>
- static consteval void ValidateFormat(std::string_view fmt);
+ static consteval void ValidateFormat(std::string_view fmt)
+ {
+ DoValidateFormat<TArgs...>(fmt);
+ }
-public:
+private:
// Non-constexpr function call will terminate compilation.
// Purposefully undefined and non-constexpr/consteval
template <class T>
static void CrashCompilerNotFormattable(std::string_view /*msg*/)
{ /*Suppress "internal linkage but undefined" warning*/ }
- static void CrashCompilerNotEnoughArguments(std::string_view msg);
- static void CrashCompilerTooManyArguments(std::string_view msg);
- static void CrashCompilerWrongTermination(std::string_view msg);
- static void CrashCompilerMissingTermination(std::string_view msg);
- static void CrashCompilerWrongFlagSpecifier(std::string_view msg);
+ static void CrashCompilerNotEnoughArguments(std::string_view /*msg*/)
+ { }
+
+ static void CrashCompilerTooManyArguments(std::string_view /*msg*/)
+ { }
+
+ static void CrashCompilerWrongTermination(std::string_view /*msg*/)
+ { }
+
+ static void CrashCompilerMissingTermination(std::string_view /*msg*/)
+ { }
+
+ static void CrashCompilerWrongFlagSpecifier(std::string_view /*msg*/)
+ { }
+
+
+ static consteval bool Contains(std::string_view sv, char symbol)
+ {
+ return sv.find(symbol) != std::string_view::npos;
+ }
struct TSpecifiers
{
std::string_view Conversion;
std::string_view Flags;
};
+
template <class TArg>
- static consteval auto GetSpecifiers();
+ static consteval auto GetSpecifiers()
+ {
+ if constexpr (!CFormattable<TArg>) {
+ CrashCompilerNotFormattable<TArg>("Your specialization of TFormatArg is broken");
+ }
+
+ return TSpecifiers{
+ .Conversion = std::string_view{
+ std::data(TFormatArg<TArg>::ConversionSpecifiers),
+ std::size(TFormatArg<TArg>::ConversionSpecifiers)},
+ .Flags = std::string_view{
+ std::data(TFormatArg<TArg>::FlagSpecifiers),
+ std::size(TFormatArg<TArg>::FlagSpecifiers)},
+ };
+ }
static constexpr char IntroductorySymbol = '%';
+
+ template <class... TArgs>
+ static consteval void DoValidateFormat(std::string_view format)
+ {
+ std::array<std::string_view, sizeof...(TArgs)> markers = {};
+ std::array<TSpecifiers, sizeof...(TArgs)> specifiers{GetSpecifiers<TArgs>()...};
+
+ int markerCount = 0;
+ int currentMarkerStart = -1;
+
+ for (int index = 0; index < std::ssize(format); ++index) {
+ auto symbol = format[index];
+
+ // Parse verbatim text.
+ if (currentMarkerStart == -1) {
+ if (symbol == IntroductorySymbol) {
+ // Marker maybe begins.
+ currentMarkerStart = index;
+ }
+ continue;
+ }
+
+ // NB: We check for %% first since
+ // in order to verify if symbol is a specifier
+ // we need markerCount to be within range of our
+ // specifier array.
+ if (symbol == IntroductorySymbol) {
+ if (currentMarkerStart + 1 != index) {
+ // '%a% detected'
+ CrashCompilerWrongTermination("You may not terminate flag sequence other than %% with \'%\' symbol");
+ return;
+ }
+ // '%%' detected --- skip
+ currentMarkerStart = -1;
+ continue;
+ }
+
+ // We are inside of marker.
+ if (markerCount == std::ssize(markers)) {
+ // To many markers
+ CrashCompilerNotEnoughArguments("Number of arguments supplied to format is smaller than the number of flag sequences");
+ return;
+ }
+
+ if (Contains(specifiers[markerCount].Conversion, symbol)) {
+ // Marker has finished.
+
+ markers[markerCount]
+ = std::string_view(format.begin() + currentMarkerStart, index - currentMarkerStart + 1);
+ currentMarkerStart = -1;
+ ++markerCount;
+
+ continue;
+ }
+
+ if (!Contains(specifiers[markerCount].Flags, symbol)) {
+ CrashCompilerWrongFlagSpecifier("Symbol is not a valid flag specifier; See FlagSpecifiers");
+ }
+ }
+
+ if (currentMarkerStart != -1) {
+ // Runaway marker.
+ CrashCompilerMissingTermination("Unterminated flag sequence detected; Use \'%%\' to type plain %");
+ return;
+ }
+
+ if (markerCount < std::ssize(markers)) {
+ // Missing markers.
+ CrashCompilerTooManyArguments("Number of arguments supplied to format is greater than the number of flag sequences");
+ return;
+ }
+
+ // TODO(arkady-e1ppa): Consider per-type verification
+ // of markers.
+ }
};
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT::NDetail
-
-#define FORMAT_ANALYSER_INL_H_
-#include "format_analyser-inl.h"
-#undef FORMAT_ANALYSER_INL_H_
diff --git a/library/cpp/yt/string/format_string.h b/library/cpp/yt/string/format_string.h
index ebef9d70422..786c2e39ed5 100644
--- a/library/cpp/yt/string/format_string.h
+++ b/library/cpp/yt/string/format_string.h
@@ -56,6 +56,13 @@ using TFormatString = TBasicFormatString<std::type_identity_t<TArgs>...>;
////////////////////////////////////////////////////////////////////////////////
+template <class T>
+concept CStringLiteral = requires (T& t) {
+ [] (const char*) { } (t);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
} // namespace NYT
#define FORMAT_STRING_INL_H_
diff --git a/library/cpp/yt/threading/notification_handle.cpp b/library/cpp/yt/threading/notification_handle.cpp
index 0896d8169b3..fea720670ed 100644
--- a/library/cpp/yt/threading/notification_handle.cpp
+++ b/library/cpp/yt/threading/notification_handle.cpp
@@ -1,5 +1,7 @@
#include "notification_handle.h"
+#include <library/cpp/yt/exception/exception.h>
+
#include <library/cpp/yt/system/handle_eintr.h>
#include <library/cpp/yt/assert/assert.h>
@@ -29,7 +31,9 @@ TNotificationHandle::TNotificationHandle(bool blocking)
eventfd,
0,
EFD_CLOEXEC | (blocking ? 0 : EFD_NONBLOCK));
- YT_VERIFY(EventFD_ >= 0);
+ if (EventFD_ < 0) {
+ throw TSimpleException("Error creating notification handle");
+ }
#elif defined(_win_)
TPipeHandle::Pipe(Reader_, Writer_, EOpenModeFlag::CloseOnExec);
if (!blocking) {
diff --git a/library/cpp/yt/threading/ya.make b/library/cpp/yt/threading/ya.make
index 3b2cb13d4fa..cc11e7974ef 100644
--- a/library/cpp/yt/threading/ya.make
+++ b/library/cpp/yt/threading/ya.make
@@ -23,6 +23,7 @@ SRCS(
PEERDIR(
library/cpp/yt/assert
library/cpp/yt/cpu_clock
+ library/cpp/yt/exception
library/cpp/yt/system
library/cpp/yt/memory
)