From 3ef72e8a7b8d66be2443c5bbf9126169e7a44974 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 23 Mar 2023 14:26:03 +0200 Subject: [PATCH] BAN: Modify Span constructors to keep constness correctly --- BAN/include/BAN/Span.h | 20 ++++++++++++++++++++ kernel/include/kernel/Font.h | 4 ++-- kernel/kernel/Font.cpp | 7 +++---- kernel/kernel/Storage/StorageDevice.cpp | 3 +-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/BAN/include/BAN/Span.h b/BAN/include/BAN/Span.h index d2e7a8632e..a6b4ad0903 100644 --- a/BAN/include/BAN/Span.h +++ b/BAN/include/BAN/Span.h @@ -20,6 +20,10 @@ namespace BAN public: Span() = default; Span(T*, size_type); + Span(Span&); + template + requires(is_same_v) + Span(const Span&); iterator begin() { return iterator(m_data); } iterator end() { return iterator(m_data + m_size); } @@ -51,6 +55,22 @@ namespace BAN { } + template + Span::Span(Span& other) + : m_data(other.data()) + , m_size(other.size()) + { + } + + template + template + requires(is_same_v) + Span::Span(const Span& other) + : m_data(other.data()) + , m_size(other.size()) + { + } + template T& Span::operator[](size_type index) { diff --git a/kernel/include/kernel/Font.h b/kernel/include/kernel/Font.h index bb10264be4..0daecf2588 100644 --- a/kernel/include/kernel/Font.h +++ b/kernel/include/kernel/Font.h @@ -21,8 +21,8 @@ namespace Kernel const uint8_t* glyph(uint32_t) const; private: - static BAN::ErrorOr parse_psf1(const BAN::Span); - static BAN::ErrorOr parse_psf2(const BAN::Span); + static BAN::ErrorOr parse_psf1(BAN::Span); + static BAN::ErrorOr parse_psf2(BAN::Span); private: BAN::HashMap m_glyph_offsets; diff --git a/kernel/kernel/Font.cpp b/kernel/kernel/Font.cpp index ef1e3c99ed..c8ee092cc5 100644 --- a/kernel/kernel/Font.cpp +++ b/kernel/kernel/Font.cpp @@ -31,7 +31,7 @@ namespace Kernel BAN::ErrorOr Font::prefs() { size_t font_data_size = _binary_font_prefs_psf_end - _binary_font_prefs_psf_start; - BAN::Span font_data(_binary_font_prefs_psf_start, font_data_size); + BAN::Span font_data(_binary_font_prefs_psf_start, font_data_size); return parse_psf1(font_data); } @@ -57,8 +57,7 @@ namespace Kernel return BAN::Error::from_c_string("Unsupported font format"); } - - BAN::ErrorOr Font::parse_psf1(const BAN::Span font_data) + BAN::ErrorOr Font::parse_psf1(BAN::Span font_data) { if (font_data.size() < 4) return BAN::Error::from_c_string("Font file is too small"); @@ -139,7 +138,7 @@ namespace Kernel return result; } - BAN::ErrorOr Font::parse_psf2(const BAN::Span font_data) + BAN::ErrorOr Font::parse_psf2(BAN::Span font_data) { struct PSF2Header { diff --git a/kernel/kernel/Storage/StorageDevice.cpp b/kernel/kernel/Storage/StorageDevice.cpp index 2d536adb49..f8b178fc45 100644 --- a/kernel/kernel/Storage/StorageDevice.cpp +++ b/kernel/kernel/Storage/StorageDevice.cpp @@ -40,7 +40,7 @@ namespace Kernel BAN::LittleEndian ending_lba; BAN::LittleEndian attributes; BAN::LittleEndian partition_name[36]; - } __attribute__((packed)); + }; static uint32_t crc32_table[256] = { @@ -167,7 +167,6 @@ namespace Kernel for (uint32_t i = 0; i < header.partition_entry_count; i++) { const PartitionEntry& entry = *(const PartitionEntry*)(entry_array.data() + header.partition_entry_size * i); - ASSERT((uintptr_t)&entry % 2 == 0); char utf8_name[36 * 4 + 1]; BAN::UTF8::from_codepoints(entry.partition_name, 36, utf8_name);