diff options
author | babenko <babenko@yandex-team.com> | 2024-07-02 08:07:30 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-07-02 08:18:46 +0300 |
commit | 318b857015da326b953274ecd06f29565f6f53ae (patch) | |
tree | 7867e72618dd673a1b074fcb39c5874073d361c9 | |
parent | bc3f0aedccfabb25a5bf14f023401837907a12a7 (diff) | |
download | ydb-318b857015da326b953274ecd06f29565f6f53ae.tar.gz |
YT-18571: Polish TSourceLocation
81b1c42ea62adf4f2a7e2e7ba3601ca9687e29ed
-rw-r--r-- | library/cpp/yt/misc/source_location-inl.h | 25 | ||||
-rw-r--r-- | library/cpp/yt/misc/source_location.cpp | 7 | ||||
-rw-r--r-- | library/cpp/yt/misc/source_location.h | 33 | ||||
-rw-r--r-- | yt/yt/client/table_client/comparator.cpp | 2 | ||||
-rw-r--r-- | yt/yt/core/actions/bind.h | 2 | ||||
-rw-r--r-- | yt/yt/core/concurrency/propagating_storage.h | 4 | ||||
-rw-r--r-- | yt/yt/core/misc/unittests/callback_ut.cpp | 4 | ||||
-rw-r--r-- | yt/yt/core/tracing/trace_context-inl.h | 4 | ||||
-rw-r--r-- | yt/yt/core/tracing/trace_context.h | 4 |
9 files changed, 48 insertions, 37 deletions
diff --git a/library/cpp/yt/misc/source_location-inl.h b/library/cpp/yt/misc/source_location-inl.h new file mode 100644 index 0000000000..9948260874 --- /dev/null +++ b/library/cpp/yt/misc/source_location-inl.h @@ -0,0 +1,25 @@ +#ifndef SOURCE_LOCATION_INL_H_ +#error "Direct inclusion of this file is not allowed, include source_location.h" +// For the sake of sane code completion. +#include "source_location.h" +#endif + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +inline TSourceLocation::TSourceLocation(const char* fileName, int line) + : FileName_(fileName) + , Line_(line) +{ } + +#ifdef __cpp_lib_source_location +inline TSourceLocation::TSourceLocation(const std::source_location& location) + : FileName_(location.file_name()) + , Line_(location.line()) +{ } +#endif // __cpp_lib_source_location + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace std diff --git a/library/cpp/yt/misc/source_location.cpp b/library/cpp/yt/misc/source_location.cpp index f3f396ee90..598126f5a7 100644 --- a/library/cpp/yt/misc/source_location.cpp +++ b/library/cpp/yt/misc/source_location.cpp @@ -70,13 +70,6 @@ bool TSourceLocation::operator==(const TSourceLocation& other) const Line_ == other.Line_; } -#ifdef __cpp_lib_source_location -TSourceLocation TSourceLocation::FromStd(const std::source_location& location) -{ - return TSourceLocation(location.file_name(), location.line()); -} -#endif // __cpp_lib_source_location - void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf /*spec*/) { if (location.GetFileName() != nullptr) { diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h index 0496a4e496..286527887a 100644 --- a/library/cpp/yt/misc/source_location.h +++ b/library/cpp/yt/misc/source_location.h @@ -14,9 +14,7 @@ class TStringBuilderBase; // TODO(dgolear): Drop when LLVM-14 is eradicated. #ifdef __cpp_lib_source_location - void FormatValue(TStringBuilderBase* builder, const std::source_location& location, TStringBuf /*spec*/); - #endif // __cpp_lib_source_location //////////////////////////////////////////////////////////////////////////////// @@ -24,15 +22,11 @@ void FormatValue(TStringBuilderBase* builder, const std::source_location& locati class TSourceLocation { public: - TSourceLocation() - : FileName_(nullptr) - , Line_(-1) - { } - - TSourceLocation(const char* fileName, int line) - : FileName_(fileName) - , Line_(line) - { } + TSourceLocation() = default; + TSourceLocation(const char* fileName, int line); +#ifdef __cpp_lib_source_location + explicit TSourceLocation(const std::source_location& location); +#endif // __cpp_lib_source_location const char* GetFileName() const; int GetLine() const; @@ -41,21 +35,16 @@ public: bool operator<(const TSourceLocation& other) const; bool operator==(const TSourceLocation& other) const; -#ifdef __cpp_lib_source_location - static TSourceLocation FromStd(const std::source_location& location); -#endif // __cpp_lib_source_location - private: - const char* FileName_; - int Line_; - + const char* FileName_ = nullptr; + int Line_ = -1; }; //! Defines a macro to record the current source location. #ifdef __cpp_lib_source_location -#define FROM_HERE ::NYT::TSourceLocation::FromStd(std::source_location::current()) +#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(std::source_location::current()) #else -#define FROM_HERE ::NYT::TSourceLocation(__FILE__, __LINE__) +#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(__FILE__, __LINE__) #endif // __cpp_lib_source_location void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, TStringBuf spec); @@ -63,3 +52,7 @@ void FormatValue(TStringBuilderBase* builder, const TSourceLocation& location, T //////////////////////////////////////////////////////////////////////////////// } // namespace NYT + +#define SOURCE_LOCATION_INL_H_ +#include "source_location-inl.h" +#undef SOURCE_LOCATION_INL_H_ diff --git a/yt/yt/client/table_client/comparator.cpp b/yt/yt/client/table_client/comparator.cpp index bd0d980d87..a6037004f3 100644 --- a/yt/yt/client/table_client/comparator.cpp +++ b/yt/yt/client/table_client/comparator.cpp @@ -383,7 +383,7 @@ TKeyComparer::TKeyComparer() : TBase( New<TCaller>( #ifdef YT_ENABLE_BIND_LOCATION_TRACKING - FROM_HERE, + YT_CURRENT_SOURCE_LOCATION, #endif nullptr, &ComparePrefix), diff --git a/yt/yt/core/actions/bind.h b/yt/yt/core/actions/bind.h index d86078578c..e1ad03b824 100644 --- a/yt/yt/core/actions/bind.h +++ b/yt/yt/core/actions/bind.h @@ -227,7 +227,7 @@ auto Bind( //////////////////////////////////////////////////////////////////////////////// #ifdef YT_ENABLE_BIND_LOCATION_TRACKING - #define BIND_IMPL(propagate, ...) ::NYT::Bind<propagate, ::NYT::TCurrentTranslationUnitTag, __COUNTER__>(FROM_HERE, __VA_ARGS__) + #define BIND_IMPL(propagate, ...) ::NYT::Bind<propagate, ::NYT::TCurrentTranslationUnitTag, __COUNTER__>(YT_CURRENT_SOURCE_LOCATION, __VA_ARGS__) #else #define BIND_IMPL(propagate, ...) ::NYT::Bind<propagate>(__VA_ARGS__) #endif diff --git a/yt/yt/core/concurrency/propagating_storage.h b/yt/yt/core/concurrency/propagating_storage.h index aa41381571..4d8fd78e83 100644 --- a/yt/yt/core/concurrency/propagating_storage.h +++ b/yt/yt/core/concurrency/propagating_storage.h @@ -107,7 +107,7 @@ class TPropagatingStorageGuard { public: explicit TPropagatingStorageGuard( - TPropagatingStorage storage, TSourceLocation loc = FROM_HERE); + TPropagatingStorage storage, TSourceLocation loc = YT_CURRENT_SOURCE_LOCATION); ~TPropagatingStorageGuard(); TPropagatingStorageGuard(const TPropagatingStorageGuard& other) = delete; @@ -128,7 +128,7 @@ class TNullPropagatingStorageGuard : public TPropagatingStorageGuard { public: - TNullPropagatingStorageGuard(TSourceLocation loc = FROM_HERE); + TNullPropagatingStorageGuard(TSourceLocation loc = YT_CURRENT_SOURCE_LOCATION); }; //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/misc/unittests/callback_ut.cpp b/yt/yt/core/misc/unittests/callback_ut.cpp index 903b582872..91eaef61c9 100644 --- a/yt/yt/core/misc/unittests/callback_ut.cpp +++ b/yt/yt/core/misc/unittests/callback_ut.cpp @@ -42,7 +42,7 @@ public: TBindState() : TBindStateBase( #ifdef YT_ENABLE_BIND_LOCATION_TRACKING - FROM_HERE + YT_CURRENT_SOURCE_LOCATION #endif ) { } @@ -56,7 +56,7 @@ struct TBindState<true, void(), void(), void(TFakeInvoker, TFakeInvoker)> TBindState() : TBindStateBase( #ifdef YT_ENABLE_BIND_LOCATION_TRACKING - FROM_HERE + YT_CURRENT_SOURCE_LOCATION #endif ) { } diff --git a/yt/yt/core/tracing/trace_context-inl.h b/yt/yt/core/tracing/trace_context-inl.h index 6994110d41..429ba545fc 100644 --- a/yt/yt/core/tracing/trace_context-inl.h +++ b/yt/yt/core/tracing/trace_context-inl.h @@ -217,7 +217,7 @@ Y_FORCE_INLINE bool TCurrentTraceContextGuard::IsActive() const Y_FORCE_INLINE void TCurrentTraceContextGuard::Release() { if (Active_) { - NDetail::SwapTraceContext(std::move(OldTraceContext_), FROM_HERE); + NDetail::SwapTraceContext(std::move(OldTraceContext_), YT_CURRENT_SOURCE_LOCATION); Active_ = false; } } @@ -254,7 +254,7 @@ Y_FORCE_INLINE bool TNullTraceContextGuard::IsActive() const Y_FORCE_INLINE void TNullTraceContextGuard::Release() { if (Active_) { - NDetail::SwapTraceContext(std::move(OldTraceContext_), FROM_HERE); + NDetail::SwapTraceContext(std::move(OldTraceContext_), YT_CURRENT_SOURCE_LOCATION); Active_ = false; } } diff --git a/yt/yt/core/tracing/trace_context.h b/yt/yt/core/tracing/trace_context.h index 8df5446155..01a03da443 100644 --- a/yt/yt/core/tracing/trace_context.h +++ b/yt/yt/core/tracing/trace_context.h @@ -304,7 +304,7 @@ class TCurrentTraceContextGuard public: explicit TCurrentTraceContextGuard( TTraceContextPtr traceContext, - TSourceLocation location = FROM_HERE); + TSourceLocation location = YT_CURRENT_SOURCE_LOCATION); TCurrentTraceContextGuard(TCurrentTraceContextGuard&& other); ~TCurrentTraceContextGuard(); @@ -324,7 +324,7 @@ private: class TNullTraceContextGuard { public: - TNullTraceContextGuard(TSourceLocation location = FROM_HERE); + TNullTraceContextGuard(TSourceLocation location = YT_CURRENT_SOURCE_LOCATION); TNullTraceContextGuard(TNullTraceContextGuard&& other); ~TNullTraceContextGuard(); |