From 4cf93820c1ced899f7d1be40a63e60451003fb8a Mon Sep 17 00:00:00 2001 From: aleexfi Date: Tue, 4 Oct 2022 13:53:13 +0300 Subject: Fix of aligned_free on windows --- library/cpp/yt/memory/new-inl.h | 28 ++++++++++++++++++---------- library/cpp/yt/memory/ref_counted.h | 4 ++++ library/cpp/yt/misc/cast-inl.h | 4 ++-- library/cpp/yt/string/enum-inl.h | 4 ++-- 4 files changed, 26 insertions(+), 14 deletions(-) (limited to 'library/cpp') diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h index 5d5fcc45c48..40bf49d3e4a 100644 --- a/library/cpp/yt/memory/new-inl.h +++ b/library/cpp/yt/memory/new-inl.h @@ -188,11 +188,15 @@ Y_FORCE_INLINE TIntrusivePtr SafeConstruct(void* ptr, As&&... args) template void* AllocateConstSizeAligned() { +#ifdef _win_ + return AllignedMalloc(Size, Alignment); +#else if (Alignment <= 16) { return NYTAlloc::AllocateConstSize(); } else { return AllignedMalloc(Size, Alignment); } +#endif } } // namespace NDetail @@ -203,11 +207,11 @@ template Y_FORCE_INLINE TIntrusivePtr New( As&&... args) { - void* ptr = NDetail::AllocateConstSizeAligned< - NDetail::TConstructHelper::Size, - NDetail::TConstructHelper::Alignment>(); + void* ptr = NYT::NDetail::AllocateConstSizeAligned< + NYT::NDetail::TConstructHelper::Size, + NYT::NDetail::TConstructHelper::Alignment>(); - return NDetail::SafeConstruct(ptr, std::forward(args)...); + return NYT::NDetail::SafeConstruct(ptr, std::forward(args)...); } template @@ -215,11 +219,11 @@ Y_FORCE_INLINE TIntrusivePtr New( typename T::TAllocator* allocator, As&&... args) { - auto* ptr = allocator->Allocate(NDetail::TConstructHelper::Size); + auto* ptr = allocator->Allocate(NYT::NDetail::TConstructHelper::Size); if (!ptr) { return nullptr; } - return NDetail::SafeConstruct(ptr, std::forward(args)...); + return NYT::NDetail::SafeConstruct(ptr, std::forward(args)...); } //////////////////////////////////////////////////////////////////////////////// @@ -232,11 +236,15 @@ Y_FORCE_INLINE TIntrusivePtr NewWithExtraSpace( auto totalSize = NYT::NDetail::TConstructHelper::Size + extraSpaceSize; void* ptr = nullptr; +#ifdef _win_ + ptr = NYT::NDetail::AllignedMalloc(totalSize, NYT::NDetail::TConstructHelper::Alignment); +#else if (NYT::NDetail::TConstructHelper::Alignment <= 16) { ptr = NYTAlloc::Allocate(totalSize); } else { ptr = NYT::NDetail::AllignedMalloc(totalSize, NYT::NDetail::TConstructHelper::Alignment); } +#endif return NYT::NDetail::SafeConstruct(ptr, std::forward(args)...); } @@ -262,9 +270,9 @@ template Y_FORCE_INLINE TIntrusivePtr NewWithDelete(const TDeleter& deleter, As&&... args) { using TWrapper = TRefCountedWrapperWithDeleter; - void* ptr = NDetail::AllocateConstSizeAligned(); + void* ptr = NYT::NDetail::AllocateConstSizeAligned(); - auto* instance = NDetail::NewEpilogue( + auto* instance = NYT::NDetail::NewEpilogue( ptr, deleter, std::forward(args)...); @@ -280,9 +288,9 @@ Y_FORCE_INLINE TIntrusivePtr NewWithLocation( As&&... args) { using TWrapper = TRefCountedWrapperWithCookie; - void* ptr = NDetail::AllocateConstSizeAligned(); + void* ptr = NYT::NDetail::AllocateConstSizeAligned(); - auto* instance = NDetail::NewEpilogue(ptr, std::forward(args)...); + auto* instance = NYT::NDetail::NewEpilogue(ptr, std::forward(args)...); #ifdef YT_ENABLE_REF_COUNTED_TRACKING instance->InitializeTracking(GetRefCountedTypeCookieWithLocation(location)); diff --git a/library/cpp/yt/memory/ref_counted.h b/library/cpp/yt/memory/ref_counted.h index 9c049c09981..e48d601c848 100644 --- a/library/cpp/yt/memory/ref_counted.h +++ b/library/cpp/yt/memory/ref_counted.h @@ -38,7 +38,11 @@ struct TFreeMemory { static void Do(void* ptr) { +#ifdef _win_ + ::_aligned_free(ptr); +#else ::free(ptr); +#endif } }; diff --git a/library/cpp/yt/misc/cast-inl.h b/library/cpp/yt/misc/cast-inl.h index 1920b7c0b76..a8b34c8af30 100644 --- a/library/cpp/yt/misc/cast-inl.h +++ b/library/cpp/yt/misc/cast-inl.h @@ -67,7 +67,7 @@ inline TString FormatInvalidCastValue(char8_t value) template bool TryIntegralCast(S value, T* result) { - if (!NDetail::IsInIntegralRange(value)) { + if (!NYT::NDetail::IsInIntegralRange(value)) { return false; } *result = static_cast(value); @@ -80,7 +80,7 @@ T CheckedIntegralCast(S value) T result; if (!TryIntegralCast(value, &result)) { throw TSimpleException(Sprintf("Argument value %s is out of expected range", - NDetail::FormatInvalidCastValue(value).c_str())); + NYT::NDetail::FormatInvalidCastValue(value).c_str())); } return result; } diff --git a/library/cpp/yt/string/enum-inl.h b/library/cpp/yt/string/enum-inl.h index ab8acff71b0..7ce7d2a350a 100644 --- a/library/cpp/yt/string/enum-inl.h +++ b/library/cpp/yt/string/enum-inl.h @@ -59,7 +59,7 @@ T ParseEnum(TStringBuf value) if (auto optionalResult = TryParseEnum(value)) { return *optionalResult; } - NDetail::ThrowMalformedEnumValueException(TEnumTraits::GetTypeName(), value); + NYT::NDetail::ThrowMalformedEnumValueException(TEnumTraits::GetTypeName(), value); } template @@ -71,7 +71,7 @@ void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase) auto* literal = TEnumTraits::FindLiteralByValue(value); if (!literal) { YT_VERIFY(!TEnumTraits::IsBitEnum); - NDetail::FormatUnknownEnumValue( + NYT::NDetail::FormatUnknownEnumValue( builder, TEnumTraits::GetTypeName(), static_cast::TUnderlying>(value)); -- cgit v1.3