mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
AK+Tests: Remove NoAllocationGuard
On systems other than SerenityOS this was a no-op anyways.
This commit is contained in:
parent
4f8a4c196f
commit
0582c01c89
Notes:
github-actions[bot]
2025-11-07 10:29:46 +00:00
Author: https://github.com/cqundefine
Commit: 0582c01c89
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6631
Reviewed-by: https://github.com/gmta ✅
4 changed files with 0 additions and 98 deletions
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
|
||||
#if defined(AK_OS_SERENITY)
|
||||
# include <mallocdefs.h>
|
||||
#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
|
||||
|
|
@ -121,7 +121,6 @@ shared_library("AK") {
|
|||
"MemoryStream.cpp",
|
||||
"MemoryStream.h",
|
||||
"NeverDestroyed.h",
|
||||
"NoAllocationGuard.h",
|
||||
"Noncopyable.h",
|
||||
"NonnullOwnPtr.h",
|
||||
"NonnullRefPtr.h",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <LibTest/TestSuite.h>
|
||||
|
||||
#include <AK/FixedArray.h>
|
||||
#include <AK/NoAllocationGuard.h>
|
||||
|
||||
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<int> array = FixedArray<int>::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<int> moved_from_array = FixedArray<int>::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<FixedArray<int>> moved_to_array;
|
||||
|
||||
{
|
||||
NoAllocationGuard guard;
|
||||
moved_to_array.emplace(move(moved_from_array));
|
||||
}
|
||||
}());
|
||||
|
||||
EXPECT_NO_DEATH("Swap", [&]() {
|
||||
FixedArray<int> target_for_swapping;
|
||||
{
|
||||
NoAllocationGuard guard;
|
||||
array.swap(target_for_swapping);
|
||||
}
|
||||
}());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -358,8 +358,6 @@ TEST_CASE(move_assign)
|
|||
EXPECT_EQ(second.size(), static_cast<size_t>(0));
|
||||
EXPECT_EQ(second.get(2), Optional<int>());
|
||||
|
||||
// 'Hashtable::operator=(Hashtable&&)' allocates temporarily an empty table,
|
||||
// so we can't use NoAllocationGuard here. :(
|
||||
second = move(orig);
|
||||
|
||||
EXPECT_EQ(orig.size(), static_cast<size_t>(0));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue