summaryrefslogtreecommitdiffstats
path: root/library/cpp/yt
diff options
context:
space:
mode:
authordann239 <[email protected]>2026-04-03 15:15:57 +0300
committerdann239 <[email protected]>2026-04-03 15:52:56 +0300
commit57a36bc0bb183d5118c335e84ac02a4f61e257ef (patch)
treef465a9693b6863d628d54331023d66d44cb8edc8 /library/cpp/yt
parenta3cb9cceb1b151bc660d9ca51115adc66995419e (diff)
YT-27872: Refactor BIND to fix ODR violations
commit_hash:25c6545fed2bffe20f7a008a218b9245896926ec
Diffstat (limited to 'library/cpp/yt')
-rw-r--r--library/cpp/yt/memory/new-inl.h7
-rw-r--r--library/cpp/yt/memory/new.h4
-rw-r--r--library/cpp/yt/memory/ref_tracked-inl.h6
-rw-r--r--library/cpp/yt/memory/ref_tracked.h13
-rw-r--r--library/cpp/yt/misc/source_location-inl.h20
-rw-r--r--library/cpp/yt/misc/source_location.h24
6 files changed, 52 insertions, 22 deletions
diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h
index 187b0ddf851..724fe6d1b9e 100644
--- a/library/cpp/yt/memory/new-inl.h
+++ b/library/cpp/yt/memory/new-inl.h
@@ -309,18 +309,15 @@ Y_FORCE_INLINE TIntrusivePtr<T> NewWithDeleter(TDeleter deleter, As&&... args)
////////////////////////////////////////////////////////////////////////////////
-template <class T, class TTag, int Counter, class... As>
+template <class T, auto LocationLite, class... As>
Y_FORCE_INLINE TIntrusivePtr<T> NewWithLocation(
- const TSourceLocation& location,
As&&... args)
{
using TWrapper = TRefCountedWrapperWithCookie<T>;
void* ptr = NYT::NDetail::AllocateConstSizeAlignedOrCrash<sizeof(TWrapper), alignof(TWrapper)>();
auto* instance = NYT::NDetail::NewEpilogue<TWrapper>(ptr, std::forward<As>(args)...);
#ifdef YT_ENABLE_REF_COUNTED_TRACKING
- instance->InitializeTracking(GetRefCountedTypeCookieWithLocation<T, TTag, Counter>(location));
-#else
- Y_UNUSED(location);
+ instance->InitializeTracking(GetRefCountedTypeCookieWithLocation<T, LocationLite>());
#endif
return TIntrusivePtr<T>(instance, /*addReference*/ false);
}
diff --git a/library/cpp/yt/memory/new.h b/library/cpp/yt/memory/new.h
index a47ee06f5f6..50f594c990a 100644
--- a/library/cpp/yt/memory/new.h
+++ b/library/cpp/yt/memory/new.h
@@ -117,8 +117,8 @@ TIntrusivePtr<T> NewWithDeleter(TDeleter deleter, As&&... args);
//! Allocates a new instance of |T|.
//! The allocation is additionally marked with #location.
//! Aborts the process on out-of-memory condition.
-template <class T, class TTag, int Counter, class... As>
-TIntrusivePtr<T> NewWithLocation(const TSourceLocation& location, As&&... args);
+template <class T, auto LocationLite, class... As>
+TIntrusivePtr<T> NewWithLocation(As&&... args);
//! Enables calling #New and co for types with private ctors.
#define DECLARE_NEW_FRIEND() \
diff --git a/library/cpp/yt/memory/ref_tracked-inl.h b/library/cpp/yt/memory/ref_tracked-inl.h
index 45bd2c70a86..cf1c4515c32 100644
--- a/library/cpp/yt/memory/ref_tracked-inl.h
+++ b/library/cpp/yt/memory/ref_tracked-inl.h
@@ -29,8 +29,8 @@ Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookie()
return cookieValue;
}
-template <class T, class TTag, int Counter>
-Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation(const TSourceLocation& location)
+template <class T, auto LocationLite>
+Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation()
{
static std::atomic<TRefCountedTypeCookie> cookie{NullRefCountedTypeCookie};
auto cookieValue = cookie.load(std::memory_order::relaxed);
@@ -38,7 +38,7 @@ Y_FORCE_INLINE TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation(const T
cookieValue = TRefCountedTrackerFacade::GetCookie(
GetRefCountedTypeKey<T>(),
sizeof(T),
- location);
+ TSourceLocation::FromLite<LocationLite>());
cookie.store(cookieValue, std::memory_order::relaxed);
}
return cookieValue;
diff --git a/library/cpp/yt/memory/ref_tracked.h b/library/cpp/yt/memory/ref_tracked.h
index be719ad41b7..f3d75528660 100644
--- a/library/cpp/yt/memory/ref_tracked.h
+++ b/library/cpp/yt/memory/ref_tracked.h
@@ -45,23 +45,14 @@ public:
////////////////////////////////////////////////////////////////////////////////
-namespace {
-
-//! A per-translation unit tag type.
-struct TCurrentTranslationUnitTag
-{ };
-
-} // namespace
-
template <class T>
TRefCountedTypeKey GetRefCountedTypeKey();
template <class T>
TRefCountedTypeCookie GetRefCountedTypeCookie();
-template <class T, class TTag, int Counter>
-TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation(
- const TSourceLocation& location);
+template <class T, auto LocationLite>
+TRefCountedTypeCookie GetRefCountedTypeCookieWithLocation();
////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/yt/misc/source_location-inl.h b/library/cpp/yt/misc/source_location-inl.h
index 9948260874a..8edff29812f 100644
--- a/library/cpp/yt/misc/source_location-inl.h
+++ b/library/cpp/yt/misc/source_location-inl.h
@@ -4,10 +4,22 @@
#include "source_location.h"
#endif
+#include <string>
+
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+template <size_t N>
+consteval TSourceLocationLite<N> MakeSourceLocationLite(const char* fileName, i64 line)
+{
+ TSourceLocationLite<N> result{.FileName = {}, .Line = line};
+ std::char_traits<char>::copy(result.FileName, fileName, N + 1);
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
inline TSourceLocation::TSourceLocation(const char* fileName, int line)
: FileName_(fileName)
, Line_(line)
@@ -20,6 +32,12 @@ inline TSourceLocation::TSourceLocation(const std::source_location& location)
{ }
#endif // __cpp_lib_source_location
+template <auto LocationLite>
+TSourceLocation TSourceLocation::FromLite()
+{
+ return TSourceLocation(LocationLite.FileName, LocationLite.Line);
+}
+
////////////////////////////////////////////////////////////////////////////////
-} // namespace std
+} // namespace NYT
diff --git a/library/cpp/yt/misc/source_location.h b/library/cpp/yt/misc/source_location.h
index 7a475022620..586593867da 100644
--- a/library/cpp/yt/misc/source_location.h
+++ b/library/cpp/yt/misc/source_location.h
@@ -10,6 +10,18 @@ namespace NYT {
////////////////////////////////////////////////////////////////////////////////
+template <size_t N>
+struct TSourceLocationLite
+{
+ char FileName[N + 1];
+ i64 Line;
+};
+
+template <size_t N>
+consteval TSourceLocationLite<N> MakeSourceLocationLite(const char* fileName, i64 line);
+
+////////////////////////////////////////////////////////////////////////////////
+
class TSourceLocation
{
public:
@@ -19,6 +31,9 @@ public:
explicit TSourceLocation(const std::source_location& location);
#endif // __cpp_lib_source_location
+ template <auto LocationLite>
+ static TSourceLocation FromLite();
+
const char* GetFileName() const;
int GetLine() const;
bool IsValid() const;
@@ -31,6 +46,15 @@ private:
int Line_ = -1;
};
+#ifdef __cpp_lib_source_location
+#define YT_CURRENT_SOURCE_LOCATION_LITE \
+ ::NYT::MakeSourceLocationLite<std::char_traits<char>::length(std::source_location::current().file_name())>( \
+ std::source_location::current().file_name(), \
+ std::source_location::current().line())
+#else
+#define YT_CURRENT_SOURCE_LOCATION_LITE ::NYT::MakeSourceLocationLite<std::char_traits<char>::length(__FILE__)>(__FILE__, __LINE__)
+#endif // __cpp_lib_source_location
+
//! Defines a macro to record the current source location.
#ifdef __cpp_lib_source_location
#define YT_CURRENT_SOURCE_LOCATION ::NYT::TSourceLocation(std::source_location::current())