summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbabenko <[email protected]>2024-12-14 10:23:55 +0300
committerbabenko <[email protected]>2024-12-14 10:37:43 +0300
commitc3657504c642129865fc8cfdeacb98ef2da8d830 (patch)
treecead21bc291ff91957fe949cba63843d21fa9f9d
parent499c02cc41e48d4edb91558305ab6fc8c4df8de0 (diff)
Introduce (any use) YT_STATIC_INITIALIZER
commit_hash:7d3055f901a21e63f7860f443252a86e9895fd08
-rw-r--r--library/cpp/yt/misc/static_initializer.h19
-rw-r--r--yt/yt/core/misc/error_code.h13
-rw-r--r--yt/yt/core/misc/protobuf_helpers.h11
-rw-r--r--yt/yt/core/phoenix/type_def-inl.h8
-rw-r--r--yt/yt/core/yson/protobuf_interop.h22
-rw-r--r--yt/yt/core/ytree/interned_attributes.h7
6 files changed, 46 insertions, 34 deletions
diff --git a/library/cpp/yt/misc/static_initializer.h b/library/cpp/yt/misc/static_initializer.h
new file mode 100644
index 00000000000..ebaa35a1a24
--- /dev/null
+++ b/library/cpp/yt/misc/static_initializer.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "preprocessor.h"
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+//! Static initializer will be invoked prior to entering |main|.
+//! The exact order of these invocations is, of course, undefined.
+#define YT_STATIC_INITIALIZER(...) \
+ [[maybe_unused]] static inline const void* PP_ANONYMOUS_VARIABLE(StaticInitializer) = [] { \
+ __VA_ARGS__; \
+ return nullptr; \
+ } ()
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT
diff --git a/yt/yt/core/misc/error_code.h b/yt/yt/core/misc/error_code.h
index 2ab243522ea..1c2c08fbb4a 100644
--- a/yt/yt/core/misc/error_code.h
+++ b/yt/yt/core/misc/error_code.h
@@ -2,13 +2,12 @@
#include <library/cpp/yt/misc/enum.h>
#include <library/cpp/yt/misc/port.h>
+#include <library/cpp/yt/misc/static_initializer.h>
#include <library/cpp/yt/string/format.h>
#include <util/generic/hash_set.h>
-#include <library/cpp/yt/misc/preprocessor.h>
-
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
@@ -90,10 +89,12 @@ void FormatValue(
//! NB: This macro should only by used in cpp files.
#define YT_DEFINE_ERROR_CODE_RANGE(from, to, namespaceName, formatter) \
- YT_ATTRIBUTE_USED static const void* PP_ANONYMOUS_VARIABLE(RegisterErrorCodeRange) = [] { \
- ::NYT::TErrorCodeRegistry::Get()->RegisterErrorCodeRange(from, to, namespaceName, formatter); \
- return nullptr; \
- } ()
+ YT_STATIC_INITIALIZER( \
+ ::NYT::TErrorCodeRegistry::Get()->RegisterErrorCodeRange( \
+ from, \
+ to, \
+ namespaceName, \
+ formatter));
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/misc/protobuf_helpers.h b/yt/yt/core/misc/protobuf_helpers.h
index a0a8ac569e6..c6e8c716d95 100644
--- a/yt/yt/core/misc/protobuf_helpers.h
+++ b/yt/yt/core/misc/protobuf_helpers.h
@@ -16,6 +16,7 @@
#include <library/cpp/yt/misc/optional.h>
#include <library/cpp/yt/misc/preprocessor.h>
#include <library/cpp/yt/misc/strong_typedef.h>
+#include <library/cpp/yt/misc/static_initializer.h>
#include <google/protobuf/duration.pb.h>
#include <google/protobuf/message.h>
@@ -373,17 +374,15 @@ struct IProtobufExtensionRegistry
};
#define REGISTER_PROTO_EXTENSION(type, tag, name) \
- YT_ATTRIBUTE_USED static const void* PP_ANONYMOUS_VARIABLE(RegisterProtoExtension) = [] { \
+ YT_STATIC_INITIALIZER( \
NYT::IProtobufExtensionRegistry::Get()->AddAction([] { \
const auto* descriptor = type::default_instance().GetDescriptor(); \
- NYT::IProtobufExtensionRegistry::Get()->RegisterDescriptor({ \
+ ::NYT::IProtobufExtensionRegistry::Get()->RegisterDescriptor({ \
.MessageDescriptor = descriptor, \
.Tag = tag, \
- .Name = #name \
+ .Name = #name, \
});\
- }); \
- return nullptr; \
- } ();
+ }));
//! Finds and deserializes an extension of the given type. Fails if no matching
//! extension is found.
diff --git a/yt/yt/core/phoenix/type_def-inl.h b/yt/yt/core/phoenix/type_def-inl.h
index ff39a471b16..b7322d79551 100644
--- a/yt/yt/core/phoenix/type_def-inl.h
+++ b/yt/yt/core/phoenix/type_def-inl.h
@@ -14,7 +14,7 @@
#include <yt/yt/core/concurrency/fls.h>
-#include <library/cpp/yt/misc/preprocessor.h>
+#include <library/cpp/yt/misc/static_initializer.h>
#include <concepts>
@@ -78,7 +78,7 @@ namespace NYT::NPhoenix2::NDetail {
template <> \
struct TPhoenixTypeInitializer__<type> \
{ \
- [[maybe_unused]] static inline const void* Dummy = &::NYT::NPhoenix2::NDetail::RegisterTypeDescriptorImpl<type, false>(); \
+ YT_STATIC_INITIALIZER(::NYT::NPhoenix2::NDetail::RegisterTypeDescriptorImpl<type, false>()); \
}
#define PHOENIX_DEFINE_TEMPLATE_TYPE(type, typeArgs) \
@@ -88,7 +88,7 @@ namespace NYT::NPhoenix2::NDetail {
template <> \
struct TPhoenixTypeInitializer__<type<PP_DEPAREN(typeArgs)>> \
{ \
- [[maybe_unused]] static inline const void* Dummy = &::NYT::NPhoenix2::NDetail::RegisterTypeDescriptorImpl<type<PP_DEPAREN(typeArgs)>, true>(); \
+ YT_STATIC_INITIALIZER(::NYT::NPhoenix2::NDetail::RegisterTypeDescriptorImpl<type<PP_DEPAREN(typeArgs)>, true>()); \
}
#define PHOENIX_DEFINE_OPAQUE_TYPE(type) \
@@ -104,7 +104,7 @@ namespace NYT::NPhoenix2::NDetail {
template <> \
struct TPhoenixTypeInitializer__<type> \
{ \
- [[maybe_unused]] static inline const void* Dummy = &::NYT::NPhoenix2::NDetail::RegisterOpaqueTypeDescriptorImpl<type>(); \
+ YT_STATIC_INITIALIZER(::NYT::NPhoenix2::NDetail::RegisterOpaqueTypeDescriptorImpl<type>()); \
}
#define PHOENIX_REGISTER_FIELD(fieldTag, fieldName) \
diff --git a/yt/yt/core/yson/protobuf_interop.h b/yt/yt/core/yson/protobuf_interop.h
index 9b56889654f..6327336075e 100644
--- a/yt/yt/core/yson/protobuf_interop.h
+++ b/yt/yt/core/yson/protobuf_interop.h
@@ -196,13 +196,11 @@ void RegisterCustomProtobufConverter(
const google::protobuf::Descriptor* descriptor,
const TProtobufMessageConverter& converter);
-#define REGISTER_INTERMEDIATE_PROTO_INTEROP_REPRESENTATION(ProtoType, Type) \
- YT_ATTRIBUTE_USED static const void* PP_ANONYMOUS_VARIABLE(RegisterIntermediateProtoInteropRepresentation) = \
- NYson::DoRegisterIntermediateProtoInteropRepresentation<ProtoType, Type, false>();
+#define REGISTER_INTERMEDIATE_PROTO_INTEROP_REPRESENTATION(ProtoType, Type) \
+ YT_STATIC_INITIALIZER(::NYT::NYson::DoRegisterIntermediateProtoInteropRepresentation<ProtoType, Type, false>());
-#define REGISTER_INTERMEDIATE_PROTO_INTEROP_REPRESENTATION_WITH_OPTIONS(ProtoType, Type) \
- YT_ATTRIBUTE_USED static const void* PP_ANONYMOUS_VARIABLE(RegisterIntermediateProtoInteropRepresentationWithOptions) = \
- NYson::DoRegisterIntermediateProtoInteropRepresentation<ProtoType, Type, true>();
+#define REGISTER_INTERMEDIATE_PROTO_INTEROP_REPRESENTATION_WITH_OPTIONS(ProtoType, Type) \
+ YT_STATIC_INITIALIZER(::NYT::NYson::DoRegisterIntermediateProtoInteropRepresentation<ProtoType, Type, true>());
////////////////////////////////////////////////////////////////////////////////
@@ -219,10 +217,10 @@ void RegisterCustomProtobufBytesFieldConverter(
const TProtobufMessageBytesFieldConverter& converter);
#define REGISTER_INTERMEDIATE_PROTO_INTEROP_BYTES_FIELD_REPRESENTATION(ProtoType, FieldNumber, Type) \
- static const void* PP_ANONYMOUS_VARIABLE(RegisterIntermediateProtoInterpBytesFieldRepresentation) = [] { \
- NYT::NYson::AddProtobufConverterRegisterAction([] { \
+ YT_STATIC_INITIALIZER( \
+ ::NYT::NYson::AddProtobufConverterRegisterAction([] { \
const auto* descriptor = ProtoType::default_instance().GetDescriptor(); \
- NYT::NYson::TProtobufMessageBytesFieldConverter converter; \
+ ::NYT::NYson::TProtobufMessageBytesFieldConverter converter; \
converter.Serializer = [] (NYT::NYson::IYsonConsumer* consumer, TStringBuf bytes) { \
Type value; \
FromBytes(&value, bytes); \
@@ -233,10 +231,8 @@ void RegisterCustomProtobufBytesFieldConverter(
Deserialize(value, node); \
ToBytes(bytes, value); \
}; \
- NYT::NYson::RegisterCustomProtobufBytesFieldConverter(descriptor, FieldNumber, converter); \
- }); \
- return nullptr; \
- } ();
+ ::NYT::NYson::RegisterCustomProtobufBytesFieldConverter(descriptor, FieldNumber, converter); \
+ }));
////////////////////////////////////////////////////////////////////////////////
diff --git a/yt/yt/core/ytree/interned_attributes.h b/yt/yt/core/ytree/interned_attributes.h
index b005ed5f54a..85d55e1f108 100644
--- a/yt/yt/core/ytree/interned_attributes.h
+++ b/yt/yt/core/ytree/interned_attributes.h
@@ -2,7 +2,7 @@
#include "public.h"
-#include <library/cpp/yt/misc/preprocessor.h>
+#include <library/cpp/yt/misc/static_initializer.h>
namespace NYT::NYTree {
@@ -43,10 +43,7 @@ void InternAttribute(const TString& uninternedKey, TInternedAttributeKey interne
////////////////////////////////////////////////////////////////////////////////
#define REGISTER_INTERNED_ATTRIBUTE(uninternedKey, internedKey) \
- YT_ATTRIBUTE_USED const void* PP_ANONYMOUS_VARIABLE(RegisterInterndAttribute) = [] { \
- ::NYT::NYTree::InternAttribute(#uninternedKey, internedKey); \
- return nullptr; \
- } ();
+ YT_STATIC_INITIALIZER(::NYT::NYTree::InternAttribute(#uninternedKey, internedKey));
////////////////////////////////////////////////////////////////////////////////