From bcc00857a4604c874b4513bc2acc1c67d8d22c73 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 5 Apr 2019 05:10:18 +0200 Subject: [PATCH] AK: Revert Eternal for now since it doesn't work as intended. --- AK/Eternal.h | 30 ---------------------------- AK/kmalloc.h | 1 - Kernel/Net/LoopbackAdapter.cpp | 7 ++++--- Kernel/Net/LoopbackAdapter.h | 5 +++-- Kernel/Net/NetworkTask.cpp | 8 +++++--- Kernel/StdLib.cpp | 10 ---------- LibGUI/GClipboard.cpp | 14 ++++++++++++- LibGUI/GClipboard.h | 9 +++++++-- LibGUI/GDesktop.cpp | 7 ++++--- LibGUI/GFontDatabase.cpp | 8 +++++--- LibGUI/GFontDatabase.h | 2 +- LibGUI/GTextEditor.cpp | 6 +++--- Servers/WindowServer/WSClipboard.cpp | 7 ++++--- Servers/WindowServer/WSClipboard.h | 4 ++-- 14 files changed, 51 insertions(+), 67 deletions(-) delete mode 100644 AK/Eternal.h diff --git a/AK/Eternal.h b/AK/Eternal.h deleted file mode 100644 index 6db63a300f..0000000000 --- a/AK/Eternal.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - -namespace AK { - -template -class Eternal { -public: - template - Eternal(Args&&... args) - { - new (m_slot) T(forward(args)...); - } - - T& get() { return *reinterpret_cast(&m_slot); } - const T& get() const { return *reinterpret_cast(&m_slot); } - T* operator->() { return &get(); } - const T* operator->() const { return &get(); } - operator T&() { return get(); } - operator const T&() const { return get(); } - - -private: - [[gnu::aligned(alignof(T))]] char m_slot[sizeof(T)]; -}; - -} - -using AK::Eternal; diff --git a/AK/kmalloc.h b/AK/kmalloc.h index d5bf402c76..99a3cd67bd 100644 --- a/AK/kmalloc.h +++ b/AK/kmalloc.h @@ -4,7 +4,6 @@ #define AK_MAKE_ETERNAL \ public: \ void* operator new(size_t size) { return kmalloc_eternal(size); } \ - void* operator new(size_t, void* ptr) { return ptr; } \ private: #else #define AK_MAKE_ETERNAL diff --git a/Kernel/Net/LoopbackAdapter.cpp b/Kernel/Net/LoopbackAdapter.cpp index c21944c5cc..1593f3b3cf 100644 --- a/Kernel/Net/LoopbackAdapter.cpp +++ b/Kernel/Net/LoopbackAdapter.cpp @@ -1,10 +1,11 @@ #include -#include LoopbackAdapter& LoopbackAdapter::the() { - static Eternal the; - return the; + static LoopbackAdapter* the; + if (!the) + the = new LoopbackAdapter; + return *the; } LoopbackAdapter::LoopbackAdapter() diff --git a/Kernel/Net/LoopbackAdapter.h b/Kernel/Net/LoopbackAdapter.h index dad949bc59..e22c146330 100644 --- a/Kernel/Net/LoopbackAdapter.h +++ b/Kernel/Net/LoopbackAdapter.h @@ -6,11 +6,12 @@ class LoopbackAdapter final : public NetworkAdapter { AK_MAKE_ETERNAL public: static LoopbackAdapter& the(); - LoopbackAdapter(); + + virtual ~LoopbackAdapter() override; virtual void send_raw(const byte*, int) override; virtual const char* class_name() const override { return "LoopbackAdapter"; } private: - virtual ~LoopbackAdapter() override; + LoopbackAdapter(); }; diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 4251a22f4a..fbd73671af 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -12,7 +12,7 @@ #include #include #include -#include + //#define ETHERNET_DEBUG #define IPV4_DEBUG @@ -28,8 +28,10 @@ static void handle_tcp(const EthernetFrameHeader&, int frame_size); Lockable>& arp_table() { - static Eternal>> the; - return the; + static Lockable>* the; + if (!the) + the = new Lockable>; + return *the; } void NetworkTask_main() diff --git a/Kernel/StdLib.cpp b/Kernel/StdLib.cpp index 4f25a84455..20c07f9341 100644 --- a/Kernel/StdLib.cpp +++ b/Kernel/StdLib.cpp @@ -145,14 +145,4 @@ int memcmp(const void* v1, const void* v2, size_t n) ASSERT_NOT_REACHED(); } -void __cxa_guard_acquire(void*) -{ - // FIXME: Lock somehow? -} - -void __cxa_guard_release(void*) -{ - // FIXME: Unlock somehow? -} - } diff --git a/LibGUI/GClipboard.cpp b/LibGUI/GClipboard.cpp index 39c167cdcb..9a349a157d 100644 --- a/LibGUI/GClipboard.cpp +++ b/LibGUI/GClipboard.cpp @@ -3,7 +3,19 @@ #include #include -String GClipboard::data() +GClipboard& GClipboard::the() +{ + static GClipboard* s_the; + if (!s_the) + s_the = new GClipboard; + return *s_the; +} + +GClipboard::GClipboard() +{ +} + +String GClipboard::data() const { WSAPI_ClientMessage request; request.type = WSAPI_ClientMessage::Type::GetClipboardContents; diff --git a/LibGUI/GClipboard.h b/LibGUI/GClipboard.h index 63b9621b71..fc8cb5c95f 100644 --- a/LibGUI/GClipboard.h +++ b/LibGUI/GClipboard.h @@ -4,6 +4,11 @@ class GClipboard { public: - static String data(); - static void set_data(const String&); + static GClipboard& the(); + + String data() const; + void set_data(const String&); + +private: + GClipboard(); }; diff --git a/LibGUI/GDesktop.cpp b/LibGUI/GDesktop.cpp index f692ca5615..234db21a84 100644 --- a/LibGUI/GDesktop.cpp +++ b/LibGUI/GDesktop.cpp @@ -1,13 +1,14 @@ #include #include -#include #include #include GDesktop& GDesktop::the() { - static Eternal the; - return the; + static GDesktop* the; + if (!the) + the = new GDesktop; + return *the; } GDesktop::GDesktop() diff --git a/LibGUI/GFontDatabase.cpp b/LibGUI/GFontDatabase.cpp index 74ace0a5fd..63c8f7ec4d 100644 --- a/LibGUI/GFontDatabase.cpp +++ b/LibGUI/GFontDatabase.cpp @@ -1,14 +1,16 @@ #include #include -#include #include #include #include +static GFontDatabase* s_the; + GFontDatabase& GFontDatabase::the() { - static Eternal the; - return the; + if (!s_the) + s_the = new GFontDatabase; + return *s_the; } GFontDatabase::GFontDatabase() diff --git a/LibGUI/GFontDatabase.h b/LibGUI/GFontDatabase.h index e0b8bff121..5cc37cc243 100644 --- a/LibGUI/GFontDatabase.h +++ b/LibGUI/GFontDatabase.h @@ -9,13 +9,13 @@ class Font; class GFontDatabase { public: static GFontDatabase& the(); - GFontDatabase(); RetainPtr get_by_name(const String&); void for_each_font(Function); void for_each_fixed_width_font(Function); private: + GFontDatabase(); ~GFontDatabase(); struct Metadata { diff --git a/LibGUI/GTextEditor.cpp b/LibGUI/GTextEditor.cpp index 41ba03d4be..f409f06a54 100644 --- a/LibGUI/GTextEditor.cpp +++ b/LibGUI/GTextEditor.cpp @@ -785,7 +785,7 @@ void GTextEditor::cut() { auto selected_text = this->selected_text(); printf("Cut: \"%s\"\n", selected_text.characters()); - GClipboard::set_data(selected_text); + GClipboard::the().set_data(selected_text); delete_selection(); } @@ -793,12 +793,12 @@ void GTextEditor::copy() { auto selected_text = this->selected_text(); printf("Copy: \"%s\"\n", selected_text.characters()); - GClipboard::set_data(selected_text); + GClipboard::the().set_data(selected_text); } void GTextEditor::paste() { - auto paste_text = GClipboard::data(); + auto paste_text = GClipboard::the().data(); printf("Paste: \"%s\"\n", paste_text.characters()); insert_at_cursor_or_replace_selection(paste_text); } diff --git a/Servers/WindowServer/WSClipboard.cpp b/Servers/WindowServer/WSClipboard.cpp index 4ee04992c0..7e54b168c8 100644 --- a/Servers/WindowServer/WSClipboard.cpp +++ b/Servers/WindowServer/WSClipboard.cpp @@ -1,10 +1,11 @@ #include -#include WSClipboard& WSClipboard::the() { - static Eternal the; - return the; + static WSClipboard* s_the; + if (!s_the) + s_the = new WSClipboard; + return *s_the; } WSClipboard::WSClipboard() diff --git a/Servers/WindowServer/WSClipboard.h b/Servers/WindowServer/WSClipboard.h index 205b880ed9..2d22beb6f3 100644 --- a/Servers/WindowServer/WSClipboard.h +++ b/Servers/WindowServer/WSClipboard.h @@ -7,7 +7,7 @@ class WSClipboard final : public WSMessageReceiver { public: static WSClipboard& the(); - WSClipboard(); + virtual ~WSClipboard() override; bool has_data() const { @@ -21,7 +21,7 @@ public: void set_data(Retained&&, int contents_size); private: - virtual ~WSClipboard() override; + WSClipboard(); virtual void on_message(const WSMessage&) override; RetainPtr m_shared_buffer;