From 093cf428a3d7473f429a589f1573d9ac1c41d762 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 25 Jan 2023 20:19:05 +0100 Subject: [PATCH] AK: Move memory streams from `LibCore` --- AK/CMakeLists.txt | 1 + .../Libraries/LibCore => AK}/MemoryStream.cpp | 5 +- .../Libraries/LibCore => AK}/MemoryStream.h | 16 ++-- Ladybird/WebContentView.cpp | 1 - Meta/Lagom/Fuzzers/FuzzBrotli.cpp | 4 +- Meta/Lagom/Fuzzers/FuzzTar.cpp | 4 +- Meta/Lagom/Fuzzers/FuzzWasmParser.cpp | 4 +- .../Tools/CodeGenerators/IPCCompiler/main.cpp | 4 +- Tests/AK/CMakeLists.txt | 1 + Tests/AK/TestBitStream.cpp | 6 +- Tests/AK/TestMemoryStream.cpp | 94 +++++++++++++++++++ Tests/LibCompress/TestDeflate.cpp | 6 +- Tests/LibCore/TestLibCoreStream.cpp | 87 ----------------- Tests/LibWasm/test-wasm.cpp | 4 +- .../Applications/Spreadsheet/ExportDialog.cpp | 4 +- .../Writers/Test/TestXSVWriter.cpp | 8 +- Userland/Libraries/LibAudio/FlacLoader.cpp | 10 +- Userland/Libraries/LibAudio/FlacLoader.h | 1 - Userland/Libraries/LibAudio/MP3Loader.cpp | 2 +- Userland/Libraries/LibAudio/MP3Loader.h | 4 +- Userland/Libraries/LibAudio/WavLoader.cpp | 6 +- Userland/Libraries/LibCompress/Deflate.cpp | 8 +- Userland/Libraries/LibCompress/Gzip.cpp | 8 +- Userland/Libraries/LibCompress/Zlib.cpp | 4 +- Userland/Libraries/LibCore/CMakeLists.txt | 1 - .../Libraries/LibCore/SOCKSProxyClient.cpp | 6 +- Userland/Libraries/LibDNS/Packet.cpp | 4 +- .../LibDebug/Dwarf/AbbreviationsMap.cpp | 4 +- Userland/Libraries/LibDebug/Dwarf/DIE.cpp | 6 +- .../Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 10 +- .../Libraries/LibDebug/Dwarf/Expression.cpp | 4 +- Userland/Libraries/LibGfx/GIFLoader.cpp | 8 +- Userland/Libraries/LibGfx/JPGLoader.cpp | 7 +- Userland/Libraries/LibGfx/QOILoader.cpp | 6 +- Userland/Libraries/LibHTTP/Job.cpp | 4 +- Userland/Libraries/LibLine/Editor.cpp | 4 +- Userland/Libraries/LibPDF/DocumentParser.cpp | 5 +- Userland/Libraries/LibProtocol/Request.h | 4 +- .../AbstractMachine/BytecodeInterpreter.cpp | 12 +-- .../LibWasm/AbstractMachine/Configuration.cpp | 4 +- Userland/Libraries/LibWasm/Parser/Parser.cpp | 4 +- .../LibWeb/WebAssembly/WebAssemblyObject.cpp | 4 +- Userland/Services/WebServer/Client.cpp | 4 +- Userland/Shell/AST.cpp | 4 +- Userland/Utilities/headless-browser.cpp | 13 ++- Userland/Utilities/wasm.cpp | 6 +- 46 files changed, 213 insertions(+), 203 deletions(-) rename {Userland/Libraries/LibCore => AK}/MemoryStream.cpp (99%) rename {Userland/Libraries/LibCore => AK}/MemoryStream.h (91%) create mode 100644 Tests/AK/TestMemoryStream.cpp diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 00609033056..2988ada7ff2 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -16,6 +16,7 @@ set(AK_SOURCES JsonValue.cpp kmalloc.cpp LexicalPath.cpp + MemoryStream.cpp NumberFormat.cpp Random.cpp StackInfo.cpp diff --git a/Userland/Libraries/LibCore/MemoryStream.cpp b/AK/MemoryStream.cpp similarity index 99% rename from Userland/Libraries/LibCore/MemoryStream.cpp rename to AK/MemoryStream.cpp index 09241ba63c3..e4b3bc94f36 100644 --- a/Userland/Libraries/LibCore/MemoryStream.cpp +++ b/AK/MemoryStream.cpp @@ -5,11 +5,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include -#include +#include -namespace Core::Stream { +namespace AK { FixedMemoryStream::FixedMemoryStream(Bytes bytes) : m_bytes(bytes) diff --git a/Userland/Libraries/LibCore/MemoryStream.h b/AK/MemoryStream.h similarity index 91% rename from Userland/Libraries/LibCore/MemoryStream.h rename to AK/MemoryStream.h index f712a198b03..c19de82cffa 100644 --- a/Userland/Libraries/LibCore/MemoryStream.h +++ b/AK/MemoryStream.h @@ -6,14 +6,11 @@ #pragma once -#include -#include #include -#include -#include -#include +#include +#include -namespace Core::Stream { +namespace AK { /// A stream class that allows for reading/writing on a preallocated memory area /// using a single read/write head. @@ -49,7 +46,7 @@ private: /// A stream class that allows for writing to an automatically allocating memory area /// and reading back the written data afterwards. -class AllocatingMemoryStream final : public AK::Stream { +class AllocatingMemoryStream final : public Stream { public: virtual ErrorOr read(Bytes) override; virtual ErrorOr write(ReadonlyBytes) override; @@ -77,3 +74,8 @@ private: }; } + +#if USING_AK_GLOBALLY +using AK::AllocatingMemoryStream; +using AK::FixedMemoryStream; +#endif diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index c0fa8a5e4d7..3dee9df3f18 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp index 142bdadc30a..e3dbbf1be47 100644 --- a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp +++ b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp @@ -4,13 +4,13 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include #include extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - auto bufstream_result = Core::Stream::FixedMemoryStream::construct({ data, size }); + auto bufstream_result = FixedMemoryStream::construct({ data, size }); if (bufstream_result.is_error()) { dbgln("MemoryStream::construct() failed."); return 0; diff --git a/Meta/Lagom/Fuzzers/FuzzTar.cpp b/Meta/Lagom/Fuzzers/FuzzTar.cpp index ff529da4c01..50be8ec74f2 100644 --- a/Meta/Lagom/Fuzzers/FuzzTar.cpp +++ b/Meta/Lagom/Fuzzers/FuzzTar.cpp @@ -4,15 +4,15 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include -#include #include #include extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - auto input_stream_or_error = Core::Stream::FixedMemoryStream::construct({ data, size }); + auto input_stream_or_error = FixedMemoryStream::construct({ data, size }); if (input_stream_or_error.is_error()) return 0; diff --git a/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp b/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp index 6ef9605e0fe..aaa4dfabca3 100644 --- a/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include @@ -12,7 +12,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { ReadonlyBytes bytes { data, size }; - auto stream_or_error = Core::Stream::FixedMemoryStream::construct(bytes); + auto stream_or_error = FixedMemoryStream::construct(bytes); if (stream_or_error.is_error()) return 0; auto stream = stream_or_error.release_value(); diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index db37dfcd265..9dc65385afd 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -586,7 +586,7 @@ public: static ErrorOr> decode_message(ReadonlyBytes buffer, [[maybe_unused]] Core::Stream::LocalSocket& socket) { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(buffer)); + auto stream = TRY(FixedMemoryStream::construct(buffer)); auto message_endpoint_magic = TRY(stream->read_value());)~~~"); generator.append(R"~~~( @@ -768,10 +768,10 @@ void build(StringBuilder& builder, Vector const& endpoints) } generator.appendln(R"~~~(#include +#include #include #include #include -#include #include #include #include diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index fae14c43d6e..cab724ee365 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -50,6 +50,7 @@ set(AK_TEST_SOURCES TestLexicalPath.cpp TestMACAddress.cpp TestMemory.cpp + TestMemoryStream.cpp TestNeverDestroyed.cpp TestNonnullRefPtr.cpp TestNumberFormat.cpp diff --git a/Tests/AK/TestBitStream.cpp b/Tests/AK/TestBitStream.cpp index 0316ae863e7..b04b11d39e0 100644 --- a/Tests/AK/TestBitStream.cpp +++ b/Tests/AK/TestBitStream.cpp @@ -5,13 +5,13 @@ */ #include -#include +#include #include // Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. TEST_CASE(little_endian_bit_stream_input_output_match) { - auto memory_stream = make(); + auto memory_stream = make(); // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, // so testing with sizes that will not trigger a write will yield unexpected results. @@ -67,7 +67,7 @@ TEST_CASE(little_endian_bit_stream_input_output_match) // Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. TEST_CASE(big_endian_bit_stream_input_output_match) { - auto memory_stream = make(); + auto memory_stream = make(); // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, // so testing with sizes that will not trigger a write will yield unexpected results. diff --git a/Tests/AK/TestMemoryStream.cpp b/Tests/AK/TestMemoryStream.cpp new file mode 100644 index 00000000000..48f74a08486 --- /dev/null +++ b/Tests/AK/TestMemoryStream.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021, sin-ack + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +TEST_CASE(allocating_memory_stream_empty) +{ + AllocatingMemoryStream stream; + + EXPECT_EQ(stream.used_buffer_size(), 0ul); + + { + Array array; + auto read_bytes = MUST(stream.read(array)); + EXPECT_EQ(read_bytes.size(), 0ul); + } + + { + auto offset = MUST(stream.offset_of("test"sv.bytes())); + EXPECT(!offset.has_value()); + } +} + +TEST_CASE(allocating_memory_stream_offset_of) +{ + AllocatingMemoryStream stream; + MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes())); + + { + auto offset = MUST(stream.offset_of(" "sv.bytes())); + EXPECT(offset.has_value()); + EXPECT_EQ(offset.value(), 4ul); + } + + { + auto offset = MUST(stream.offset_of("W"sv.bytes())); + EXPECT(offset.has_value()); + EXPECT_EQ(offset.value(), 0ul); + } + + { + auto offset = MUST(stream.offset_of(")"sv.bytes())); + EXPECT(offset.has_value()); + EXPECT_EQ(offset.value(), 22ul); + } + + { + auto offset = MUST(stream.offset_of("-"sv.bytes())); + EXPECT(!offset.has_value()); + } + + MUST(stream.discard(1)); + + { + auto offset = MUST(stream.offset_of("W"sv.bytes())); + EXPECT(!offset.has_value()); + } + + { + auto offset = MUST(stream.offset_of("e"sv.bytes())); + EXPECT(offset.has_value()); + EXPECT_EQ(offset.value(), 0ul); + } +} + +TEST_CASE(allocating_memory_stream_offset_of_oob) +{ + AllocatingMemoryStream stream; + // NOTE: This test is to make sure that offset_of() doesn't read past the end of the "initialized" data. + // So we have to assume some things about the behaviour of this class: + // - The chunk size is 4096 bytes. + // - A chunk is moved to the end when it's fully read from + // - A free chunk is used as-is, no new ones are allocated if one exists. + + // First, fill exactly one chunk. + for (size_t i = 0; i < 256; ++i) + MUST(stream.write_entire_buffer("AAAAAAAAAAAAAAAA"sv.bytes())); + + // Then discard it all. + MUST(stream.discard(4096)); + // Now we can write into this chunk again, knowing that it's initialized to all 'A's. + MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes())); + + { + auto offset = MUST(stream.offset_of("A"sv.bytes())); + EXPECT(!offset.has_value()); + } +} diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp index bdeeabd9b09..9cb2ec94605 100644 --- a/Tests/LibCompress/TestDeflate.cpp +++ b/Tests/LibCompress/TestDeflate.cpp @@ -8,9 +8,9 @@ #include #include +#include #include #include -#include #include TEST_CASE(canonical_code_simple) @@ -28,7 +28,7 @@ TEST_CASE(canonical_code_simple) }; auto const huffman = Compress::CanonicalCode::from_bytes(code).value(); - auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input)); + auto memory_stream = MUST(FixedMemoryStream::construct(input)); auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream))); for (size_t idx = 0; idx < 9; ++idx) @@ -48,7 +48,7 @@ TEST_CASE(canonical_code_complex) }; auto const huffman = Compress::CanonicalCode::from_bytes(code).value(); - auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input)); + auto memory_stream = MUST(FixedMemoryStream::construct(input)); auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream))); for (size_t idx = 0; idx < 12; ++idx) diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cpp index 500d3b5a18b..fe448f26980 100644 --- a/Tests/LibCore/TestLibCoreStream.cpp +++ b/Tests/LibCore/TestLibCoreStream.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -594,89 +593,3 @@ TEST_CASE(buffered_tcp_socket_read) auto second_received_line = maybe_second_received_line.value(); EXPECT_EQ(second_received_line, second_line); } - -// Allocating memory stream tests - -TEST_CASE(allocating_memory_stream_empty) -{ - Core::Stream::AllocatingMemoryStream stream; - - EXPECT_EQ(stream.used_buffer_size(), 0ul); - - { - Array array; - auto read_bytes = MUST(stream.read(array)); - EXPECT_EQ(read_bytes.size(), 0ul); - } - - { - auto offset = MUST(stream.offset_of("test"sv.bytes())); - EXPECT(!offset.has_value()); - } -} - -TEST_CASE(allocating_memory_stream_offset_of) -{ - Core::Stream::AllocatingMemoryStream stream; - MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes())); - - { - auto offset = MUST(stream.offset_of(" "sv.bytes())); - EXPECT(offset.has_value()); - EXPECT_EQ(offset.value(), 4ul); - } - - { - auto offset = MUST(stream.offset_of("W"sv.bytes())); - EXPECT(offset.has_value()); - EXPECT_EQ(offset.value(), 0ul); - } - - { - auto offset = MUST(stream.offset_of(")"sv.bytes())); - EXPECT(offset.has_value()); - EXPECT_EQ(offset.value(), 22ul); - } - - { - auto offset = MUST(stream.offset_of("-"sv.bytes())); - EXPECT(!offset.has_value()); - } - - MUST(stream.discard(1)); - - { - auto offset = MUST(stream.offset_of("W"sv.bytes())); - EXPECT(!offset.has_value()); - } - - { - auto offset = MUST(stream.offset_of("e"sv.bytes())); - EXPECT(offset.has_value()); - EXPECT_EQ(offset.value(), 0ul); - } -} - -TEST_CASE(allocating_memory_stream_offset_of_oob) -{ - Core::Stream::AllocatingMemoryStream stream; - // NOTE: This test is to make sure that offset_of() doesn't read past the end of the "initialized" data. - // So we have to assume some things about the behaviour of this class: - // - The chunk size is 4096 bytes. - // - A chunk is moved to the end when it's fully read from - // - A free chunk is used as-is, no new ones are allocated if one exists. - - // First, fill exactly one chunk. - for (size_t i = 0; i < 256; ++i) - MUST(stream.write_entire_buffer("AAAAAAAAAAAAAAAA"sv.bytes())); - - // Then discard it all. - MUST(stream.discard(4096)); - // Now we can write into this chunk again, knowing that it's initialized to all 'A's. - MUST(stream.write_entire_buffer("Well Hello Friends! :^)"sv.bytes())); - - { - auto offset = MUST(stream.offset_of("A"sv.bytes())); - EXPECT(!offset.has_value()); - } -} diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index e203c6486f7..917d32b94cc 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include @@ -106,7 +106,7 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule) if (!is(object)) return vm.throw_completion("Expected a Uint8Array argument to parse_webassembly_module"); auto& array = static_cast(*object); - auto stream = Core::Stream::FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors(); auto result = Wasm::Module::parse(*stream); if (result.is_error()) return vm.throw_completion(Wasm::parse_error_to_deprecated_string(result.error())); diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp index 1e81e094ec0..df225e48881 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp @@ -10,8 +10,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -167,7 +167,7 @@ auto CSVExportDialogPage::generate(AK::Stream& stream, GenerationType type) -> E void CSVExportDialogPage::update_preview() { auto maybe_error = [this]() -> ErrorOr { - Core::Stream::AllocatingMemoryStream memory_stream; + AllocatingMemoryStream memory_stream; TRY(generate(memory_stream, GenerationType::Preview)); auto buffer = TRY(memory_stream.read_until_eof()); m_data_preview_text_editor->set_text(StringView(buffer)); diff --git a/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp b/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp index f47c98ee8af..8b09cf579d4 100644 --- a/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp +++ b/Userland/Applications/Spreadsheet/Writers/Test/TestXSVWriter.cpp @@ -7,7 +7,7 @@ #include #include "../CSV.h" -#include +#include TEST_CASE(can_write) { @@ -17,7 +17,7 @@ TEST_CASE(can_write) { 7, 8, 9 }, }; - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; MUST(Writer::CSV::generate(stream, data)); auto expected_output = R"~(1,2,3 @@ -37,7 +37,7 @@ TEST_CASE(can_write_with_header) { 7, 8, 9 }, }; - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; MUST(Writer::CSV::generate(stream, data, { "A"sv, "B\""sv, "C"sv })); auto expected_output = R"~(A,"B""",C @@ -57,7 +57,7 @@ TEST_CASE(can_write_with_different_behaviors) { "We\"ll", "Hello,", " Friends" }, }; - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; MUST(Writer::CSV::generate(stream, data, { "A"sv, "B\""sv, "C"sv }, Writer::WriterBehavior::QuoteOnlyInFieldStart | Writer::WriterBehavior::WriteHeaders)); auto expected_output = R"~(A,B",C diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 6bae382a54d..0d3decd763f 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include namespace Audio { @@ -42,7 +42,7 @@ Result, LoaderError> FlacLoaderPlugin::create(St Result, LoaderError> FlacLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); @@ -78,7 +78,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() // Receive the streaminfo block auto streaminfo = TRY(next_meta_block(*bit_input)); FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO"); - auto streaminfo_data_memory = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(streaminfo.data.bytes())); + auto streaminfo_data_memory = LOADER_TRY(FixedMemoryStream::construct(streaminfo.data.bytes())); auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*streaminfo_data_memory))); // 11.10 METADATA_BLOCK_STREAMINFO @@ -149,7 +149,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() // 11.19. METADATA_BLOCK_PICTURE MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) { - auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); + auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes())); auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); PictureData picture {}; @@ -186,7 +186,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) // 11.13. METADATA_BLOCK_SEEKTABLE MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) { - auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes())); + auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes())); auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); for (size_t i = 0; i < block.length / 18; ++i) { // 11.14. SEEKPOINT diff --git a/Userland/Libraries/LibAudio/FlacLoader.h b/Userland/Libraries/LibAudio/FlacLoader.h index cc7a9703bb2..abb7d34e72f 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.h +++ b/Userland/Libraries/LibAudio/FlacLoader.h @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace Audio { diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 62e534d6de5..f6804fa5a04 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -31,7 +31,7 @@ Result, LoaderError> MP3LoaderPlugin::create(Stri Result, LoaderError> MP3LoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); diff --git a/Userland/Libraries/LibAudio/MP3Loader.h b/Userland/Libraries/LibAudio/MP3Loader.h index 1af97b0ce28..3568745f6e3 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.h +++ b/Userland/Libraries/LibAudio/MP3Loader.h @@ -9,8 +9,8 @@ #include "Loader.h" #include "MP3Types.h" #include +#include #include -#include #include #include @@ -73,7 +73,7 @@ private: AK::Optional m_current_frame; u32 m_current_frame_read; OwnPtr m_bitstream; - Core::Stream::AllocatingMemoryStream m_bit_reservoir; + AllocatingMemoryStream m_bit_reservoir; }; } diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index 91e96887618..4fcff2ae884 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include namespace Audio { @@ -35,7 +35,7 @@ Result, LoaderError> WavLoaderPlugin::create(Stri Result, LoaderError> WavLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); @@ -115,7 +115,7 @@ static ErrorOr read_sample(AK::Stream& stream) LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const { FixedArray samples = LOADER_TRY(FixedArray::create(samples_to_read)); - auto stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(move(data))); + auto stream = LOADER_TRY(FixedMemoryStream::construct(move(data))); switch (m_sample_format) { case PcmSampleFormat::Uint8: diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index 74a43542957..18ad2156453 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -317,9 +317,9 @@ void DeflateDecompressor::close() ErrorOr DeflateDecompressor::decompress_all(ReadonlyBytes bytes) { - auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes)); + auto memory_stream = TRY(FixedMemoryStream::construct(bytes)); auto deflate_stream = TRY(DeflateDecompressor::construct(move(memory_stream))); - Core::Stream::AllocatingMemoryStream output_stream; + AllocatingMemoryStream output_stream; auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); while (!deflate_stream->is_eof()) { @@ -1017,7 +1017,7 @@ ErrorOr DeflateCompressor::final_flush() ErrorOr DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level) { - auto output_stream = TRY(try_make()); + auto output_stream = TRY(try_make()); auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned(*output_stream), compression_level)); TRY(deflate_stream->write_entire_buffer(bytes)); diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index f47b6e2083c..93208319d48 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -8,8 +8,8 @@ #include #include +#include #include -#include namespace Compress { @@ -164,9 +164,9 @@ Optional GzipDecompressor::describe_header(ReadonlyBytes bytes ErrorOr GzipDecompressor::decompress_all(ReadonlyBytes bytes) { - auto memory_stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes)); + auto memory_stream = TRY(FixedMemoryStream::construct(bytes)); auto gzip_stream = make(move(memory_stream)); - Core::Stream::AllocatingMemoryStream output_stream; + AllocatingMemoryStream output_stream; auto buffer = TRY(ByteBuffer::create_uninitialized(4096)); while (!gzip_stream->is_eof()) { @@ -235,7 +235,7 @@ void GzipCompressor::close() ErrorOr GzipCompressor::compress_all(ReadonlyBytes bytes) { - auto output_stream = TRY(try_make()); + auto output_stream = TRY(try_make()); GzipCompressor gzip_stream { MaybeOwned(*output_stream) }; TRY(gzip_stream.write_entire_buffer(bytes)); diff --git a/Userland/Libraries/LibCompress/Zlib.cpp b/Userland/Libraries/LibCompress/Zlib.cpp index feab384f44e..a62d0633a1a 100644 --- a/Userland/Libraries/LibCompress/Zlib.cpp +++ b/Userland/Libraries/LibCompress/Zlib.cpp @@ -5,12 +5,12 @@ */ #include +#include #include #include #include #include #include -#include namespace Compress { @@ -163,7 +163,7 @@ ErrorOr ZlibCompressor::finish() ErrorOr ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level) { - auto output_stream = TRY(try_make()); + auto output_stream = TRY(try_make()); auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned(*output_stream), compression_level)); TRY(zlib_stream->write_entire_buffer(bytes)); diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt index 7485a6a5ae0..473812dae4d 100644 --- a/Userland/Libraries/LibCore/CMakeLists.txt +++ b/Userland/Libraries/LibCore/CMakeLists.txt @@ -13,7 +13,6 @@ set(SOURCES IODevice.cpp LockFile.cpp MappedFile.cpp - MemoryStream.cpp MimeData.cpp NetworkJob.cpp Notifier.cpp diff --git a/Userland/Libraries/LibCore/SOCKSProxyClient.cpp b/Userland/Libraries/LibCore/SOCKSProxyClient.cpp index bde5c113a92..f658e5e2743 100644 --- a/Userland/Libraries/LibCore/SOCKSProxyClient.cpp +++ b/Userland/Libraries/LibCore/SOCKSProxyClient.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include enum class Method : u8 { @@ -122,7 +122,7 @@ ErrorOr send_version_identifier_and_method_selection_message(Core::Stream: ErrorOr send_connect_request_message(Core::Stream::Socket& socket, Core::SOCKSProxyClient::Version version, Core::SOCKSProxyClient::HostOrIPV4 target, int port, Core::SOCKSProxyClient::Command command) { - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; Socks5ConnectRequestHeader header { .version_identifier = to_underlying(version), @@ -218,7 +218,7 @@ ErrorOr send_connect_request_message(Core::Stream::Socket& socket, Core:: ErrorOr send_username_password_authentication_message(Core::Stream::Socket& socket, Core::SOCKSProxyClient::UsernamePasswordAuthenticationData const& auth_data) { - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; u8 version = 0x01; auto size = TRY(stream.write({ &version, sizeof(version) })); diff --git a/Userland/Libraries/LibDNS/Packet.cpp b/Userland/Libraries/LibDNS/Packet.cpp index 211ef368924..d3b39538c6c 100644 --- a/Userland/Libraries/LibDNS/Packet.cpp +++ b/Userland/Libraries/LibDNS/Packet.cpp @@ -9,8 +9,8 @@ #include "Name.h" #include "PacketHeader.h" #include +#include #include -#include #include namespace DNS { @@ -48,7 +48,7 @@ ErrorOr Packet::to_byte_buffer() const header.set_question_count(m_questions.size()); header.set_answer_count(m_answers.size()); - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; TRY(stream.write_value(header)); for (auto& question : m_questions) { diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp index 78c6fca329b..94630d9b194 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp @@ -8,7 +8,7 @@ #include "DwarfInfo.h" #include -#include +#include namespace Debug::Dwarf { @@ -21,7 +21,7 @@ AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset) ErrorOr AbbreviationsMap::populate_map() { - auto abbreviation_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_dwarf_info.abbreviation_data())); + auto abbreviation_stream = TRY(FixedMemoryStream::construct(m_dwarf_info.abbreviation_data())); TRY(abbreviation_stream->discard(m_offset)); Core::Stream::WrapInAKInputStream wrapped_abbreviation_stream { *abbreviation_stream }; diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp index 29aee09a5de..ec91d98def2 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp @@ -9,7 +9,7 @@ #include "DwarfInfo.h" #include #include -#include +#include namespace Debug::Dwarf { @@ -23,7 +23,7 @@ ErrorOr DIE::rehydrate_from(u32 offset, Optional parent_offset) { m_offset = offset; - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); + auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); // Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek(). TRY(stream->seek(m_offset)); Core::Stream::WrapInAKInputStream wrapped_stream { *stream }; @@ -52,7 +52,7 @@ ErrorOr DIE::rehydrate_from(u32 offset, Optional parent_offset) ErrorOr> DIE::get_attribute(Attribute const& attribute) const { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); + auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); // Note: We can't just slice away from the input data here, since get_attribute_value will try to recover the original offset using seek(). TRY(stream->seek(m_data_offset)); diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index 4a7fd797f36..c52810e2913 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include namespace Debug::Dwarf { @@ -47,8 +47,8 @@ ErrorOr DwarfInfo::populate_compilation_units() if (!m_debug_info_data.data()) return {}; - auto debug_info_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_debug_info_data)); - auto line_info_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_debug_line_data)); + auto debug_info_stream = TRY(FixedMemoryStream::construct(m_debug_info_data)); + auto line_info_stream = TRY(FixedMemoryStream::construct(m_debug_line_data)); while (!debug_info_stream->is_eof()) { auto unit_offset = TRY(debug_info_stream->tell()); @@ -321,14 +321,14 @@ ErrorOr DwarfInfo::build_cached_dies() const Vector entries; if (die.compilation_unit().dwarf_version() == 5) { - auto range_lists_stream = TRY(Core::Stream::FixedMemoryStream::construct(debug_range_lists_data())); + auto range_lists_stream = TRY(FixedMemoryStream::construct(debug_range_lists_data())); TRY(range_lists_stream->seek(offset)); AddressRangesV5 address_ranges(move(range_lists_stream), die.compilation_unit()); TRY(address_ranges.for_each_range([&entries](auto range) { entries.empend(range.start, range.end); })); } else { - auto ranges_stream = TRY(Core::Stream::FixedMemoryStream::construct(debug_ranges_data())); + auto ranges_stream = TRY(FixedMemoryStream::construct(debug_ranges_data())); TRY(ranges_stream->seek(offset)); AddressRangesV4 address_ranges(move(ranges_stream), die.compilation_unit()); TRY(address_ranges.for_each_range([&entries](auto range) { diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp index 74ae6f51495..373bf269407 100644 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp @@ -7,14 +7,14 @@ #include "Expression.h" #include -#include +#include #include namespace Debug::Dwarf::Expression { ErrorOr evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs) { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes)); + auto stream = TRY(FixedMemoryStream::construct(bytes)); while (!stream->is_eof()) { auto opcode = TRY(stream->read_value()); diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 9b3f55db43c..6535980ecf6 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -11,9 +11,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -381,7 +381,7 @@ static ErrorOr load_gif_frame_descriptors(GIFLoadingContext& context) if (context.data_size < 32) return Error::from_string_literal("Size too short for GIF frame descriptors"); - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size })); + auto stream = TRY(FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size })); TRY(decode_gif_header(*stream)); @@ -565,7 +565,7 @@ bool GIFImageDecoderPlugin::set_nonvolatile(bool& was_purged) bool GIFImageDecoderPlugin::initialize() { - auto stream_or_error = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size }); + auto stream_or_error = FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size }); if (stream_or_error.is_error()) return false; return !decode_gif_header(*stream_or_error.value()).is_error(); @@ -573,7 +573,7 @@ bool GIFImageDecoderPlugin::initialize() ErrorOr GIFImageDecoderPlugin::sniff(ReadonlyBytes data) { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(data)); + auto stream = TRY(FixedMemoryStream::construct(data)); return !decode_gif_header(*stream).is_error(); } diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 1e4be054995..8f67d4f7464 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -5,14 +5,15 @@ */ #include +#include #include #include #include #include +#include #include #include #include -#include #include #define JPG_INVALID 0X0000 @@ -198,7 +199,7 @@ struct JPGLoadingContext { HuffmanStreamState huffman_stream; i32 previous_dc_values[3] = { 0 }; MacroblockMeta mblock_meta; - OwnPtr stream; + OwnPtr stream; Optional icc_multi_chunk_state; Optional icc_data; @@ -1201,7 +1202,7 @@ static ErrorOr scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingC static ErrorOr decode_header(JPGLoadingContext& context) { if (context.state < JPGLoadingContext::State::HeaderDecoded) { - context.stream = TRY(Core::Stream::FixedMemoryStream::construct({ context.data, context.data_size })); + context.stream = TRY(FixedMemoryStream::construct({ context.data, context.data_size })); if (auto result = parse_header(*context.stream, context); result.is_error()) { context.state = JPGLoadingContext::State::Error; diff --git a/Userland/Libraries/LibGfx/QOILoader.cpp b/Userland/Libraries/LibGfx/QOILoader.cpp index d55a9385447..0ecbed76cfc 100644 --- a/Userland/Libraries/LibGfx/QOILoader.cpp +++ b/Userland/Libraries/LibGfx/QOILoader.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include @@ -202,13 +202,13 @@ bool QOIImageDecoderPlugin::initialize() ErrorOr QOIImageDecoderPlugin::sniff(ReadonlyBytes data) { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct({ data.data(), data.size() })); + auto stream = TRY(FixedMemoryStream::construct({ data.data(), data.size() })); return !decode_qoi_header(*stream).is_error(); } ErrorOr> QOIImageDecoderPlugin::create(ReadonlyBytes data) { - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(data)); + auto stream = TRY(FixedMemoryStream::construct(data)); return adopt_nonnull_own_or_enomem(new (nothrow) QOIImageDecoderPlugin(move(stream))); } diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 8c34e575203..4ae7724a9da 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -8,12 +8,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -70,7 +70,7 @@ static ErrorOr handle_content_encoding(ByteBuffer const& buf, Deprec } else if (content_encoding == "br") { dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!"); - auto bufstream = TRY(Core::Stream::FixedMemoryStream::construct({ buf.data(), buf.size() })); + auto bufstream = TRY(FixedMemoryStream::construct({ buf.data(), buf.size() })); auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; auto uncompressed = TRY(brotli_stream.read_until_eof()); diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index db1b8f33f6a..049234ec6bb 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -1329,7 +1329,7 @@ ErrorOr Editor::cleanup() ErrorOr Editor::refresh_display() { - Core::Stream::AllocatingMemoryStream output_stream; + AllocatingMemoryStream output_stream; ScopeGuard flush_stream { [&] { m_shown_lines = current_prompt_metrics().lines_with_addition(m_cached_buffer_metrics, m_num_columns); diff --git a/Userland/Libraries/LibPDF/DocumentParser.cpp b/Userland/Libraries/LibPDF/DocumentParser.cpp index 507b0e1c330..86f98e79810 100644 --- a/Userland/Libraries/LibPDF/DocumentParser.cpp +++ b/Userland/Libraries/LibPDF/DocumentParser.cpp @@ -6,8 +6,9 @@ */ #include +#include +#include #include -#include #include #include #include @@ -595,7 +596,7 @@ PDFErrorOr DocumentParser::parse_page_offse PDFErrorOr> DocumentParser::parse_all_page_offset_hint_table_entries(PageOffsetHintTable const& hint_table, ReadonlyBytes hint_stream_bytes) { - auto input_stream = TRY(Core::Stream::FixedMemoryStream::construct(hint_stream_bytes)); + auto input_stream = TRY(FixedMemoryStream::construct(hint_stream_bytes)); TRY(input_stream->seek(sizeof(PageOffsetHintTable))); auto bit_stream = TRY(LittleEndianInputBitStream::construct(move(input_stream))); diff --git a/Userland/Libraries/LibProtocol/Request.h b/Userland/Libraries/LibProtocol/Request.h index b42f913bbf9..2995a8d5984 100644 --- a/Userland/Libraries/LibProtocol/Request.h +++ b/Userland/Libraries/LibProtocol/Request.h @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -68,7 +68,7 @@ private: bool m_should_buffer_all_input { false }; struct InternalBufferedData { - Core::Stream::AllocatingMemoryStream payload_stream; + AllocatingMemoryStream payload_stream; HashMap response_headers; Optional response_code; }; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index dba2c43e24d..2a2856e472d 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include @@ -203,7 +203,7 @@ struct ConvertToRaw { { LittleEndian res; ReadonlyBytes bytes { &value, sizeof(float) }; - auto stream = Core::Stream::FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors(); stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors(); return static_cast(res); } @@ -215,7 +215,7 @@ struct ConvertToRaw { { LittleEndian res; ReadonlyBytes bytes { &value, sizeof(double) }; - auto stream = Core::Stream::FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(bytes).release_value_but_fixme_should_propagate_errors(); stream->read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors(); return static_cast(res); } @@ -253,7 +253,7 @@ template T BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian value; - auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); auto maybe_error = stream->read_entire_buffer(value.bytes()); if (maybe_error.is_error()) { dbgln("Read from {} failed", data.data()); @@ -266,7 +266,7 @@ template<> float BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian raw_value; - auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); auto maybe_error = stream->read_entire_buffer(raw_value.bytes()); if (maybe_error.is_error()) m_trap = Trap { "Read from memory failed" }; @@ -277,7 +277,7 @@ template<> double BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian raw_value; - auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); auto maybe_error = stream->read_entire_buffer(raw_value.bytes()); if (maybe_error.is_error()) m_trap = Trap { "Read from memory failed" }; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp index 43cc915617a..74f54587c9b 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include #include @@ -86,7 +86,7 @@ Result Configuration::execute(Interpreter& interpreter) void Configuration::dump_stack() { auto print_value = [](CheckedFormatString format, Ts... vs) { - Core::Stream::AllocatingMemoryStream memory_stream; + AllocatingMemoryStream memory_stream; Printer { memory_stream }.print(vs...); auto buffer = ByteBuffer::create_uninitialized(memory_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors(); memory_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors(); diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 46b9dedb742..09cc7f3dc9b 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include #include namespace Wasm { @@ -261,7 +261,7 @@ ParseResult BlockType::parse(AK::Stream& stream) return BlockType {}; { - auto value_stream = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { &kind, 1 }).release_value_but_fixme_should_propagate_errors(); + auto value_stream = FixedMemoryStream::construct(ReadonlyBytes { &kind, 1 }).release_value_but_fixme_should_propagate_errors(); if (auto value_type = ValueType::parse(*value_stream); !value_type.is_error()) return BlockType { value_type.release_value() }; } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index b37ff741adb..bf6dc243ae1 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -11,8 +11,8 @@ #include "WebAssemblyModulePrototype.h" #include "WebAssemblyTableObject.h" #include "WebAssemblyTablePrototype.h" +#include #include -#include #include #include #include @@ -121,7 +121,7 @@ JS::ThrowCompletionOr parse_module(JS::VM& vm, JS::Object* buffer_object } else { return vm.throw_completion("Not a BufferSource"); } - auto stream = Core::Stream::FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); auto module_result = Wasm::Module::parse(*stream); if (module_result.is_error()) { // FIXME: Throw CompileError instead. diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index 0804a033ec0..269582af5f2 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -336,7 +336,7 @@ ErrorOr Client::handle_directory_listing(String const& requested_path, Str builder.append("\n"sv); auto response = builder.to_deprecated_string(); - auto stream = TRY(Core::Stream::FixedMemoryStream::construct(response.bytes())); + auto stream = TRY(FixedMemoryStream::construct(response.bytes())); return send_response(*stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() }); } diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index 55522038b6c..be2195db00b 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -7,13 +7,13 @@ #include "AST.h" #include "Shell.h" #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -1641,7 +1641,7 @@ void Execute::for_each_entry(RefPtr shell, Function #include #include -#include #include #include #include @@ -343,7 +342,7 @@ public: private: HTTPHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr socket, ByteBuffer&& stream_backing_buffer) : m_stream_backing_buffer(move(stream_backing_buffer)) - , m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) , m_socket(move(socket)) , m_job(HTTP::Job::construct(move(request), *m_output_stream)) { @@ -369,7 +368,7 @@ public: Optional m_response_code; ByteBuffer m_stream_backing_buffer; - NonnullOwnPtr m_output_stream; + NonnullOwnPtr m_output_stream; NonnullOwnPtr m_socket; NonnullRefPtr m_job; HashMap m_response_headers; @@ -422,7 +421,7 @@ public: private: HTTPSHeadlessRequest(HTTP::HttpRequest&& request, NonnullOwnPtr socket, ByteBuffer&& stream_backing_buffer) : m_stream_backing_buffer(move(stream_backing_buffer)) - , m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) , m_socket(move(socket)) , m_job(HTTP::HttpsJob::construct(move(request), *m_output_stream)) { @@ -448,7 +447,7 @@ public: Optional m_response_code; ByteBuffer m_stream_backing_buffer; - NonnullOwnPtr m_output_stream; + NonnullOwnPtr m_output_stream; NonnullOwnPtr m_socket; NonnullRefPtr m_job; HashMap m_response_headers; @@ -491,7 +490,7 @@ public: private: GeminiHeadlessRequest(Gemini::GeminiRequest&& request, NonnullOwnPtr socket, ByteBuffer&& stream_backing_buffer) : m_stream_backing_buffer(move(stream_backing_buffer)) - , m_output_stream(Core::Stream::FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) , m_socket(move(socket)) , m_job(Gemini::Job::construct(move(request), *m_output_stream)) { @@ -517,7 +516,7 @@ public: Optional m_response_code; ByteBuffer m_stream_backing_buffer; - NonnullOwnPtr m_output_stream; + NonnullOwnPtr m_output_stream; NonnullOwnPtr m_socket; NonnullRefPtr m_job; HashMap m_response_headers; diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index e08a2484b1a..0ec6e4ca764 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -5,10 +5,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include -#include #include #include #include @@ -252,7 +252,7 @@ static Optional parse(StringView filename) return {}; } - auto stream = Core::Stream::FixedMemoryStream::construct(ReadonlyBytes { result.value()->data(), result.value()->size() }).release_value_but_fixme_should_propagate_errors(); + auto stream = FixedMemoryStream::construct(ReadonlyBytes { result.value()->data(), result.value()->size() }).release_value_but_fixme_should_propagate_errors(); auto parse_result = Wasm::Module::parse(*stream); if (parse_result.is_error()) { warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!"); @@ -398,7 +398,7 @@ ErrorOr serenity_main(Main::Arguments arguments) StringBuilder argument_builder; bool first = true; for (auto& argument : arguments) { - Core::Stream::AllocatingMemoryStream stream; + AllocatingMemoryStream stream; Wasm::Printer { stream }.print(argument); if (first) first = false;