diff --git a/AK/NoAllocationGuard.h b/AK/NoAllocationGuard.h deleted file mode 100644 index 8cc3c846ba..0000000000 --- a/AK/NoAllocationGuard.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022, kleines Filmröllchen . - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -#if defined(AK_OS_SERENITY) -# include -#endif - -namespace AK { - -class NoAllocationGuard { - AK_MAKE_NONCOPYABLE(NoAllocationGuard); - AK_MAKE_NONMOVABLE(NoAllocationGuard); - -public: - NoAllocationGuard() - : m_allocation_enabled_previously(get_thread_allocation_state()) - { - set_thread_allocation_state(false); - } - - ~NoAllocationGuard() - { - set_thread_allocation_state(m_allocation_enabled_previously); - } - -private: - static bool get_thread_allocation_state() - { -#if defined(AK_OS_SERENITY) - // This extern thread-local lives in our LibC, which doesn't exist on other systems. - return s_allocation_enabled; -#else - return true; -#endif - } - - static void set_thread_allocation_state(bool value) - { -#if defined(AK_OS_SERENITY) - s_allocation_enabled = value; -#else - (void)value; -#endif - } - - bool m_allocation_enabled_previously { true }; -}; - -} - -#if USING_AK_GLOBALLY -using AK::NoAllocationGuard; -#endif diff --git a/Meta/gn/secondary/AK/BUILD.gn b/Meta/gn/secondary/AK/BUILD.gn index 4e9a9b25fa..ee31849cad 100644 --- a/Meta/gn/secondary/AK/BUILD.gn +++ b/Meta/gn/secondary/AK/BUILD.gn @@ -121,7 +121,6 @@ shared_library("AK") { "MemoryStream.cpp", "MemoryStream.h", "NeverDestroyed.h", - "NoAllocationGuard.h", "Noncopyable.h", "NonnullOwnPtr.h", "NonnullRefPtr.h", diff --git a/Tests/AK/TestFixedArray.cpp b/Tests/AK/TestFixedArray.cpp index ec4f180e56..9ad80c57be 100644 --- a/Tests/AK/TestFixedArray.cpp +++ b/Tests/AK/TestFixedArray.cpp @@ -8,7 +8,6 @@ #include #include -#include TEST_CASE(construct) { @@ -55,36 +54,3 @@ TEST_CASE(move) EXPECT_EQ(moved_to_array.size(), 6u); EXPECT_EQ(moved_from_array.size(), 0u); } - -TEST_CASE(no_allocation) -{ - FixedArray array = FixedArray::must_create_but_fixme_should_propagate_errors(5); - EXPECT_NO_DEATH("Assignments", [&]() { - NoAllocationGuard guard; - array[0] = 0; - array[1] = 1; - array[2] = 2; - array[4] = array[1]; - array[3] = array[0] + array[2]; - }()); - - EXPECT_NO_DEATH("Move", [&]() { - FixedArray moved_from_array = FixedArray::must_create_but_fixme_should_propagate_errors(6); - // We need an Optional here to ensure that the NoAllocationGuard is - // destroyed before the moved_to_array, because that would call free - Optional> moved_to_array; - - { - NoAllocationGuard guard; - moved_to_array.emplace(move(moved_from_array)); - } - }()); - - EXPECT_NO_DEATH("Swap", [&]() { - FixedArray target_for_swapping; - { - NoAllocationGuard guard; - array.swap(target_for_swapping); - } - }()); -} diff --git a/Tests/AK/TestHashMap.cpp b/Tests/AK/TestHashMap.cpp index 0086fe2e1b..db3d470ab3 100644 --- a/Tests/AK/TestHashMap.cpp +++ b/Tests/AK/TestHashMap.cpp @@ -358,8 +358,6 @@ TEST_CASE(move_assign) EXPECT_EQ(second.size(), static_cast(0)); EXPECT_EQ(second.get(2), Optional()); - // 'Hashtable::operator=(Hashtable&&)' allocates temporarily an empty table, - // so we can't use NoAllocationGuard here. :( second = move(orig); EXPECT_EQ(orig.size(), static_cast(0));