From 1116a29c19c797bd1299aa42827bb69286d3bade Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 4 Jan 2022 13:29:06 -0500 Subject: [PATCH] LibUnicode: Remove now unused Unicode symbol loader All generated sources are now linked via weak symbols. --- Userland/Libraries/LibUnicode/CMakeLists.txt | 1 - .../Libraries/LibUnicode/UnicodeSymbols.cpp | 97 ------------------- .../Libraries/LibUnicode/UnicodeSymbols.h | 45 --------- 3 files changed, 143 deletions(-) delete mode 100644 Userland/Libraries/LibUnicode/UnicodeSymbols.cpp delete mode 100644 Userland/Libraries/LibUnicode/UnicodeSymbols.h diff --git a/Userland/Libraries/LibUnicode/CMakeLists.txt b/Userland/Libraries/LibUnicode/CMakeLists.txt index 20b49eb335..6752fbb09d 100644 --- a/Userland/Libraries/LibUnicode/CMakeLists.txt +++ b/Userland/Libraries/LibUnicode/CMakeLists.txt @@ -13,7 +13,6 @@ set(SOURCES DateTimeFormat.cpp Locale.cpp NumberFormat.cpp - UnicodeSymbols.cpp ) serenity_lib(LibUnicode unicode) diff --git a/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp b/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp deleted file mode 100644 index 39dade6a9f..0000000000 --- a/Userland/Libraries/LibUnicode/UnicodeSymbols.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2021, Tim Flynn - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#if ENABLE_UNICODE_DATA -# if defined(__serenity__) -# include -# include -# else -# include -# endif -#else -# include -#endif - -namespace Unicode::Detail { - -#if !ENABLE_UNICODE_DATA - -template -struct FunctionStub; - -template -struct FunctionStub> { - static constexpr auto make_stub() - { - if constexpr (IsVoid) - return [](ParameterTypes...) {}; - else - return [](ParameterTypes...) -> ReturnType { return {}; }; - } -}; - -#endif - -// This loader supports 3 modes: -// -// 1. When the Unicode data generators are enabled, and the target is Serenity, the symbols are -// dynamically loaded from the shared library containing them. -// -// 2. When the Unicode data generators are enabled, and the target is Lagom, the symbols are -// dynamically loaded from the main program. -// -// 3. When the Unicode data generators are disabled, the symbols are stubbed out to empty lambdas. -// This allows callers to remain agnostic as to whether the generators are enabled. -Symbols const& Symbols::ensure_loaded() -{ - static Symbols symbols {}; - - static bool initialized = false; - if (initialized) - return symbols; - -#if ENABLE_UNICODE_DATA -# if defined(__serenity__) - static void* libunicodedata = MUST(__dlopen("libunicodedata.so.serenity", RTLD_NOW)); - - auto load_symbol = [&](T& dest, char const* name) { - dest = reinterpret_cast(MUST(__dlsym(libunicodedata, name))); - }; -# else - static void* libunicodedata = dlopen(nullptr, RTLD_NOW); - VERIFY(libunicodedata); - - auto load_symbol = [&](T& dest, char const* name) { - dest = reinterpret_cast(dlsym(libunicodedata, name)); - VERIFY(dest); - }; -# endif -#else - auto load_symbol = [](T& dest, char const*) { - dest = +FunctionStub>>::make_stub(); - }; -#endif - - load_symbol(symbols.code_point_display_name, "unicode_code_point_display_name"); - load_symbol(symbols.canonical_combining_class, "unicode_canonical_combining_class"); - load_symbol(symbols.simple_uppercase_mapping, "unicode_simple_uppercase_mapping"); - load_symbol(symbols.simple_lowercase_mapping, "unicode_simple_lowercase_mapping"); - load_symbol(symbols.special_case_mapping, "unicode_special_case_mapping"); - load_symbol(symbols.general_category_from_string, "unicode_general_category_from_string"); - load_symbol(symbols.code_point_has_general_category, "unicode_code_point_has_general_category"); - load_symbol(symbols.property_from_string, "unicode_property_from_string"); - load_symbol(symbols.code_point_has_property, "unicode_code_point_has_property"); - load_symbol(symbols.script_from_string, "unicode_script_from_string"); - load_symbol(symbols.code_point_has_script, "unicode_code_point_has_script"); - load_symbol(symbols.code_point_has_script_extension, "unicode_code_point_has_script_extension"); - - initialized = true; - return symbols; -} - -} diff --git a/Userland/Libraries/LibUnicode/UnicodeSymbols.h b/Userland/Libraries/LibUnicode/UnicodeSymbols.h deleted file mode 100644 index 920234ff7d..0000000000 --- a/Userland/Libraries/LibUnicode/UnicodeSymbols.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021, Tim Flynn - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace Unicode::Detail { - -struct Symbols { - static Symbols const& ensure_loaded(); - - // Loaded from UnicodeData.cpp: - - Optional (*code_point_display_name)(u32) { nullptr }; - - u32 (*canonical_combining_class)(u32 code_point) { nullptr }; - - u32 (*simple_uppercase_mapping)(u32) { nullptr }; - u32 (*simple_lowercase_mapping)(u32) { nullptr }; - Span (*special_case_mapping)(u32 code_point) { nullptr }; - - Optional (*general_category_from_string)(StringView) { nullptr }; - bool (*code_point_has_general_category)(u32, GeneralCategory) { nullptr }; - - Optional (*property_from_string)(StringView) { nullptr }; - bool (*code_point_has_property)(u32, Property) { nullptr }; - - Optional