diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp index d4c9659b3a5..10c35f0bf01 100644 --- a/AK/MemoryStream.cpp +++ b/AK/MemoryStream.cpp @@ -23,16 +23,6 @@ FixedMemoryStream::FixedMemoryStream(ReadonlyBytes bytes) { } -ErrorOr> FixedMemoryStream::construct(Bytes bytes) -{ - return adopt_nonnull_own_or_enomem(new (nothrow) FixedMemoryStream(bytes)); -} - -ErrorOr> FixedMemoryStream::construct(ReadonlyBytes bytes) -{ - return adopt_nonnull_own_or_enomem(new (nothrow) FixedMemoryStream(bytes)); -} - bool FixedMemoryStream::is_eof() const { return m_offset >= m_bytes.size(); diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index b81310b0634..fa4961b77b4 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -16,8 +16,8 @@ namespace AK { /// using a single read/write head. class FixedMemoryStream final : public SeekableStream { public: - static ErrorOr> construct(Bytes bytes); - static ErrorOr> construct(ReadonlyBytes bytes); + explicit FixedMemoryStream(Bytes bytes); + explicit FixedMemoryStream(ReadonlyBytes bytes); virtual bool is_eof() const override; virtual bool is_open() const override; @@ -36,9 +36,6 @@ public: size_t remaining() const; private: - explicit FixedMemoryStream(Bytes bytes); - explicit FixedMemoryStream(ReadonlyBytes bytes); - Bytes m_bytes; size_t m_offset { 0 }; bool m_writing_enabled { true }; diff --git a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp index e3dbbf1be47..db75f5c3fd5 100644 --- a/Meta/Lagom/Fuzzers/FuzzBrotli.cpp +++ b/Meta/Lagom/Fuzzers/FuzzBrotli.cpp @@ -10,14 +10,9 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - auto bufstream_result = FixedMemoryStream::construct({ data, size }); - if (bufstream_result.is_error()) { - dbgln("MemoryStream::construct() failed."); - return 0; - } - auto bufstream = bufstream_result.release_value(); + FixedMemoryStream bufstream { { data, size } }; - auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; + auto brotli_stream = Compress::BrotliDecompressionStream { bufstream }; (void)brotli_stream.read_until_eof(); return 0; diff --git a/Meta/Lagom/Fuzzers/FuzzTar.cpp b/Meta/Lagom/Fuzzers/FuzzTar.cpp index 50be8ec74f2..88c81139dd9 100644 --- a/Meta/Lagom/Fuzzers/FuzzTar.cpp +++ b/Meta/Lagom/Fuzzers/FuzzTar.cpp @@ -12,7 +12,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { - auto input_stream_or_error = FixedMemoryStream::construct({ data, size }); + auto input_stream_or_error = try_make(ReadonlyBytes { 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 aaa4dfabca3..7a677dd6d53 100644 --- a/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzWasmParser.cpp @@ -12,10 +12,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { ReadonlyBytes bytes { data, size }; - auto stream_or_error = FixedMemoryStream::construct(bytes); - if (stream_or_error.is_error()) - return 0; - auto stream = stream_or_error.release_value(); - [[maybe_unused]] auto result = Wasm::Module::parse(*stream); + FixedMemoryStream stream { bytes }; + [[maybe_unused]] auto result = Wasm::Module::parse(stream); return 0; } diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index 9dc65385afd..9d58aa0ff38 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -586,8 +586,8 @@ public: static ErrorOr> decode_message(ReadonlyBytes buffer, [[maybe_unused]] Core::Stream::LocalSocket& socket) { - auto stream = TRY(FixedMemoryStream::construct(buffer)); - auto message_endpoint_magic = TRY(stream->read_value());)~~~"); + FixedMemoryStream stream { buffer }; + auto message_endpoint_magic = TRY(stream.read_value());)~~~"); generator.append(R"~~~( if (message_endpoint_magic != @endpoint.magic@) {)~~~"); @@ -599,7 +599,7 @@ public: return Error::from_string_literal("Endpoint magic number mismatch, not my message!"); } - auto message_id = TRY(stream->read_value());)~~~"); + auto message_id = TRY(stream.read_value());)~~~"); generator.appendln(R"~~~( switch (message_id) {)~~~"); @@ -613,7 +613,7 @@ public: message_generator.append(R"~~~( case (int)Messages::@endpoint.name@::MessageID::@message.pascal_name@: - return TRY(Messages::@endpoint.name@::@message.pascal_name@::decode(*stream, socket));)~~~"); + return TRY(Messages::@endpoint.name@::@message.pascal_name@::decode(stream, socket));)~~~"); }; do_decode_message(message.name); diff --git a/Tests/AK/TestLEB128.cpp b/Tests/AK/TestLEB128.cpp index 1e7c68024e3..996a3cbb9aa 100644 --- a/Tests/AK/TestLEB128.cpp +++ b/Tests/AK/TestLEB128.cpp @@ -14,18 +14,18 @@ TEST_CASE(single_byte) u32 output = {}; i32 output_signed = {}; u8 buf[] = { 0x00 }; - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { buf, sizeof(buf) })); + FixedMemoryStream stream { ReadonlyBytes { buf, sizeof(buf) } }; // less than/eq 0b0011_1111, signed == unsigned == raw byte for (u8 i = 0u; i <= 0x3F; ++i) { buf[0] = i; - MUST(stream->seek(0)); - output = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output = MUST(stream.read_value>()); EXPECT_EQ(output, i); - MUST(stream->seek(0)); - output_signed = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output_signed = MUST(stream.read_value>()); EXPECT_EQ(output_signed, i); } @@ -33,23 +33,23 @@ TEST_CASE(single_byte) for (u8 i = 0x40u; i < 0x80; ++i) { buf[0] = i; - MUST(stream->seek(0)); - output = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output = MUST(stream.read_value>()); EXPECT_EQ(output, i); - MUST(stream->seek(0)); - output_signed = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output_signed = MUST(stream.read_value>()); EXPECT_EQ(output_signed, (i | (-1 & (~0x3F)))); } // MSB set, but input too short for (u16 i = 0x80; i <= 0xFF; ++i) { buf[0] = static_cast(i); - MUST(stream->seek(0)); - EXPECT(stream->read_value>().is_error()); + MUST(stream.seek(0)); + EXPECT(stream.read_value>().is_error()); - MUST(stream->seek(0)); - EXPECT(stream->read_value>().is_error()); + MUST(stream.seek(0)); + EXPECT(stream.read_value>().is_error()); } } @@ -58,7 +58,7 @@ TEST_CASE(two_bytes) u32 output = {}; i32 output_signed = {}; u8 buf[] = { 0x00, 0x1 }; - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { buf, sizeof(buf) })); + FixedMemoryStream stream { ReadonlyBytes { buf, sizeof(buf) } }; // Only test with first byte expecting more, otherwise equivalent to single byte case for (u16 i = 0x80; i <= 0xFF; ++i) { @@ -68,12 +68,12 @@ TEST_CASE(two_bytes) for (u8 j = 0u; j <= 0x3F; ++j) { buf[1] = j; - MUST(stream->seek(0)); - output = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output = MUST(stream.read_value>()); EXPECT_EQ(output, (static_cast(j) << 7) + (i & 0x7F)); - MUST(stream->seek(0)); - output_signed = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output_signed = MUST(stream.read_value>()); EXPECT_EQ(output_signed, (static_cast(j) << 7) + (i & 0x7F)); } @@ -81,12 +81,12 @@ TEST_CASE(two_bytes) for (u8 j = 0x40u; j < 0x80; ++j) { buf[1] = j; - MUST(stream->seek(0)); - output = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output = MUST(stream.read_value>()); EXPECT_EQ(output, (static_cast(j) << 7) + (i & 0x7F)); - MUST(stream->seek(0)); - output_signed = MUST(stream->read_value>()); + MUST(stream.seek(0)); + output_signed = MUST(stream.read_value>()); EXPECT_EQ(output_signed, ((static_cast(j) << 7) + (i & 0x7F)) | (-1 & (~0x3FFF))); } @@ -94,11 +94,11 @@ TEST_CASE(two_bytes) for (u16 j = 0x80; j <= 0xFF; ++j) { buf[1] = static_cast(j); - MUST(stream->seek(0)); - EXPECT(stream->read_value>().is_error()); + MUST(stream.seek(0)); + EXPECT(stream.read_value>().is_error()); - MUST(stream->seek(0)); - EXPECT(stream->read_value>().is_error()); + MUST(stream.seek(0)); + EXPECT(stream.read_value>().is_error()); } } } @@ -107,22 +107,22 @@ TEST_CASE(overflow_sizeof_output_unsigned) { u8 u32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x10 }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { u32_max_plus_one, sizeof(u32_max_plus_one) })); - EXPECT(stream->read_value>().is_error()); + FixedMemoryStream stream { ReadonlyBytes { u32_max_plus_one, sizeof(u32_max_plus_one) } }; + EXPECT(stream.read_value>().is_error()); - MUST(stream->seek(0)); - u64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + u64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, static_cast(NumericLimits::max()) + 1); } u8 u32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x0F }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { u32_max, sizeof(u32_max) })); - u32 out = MUST(stream->read_value>()); + FixedMemoryStream stream { ReadonlyBytes { u32_max, sizeof(u32_max) } }; + u32 out = MUST(stream.read_value>()); EXPECT_EQ(out, NumericLimits::max()); - MUST(stream->seek(0)); - u64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + u64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, NumericLimits::max()); } } @@ -131,43 +131,43 @@ TEST_CASE(overflow_sizeof_output_signed) { u8 i32_max_plus_one[] = { 0x80, 0x80, 0x80, 0x80, 0x08 }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_max_plus_one, sizeof(i32_max_plus_one) })); - EXPECT(stream->read_value>().is_error()); + FixedMemoryStream stream { ReadonlyBytes { i32_max_plus_one, sizeof(i32_max_plus_one) } }; + EXPECT(stream.read_value>().is_error()); - MUST(stream->seek(0)); - i64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + i64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, static_cast(NumericLimits::max()) + 1); } u8 i32_max[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x07 }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_max, sizeof(i32_max) })); - i32 out = MUST(stream->read_value>()); + FixedMemoryStream stream { ReadonlyBytes { i32_max, sizeof(i32_max) } }; + i32 out = MUST(stream.read_value>()); EXPECT_EQ(out, NumericLimits::max()); - MUST(stream->seek(0)); - i64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + i64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, NumericLimits::max()); } u8 i32_min_minus_one[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0x77 }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_min_minus_one, sizeof(i32_min_minus_one) })); - EXPECT(stream->read_value>().is_error()); + FixedMemoryStream stream { ReadonlyBytes { i32_min_minus_one, sizeof(i32_min_minus_one) } }; + EXPECT(stream.read_value>().is_error()); - MUST(stream->seek(0)); - i64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + i64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, static_cast(NumericLimits::min()) - 1); } u8 i32_min[] = { 0x80, 0x80, 0x80, 0x80, 0x78 }; { - auto stream = MUST(FixedMemoryStream::construct(ReadonlyBytes { i32_min, sizeof(i32_min) })); - i32 out = MUST(stream->read_value>()); + FixedMemoryStream stream { ReadonlyBytes { i32_min, sizeof(i32_min) } }; + i32 out = MUST(stream.read_value>()); EXPECT_EQ(out, NumericLimits::min()); - MUST(stream->seek(0)); - i64 out64 = MUST(stream->read_value>()); + MUST(stream.seek(0)); + i64 out64 = MUST(stream.read_value>()); EXPECT_EQ(out64, NumericLimits::min()); } } diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp index 8e50430d22d..e51092e5b38 100644 --- a/Tests/LibCompress/TestDeflate.cpp +++ b/Tests/LibCompress/TestDeflate.cpp @@ -28,7 +28,7 @@ TEST_CASE(canonical_code_simple) }; auto const huffman = Compress::CanonicalCode::from_bytes(code).value(); - auto memory_stream = MUST(FixedMemoryStream::construct(input)); + auto memory_stream = MUST(try_make(input)); LittleEndianInputBitStream bit_stream { 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(FixedMemoryStream::construct(input)); + auto memory_stream = MUST(try_make(input)); LittleEndianInputBitStream bit_stream { move(memory_stream) }; for (size_t idx = 0; idx < 12; ++idx) diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index 917d32b94cc..1cbeff367a6 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -106,8 +106,8 @@ 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 = FixedMemoryStream::construct(array.data()).release_value_but_fixme_should_propagate_errors(); - auto result = Wasm::Module::parse(*stream); + FixedMemoryStream stream { array.data() }; + 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/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index d2ba2ed2cb7..26036610d4c 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -42,7 +42,7 @@ Result, LoaderError> FlacLoaderPlugin::create(St Result, LoaderError> FlacLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); @@ -78,8 +78,8 @@ 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(FixedMemoryStream::construct(streaminfo.data.bytes())); - BigEndianInputBitStream streaminfo_data { MaybeOwned(*streaminfo_data_memory) }; + FixedMemoryStream streaminfo_data_memory { streaminfo.data.bytes() }; + BigEndianInputBitStream streaminfo_data { MaybeOwned(streaminfo_data_memory) }; // 11.10 METADATA_BLOCK_STREAMINFO m_min_block_size = LOADER_TRY(streaminfo_data.read_bits(16)); @@ -149,8 +149,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header() // 11.19. METADATA_BLOCK_PICTURE MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) { - auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes())); - BigEndianInputBitStream picture_block_bytes { MaybeOwned(*memory_stream) }; + FixedMemoryStream memory_stream { block.data.bytes() }; + BigEndianInputBitStream picture_block_bytes { MaybeOwned(memory_stream) }; PictureData picture {}; @@ -158,13 +158,13 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) auto const mime_string_length = LOADER_TRY(picture_block_bytes.read_bits(32)); // Note: We are seeking before reading the value to ensure that we stayed inside buffer's size. - auto offset_before_seeking = memory_stream->offset(); - LOADER_TRY(memory_stream->seek(mime_string_length, SeekMode::FromCurrentPosition)); + auto offset_before_seeking = memory_stream.offset(); + LOADER_TRY(memory_stream.seek(mime_string_length, SeekMode::FromCurrentPosition)); picture.mime_string = { block.data.bytes().data() + offset_before_seeking, (size_t)mime_string_length }; auto const description_string_length = LOADER_TRY(picture_block_bytes.read_bits(32)); - offset_before_seeking = memory_stream->offset(); - LOADER_TRY(memory_stream->seek(description_string_length, SeekMode::FromCurrentPosition)); + offset_before_seeking = memory_stream.offset(); + LOADER_TRY(memory_stream.seek(description_string_length, SeekMode::FromCurrentPosition)); picture.description_string = Vector { Span { reinterpret_cast(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } }; picture.width = LOADER_TRY(picture_block_bytes.read_bits(32)); @@ -174,8 +174,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) picture.colors = LOADER_TRY(picture_block_bytes.read_bits(32)); auto const picture_size = LOADER_TRY(picture_block_bytes.read_bits(32)); - offset_before_seeking = memory_stream->offset(); - LOADER_TRY(memory_stream->seek(picture_size, SeekMode::FromCurrentPosition)); + offset_before_seeking = memory_stream.offset(); + LOADER_TRY(memory_stream.seek(picture_size, SeekMode::FromCurrentPosition)); picture.data = Vector { Span { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } }; m_pictures.append(move(picture)); @@ -186,8 +186,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block) // 11.13. METADATA_BLOCK_SEEKTABLE MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block) { - auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes())); - BigEndianInputBitStream seektable_bytes { MaybeOwned(*memory_stream) }; + FixedMemoryStream memory_stream { block.data.bytes() }; + BigEndianInputBitStream seektable_bytes { MaybeOwned(memory_stream) }; for (size_t i = 0; i < block.length / 18; ++i) { // 11.14. SEEKPOINT FlacSeekPoint seekpoint { diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 693f6805275..59a90cf2339 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(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp index 4fcff2ae884..f222cd4cfc9 100644 --- a/Userland/Libraries/LibAudio/WavLoader.cpp +++ b/Userland/Libraries/LibAudio/WavLoader.cpp @@ -35,7 +35,7 @@ Result, LoaderError> WavLoaderPlugin::create(Stri Result, LoaderError> WavLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); @@ -115,23 +115,23 @@ 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(FixedMemoryStream::construct(move(data))); + FixedMemoryStream stream { data }; switch (m_sample_format) { case PcmSampleFormat::Uint8: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; case PcmSampleFormat::Int16: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; case PcmSampleFormat::Int24: - TRY(read_samples_from_stream(*stream, read_sample_int24, samples)); + TRY(read_samples_from_stream(stream, read_sample_int24, samples)); break; case PcmSampleFormat::Float32: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; case PcmSampleFormat::Float64: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; default: VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index f6c296635fc..0dc24c55a1b 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -317,7 +317,7 @@ void DeflateDecompressor::close() ErrorOr DeflateDecompressor::decompress_all(ReadonlyBytes bytes) { - auto memory_stream = TRY(FixedMemoryStream::construct(bytes)); + auto memory_stream = TRY(try_make(bytes)); auto deflate_stream = TRY(DeflateDecompressor::construct(move(memory_stream))); AllocatingMemoryStream output_stream; diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index 93208319d48..3fcb2adb22b 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -164,7 +164,7 @@ Optional GzipDecompressor::describe_header(ReadonlyBytes bytes ErrorOr GzipDecompressor::decompress_all(ReadonlyBytes bytes) { - auto memory_stream = TRY(FixedMemoryStream::construct(bytes)); + auto memory_stream = TRY(try_make(bytes)); auto gzip_stream = make(move(memory_stream)); AllocatingMemoryStream output_stream; diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp index e8c263ffa66..67f926a43e5 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp @@ -21,19 +21,19 @@ AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset) ErrorOr AbbreviationsMap::populate_map() { - auto abbreviation_stream = TRY(FixedMemoryStream::construct(m_dwarf_info.abbreviation_data())); - TRY(abbreviation_stream->discard(m_offset)); + FixedMemoryStream abbreviation_stream { m_dwarf_info.abbreviation_data() }; + TRY(abbreviation_stream.discard(m_offset)); - while (!abbreviation_stream->is_eof()) { - size_t abbreviation_code = TRY(abbreviation_stream->read_value>()); + while (!abbreviation_stream.is_eof()) { + size_t abbreviation_code = TRY(abbreviation_stream.read_value>()); // An abbreviation code of 0 marks the end of the // abbreviations for a given compilation unit if (abbreviation_code == 0) break; - size_t tag = TRY(abbreviation_stream->read_value>()); + size_t tag = TRY(abbreviation_stream.read_value>()); - auto has_children = TRY(abbreviation_stream->read_value()); + auto has_children = TRY(abbreviation_stream.read_value()); AbbreviationEntry abbreviation_entry {}; abbreviation_entry.tag = static_cast(tag); @@ -41,14 +41,14 @@ ErrorOr AbbreviationsMap::populate_map() AttributeSpecification current_attribute_specification {}; do { - size_t attribute_value = TRY(abbreviation_stream->read_value>()); - size_t form_value = TRY(abbreviation_stream->read_value>()); + size_t attribute_value = TRY(abbreviation_stream.read_value>()); + size_t form_value = TRY(abbreviation_stream.read_value>()); current_attribute_specification.attribute = static_cast(attribute_value); current_attribute_specification.form = static_cast(form_value); if (current_attribute_specification.form == AttributeDataForm::ImplicitConst) { - ssize_t data_value = TRY(abbreviation_stream->read_value>()); + ssize_t data_value = TRY(abbreviation_stream.read_value>()); current_attribute_specification.value = data_value; } diff --git a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h index 4f4a82985fa..7849b9778db 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h +++ b/Userland/Libraries/LibDebug/Dwarf/AddressRanges.h @@ -24,6 +24,7 @@ class AddressRangesV5 { AK_MAKE_NONMOVABLE(AddressRangesV5); public: + // FIXME: This should be fine with using a non-owned stream. AddressRangesV5(NonnullOwnPtr range_lists_stream, CompilationUnit const& compilation_unit); ErrorOr for_each_range(Function); diff --git a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp index a9e0cef9799..2d2c5154c1e 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DIE.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DIE.cpp @@ -23,11 +23,11 @@ ErrorOr DIE::rehydrate_from(u32 offset, Optional parent_offset) { m_offset = offset; - auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); + FixedMemoryStream stream { 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)); - m_abbreviation_code = TRY(stream->read_value>()); - m_data_offset = TRY(stream->tell()); + TRY(stream.seek(m_offset)); + m_abbreviation_code = TRY(stream.read_value>()); + m_data_offset = TRY(stream.tell()); if (m_abbreviation_code == 0) { // An abbreviation code of 0 ( = null DIE entry) means the end of a chain of siblings @@ -41,25 +41,25 @@ ErrorOr DIE::rehydrate_from(u32 offset, Optional parent_offset) // We iterate the attributes data only to calculate this DIE's size for (auto& attribute_spec : abbreviation_info->attribute_specifications) { - TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, *stream, &m_compilation_unit)); + TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit)); } } - m_size = TRY(stream->tell()) - m_offset; + m_size = TRY(stream.tell()) - m_offset; m_parent_offset = parent_offset; return {}; } ErrorOr> DIE::get_attribute(Attribute const& attribute) const { - auto stream = TRY(FixedMemoryStream::construct(m_compilation_unit.dwarf_info().debug_info_data())); + FixedMemoryStream stream { 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)); + TRY(stream.seek(m_data_offset)); auto abbreviation_info = m_compilation_unit.abbreviations_map().get(m_abbreviation_code); VERIFY(abbreviation_info); for (auto const& attribute_spec : abbreviation_info->attribute_specifications) { - auto value = TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, *stream, &m_compilation_unit)); + auto value = TRY(m_compilation_unit.dwarf_info().get_attribute_value(attribute_spec.form, attribute_spec.value, stream, &m_compilation_unit)); if (attribute_spec.attribute == attribute) { return value; } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index b4b519cdaf1..6d52ecf8b7c 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -47,35 +47,35 @@ ErrorOr DwarfInfo::populate_compilation_units() if (!m_debug_info_data.data()) return {}; - auto debug_info_stream = TRY(FixedMemoryStream::construct(m_debug_info_data)); - auto line_info_stream = TRY(FixedMemoryStream::construct(m_debug_line_data)); + FixedMemoryStream debug_info_stream { m_debug_info_data }; + FixedMemoryStream line_info_stream { m_debug_line_data }; - while (!debug_info_stream->is_eof()) { - auto unit_offset = TRY(debug_info_stream->tell()); + while (!debug_info_stream.is_eof()) { + auto unit_offset = TRY(debug_info_stream.tell()); - auto compilation_unit_header = TRY(debug_info_stream->read_value()); + auto compilation_unit_header = TRY(debug_info_stream.read_value()); VERIFY(compilation_unit_header.common.version <= 5); VERIFY(compilation_unit_header.address_size() == sizeof(FlatPtr)); u32 length_after_header = compilation_unit_header.length() - (compilation_unit_header.header_size() - offsetof(CompilationUnitHeader, common.version)); - auto line_program = make(*this, *line_info_stream); + auto line_program = make(*this, line_info_stream); // HACK: Clang generates line programs for embedded resource assembly files, but not compile units. // Meaning that for graphical applications, some line info data would be unread, triggering the assertion below. // As a fix, we don't create compilation units for line programs that come from resource files. #if defined(AK_COMPILER_CLANG) if (line_program->looks_like_embedded_resource()) { - TRY(debug_info_stream->seek(unit_offset)); + TRY(debug_info_stream.seek(unit_offset)); } else #endif { m_compilation_units.append(make(*this, unit_offset, compilation_unit_header, move(line_program))); - TRY(debug_info_stream->discard(length_after_header)); + TRY(debug_info_stream.discard(length_after_header)); } } - VERIFY(line_info_stream->is_eof()); + VERIFY(line_info_stream.is_eof()); return {}; } @@ -300,14 +300,14 @@ ErrorOr DwarfInfo::build_cached_dies() const Vector entries; if (die.compilation_unit().dwarf_version() == 5) { - auto range_lists_stream = TRY(FixedMemoryStream::construct(debug_range_lists_data())); + auto range_lists_stream = TRY(try_make(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(FixedMemoryStream::construct(debug_ranges_data())); + auto ranges_stream = TRY(try_make(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 373bf269407..30f45f6e4be 100644 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp @@ -14,10 +14,10 @@ namespace Debug::Dwarf::Expression { ErrorOr evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs) { - auto stream = TRY(FixedMemoryStream::construct(bytes)); + FixedMemoryStream stream { bytes }; - while (!stream->is_eof()) { - auto opcode = TRY(stream->read_value()); + while (!stream.is_eof()) { + auto opcode = TRY(stream.read_value()); switch (static_cast(opcode)) { diff --git a/Userland/Libraries/LibGfx/GIFLoader.cpp b/Userland/Libraries/LibGfx/GIFLoader.cpp index 6535980ecf6..dbf76239b13 100644 --- a/Userland/Libraries/LibGfx/GIFLoader.cpp +++ b/Userland/Libraries/LibGfx/GIFLoader.cpp @@ -381,21 +381,21 @@ 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(FixedMemoryStream::construct(ReadonlyBytes { context.data, context.data_size })); + FixedMemoryStream stream { { context.data, context.data_size } }; - TRY(decode_gif_header(*stream)); + TRY(decode_gif_header(stream)); - context.logical_screen.width = TRY(stream->read_value>()); - context.logical_screen.height = TRY(stream->read_value>()); + context.logical_screen.width = TRY(stream.read_value>()); + context.logical_screen.height = TRY(stream.read_value>()); if (context.logical_screen.width > maximum_width_for_decoded_images || context.logical_screen.height > maximum_height_for_decoded_images) { dbgln("This GIF is too large for comfort: {}x{}", context.logical_screen.width, context.logical_screen.height); return Error::from_string_literal("This GIF is too large for comfort"); } - auto gcm_info = TRY(stream->read_value()); - context.background_color_index = TRY(stream->read_value()); - [[maybe_unused]] auto pixel_aspect_ratio = TRY(stream->read_value()); + auto gcm_info = TRY(stream.read_value()); + context.background_color_index = TRY(stream.read_value()); + [[maybe_unused]] auto pixel_aspect_ratio = TRY(stream.read_value()); u8 bits_per_pixel = (gcm_info & 7) + 1; int color_map_entry_count = 1; @@ -403,29 +403,29 @@ static ErrorOr load_gif_frame_descriptors(GIFLoadingContext& context) color_map_entry_count *= 2; for (int i = 0; i < color_map_entry_count; ++i) { - u8 r = TRY(stream->read_value()); - u8 g = TRY(stream->read_value()); - u8 b = TRY(stream->read_value()); + u8 r = TRY(stream.read_value()); + u8 g = TRY(stream.read_value()); + u8 b = TRY(stream.read_value()); context.logical_screen.color_map[i] = { r, g, b }; } NonnullOwnPtr current_image = make(); for (;;) { - u8 sentinel = TRY(stream->read_value()); + u8 sentinel = TRY(stream.read_value()); if (sentinel == '!') { - u8 extension_type = TRY(stream->read_value()); + u8 extension_type = TRY(stream.read_value()); u8 sub_block_length = 0; Vector sub_block {}; for (;;) { - sub_block_length = TRY(stream->read_value()); + sub_block_length = TRY(stream.read_value()); if (sub_block_length == 0) break; TRY(sub_block.try_resize(sub_block.size() + sub_block_length)); - TRY(stream->read_entire_buffer(sub_block.span().slice_from_end(sub_block_length))); + TRY(stream.read_entire_buffer(sub_block.span().slice_from_end(sub_block_length))); } if (extension_type == 0xF9) { @@ -471,12 +471,12 @@ static ErrorOr load_gif_frame_descriptors(GIFLoadingContext& context) context.images.append(move(current_image)); auto& image = context.images.last(); - image.x = TRY(stream->read_value>()); - image.y = TRY(stream->read_value>()); - image.width = TRY(stream->read_value>()); - image.height = TRY(stream->read_value>()); + image.x = TRY(stream.read_value>()); + image.y = TRY(stream.read_value>()); + image.width = TRY(stream.read_value>()); + image.height = TRY(stream.read_value>()); - auto packed_fields = TRY(stream->read_value()); + auto packed_fields = TRY(stream.read_value()); image.use_global_color_map = !(packed_fields & 0x80); image.interlaced = (packed_fields & 0x40) != 0; @@ -485,24 +485,24 @@ static ErrorOr load_gif_frame_descriptors(GIFLoadingContext& context) size_t local_color_table_size = AK::exp2((packed_fields & 7) + 1); for (size_t i = 0; i < local_color_table_size; ++i) { - u8 r = TRY(stream->read_value()); - u8 g = TRY(stream->read_value()); - u8 b = TRY(stream->read_value()); + u8 r = TRY(stream.read_value()); + u8 g = TRY(stream.read_value()); + u8 b = TRY(stream.read_value()); image.color_map[i] = { r, g, b }; } } - image.lzw_min_code_size = TRY(stream->read_value()); + image.lzw_min_code_size = TRY(stream.read_value()); u8 lzw_encoded_bytes_expected = 0; for (;;) { - lzw_encoded_bytes_expected = TRY(stream->read_value()); + lzw_encoded_bytes_expected = TRY(stream.read_value()); if (lzw_encoded_bytes_expected == 0) break; Array buffer; - TRY(stream->read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected))); + TRY(stream.read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected))); for (int i = 0; i < lzw_encoded_bytes_expected; ++i) { image.lzw_encoded_bytes.append(buffer[i]); @@ -565,16 +565,14 @@ bool GIFImageDecoderPlugin::set_nonvolatile(bool& was_purged) bool GIFImageDecoderPlugin::initialize() { - 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(); + FixedMemoryStream stream { { m_context->data, m_context->data_size } }; + return !decode_gif_header(stream).is_error(); } ErrorOr GIFImageDecoderPlugin::sniff(ReadonlyBytes data) { - auto stream = TRY(FixedMemoryStream::construct(data)); - return !decode_gif_header(*stream).is_error(); + FixedMemoryStream stream { data }; + return !decode_gif_header(stream).is_error(); } ErrorOr> GIFImageDecoderPlugin::create(ReadonlyBytes data) diff --git a/Userland/Libraries/LibGfx/ICOLoader.cpp b/Userland/Libraries/LibGfx/ICOLoader.cpp index 9007d06a907..ad4fcb5edf7 100644 --- a/Userland/Libraries/LibGfx/ICOLoader.cpp +++ b/Userland/Libraries/LibGfx/ICOLoader.cpp @@ -116,14 +116,14 @@ static size_t find_largest_image(ICOLoadingContext const& context) static ErrorOr load_ico_directory(ICOLoadingContext& context) { - auto stream = TRY(FixedMemoryStream::construct({ context.data, context.data_size })); + FixedMemoryStream stream { { context.data, context.data_size } }; - auto image_count = TRY(decode_ico_header(*stream)); + auto image_count = TRY(decode_ico_header(stream)); if (image_count == 0) return Error::from_string_literal("ICO file has no images"); for (size_t i = 0; i < image_count; ++i) { - auto desc = TRY(decode_ico_direntry(*stream)); + auto desc = TRY(decode_ico_direntry(stream)); if (desc.offset + desc.size < desc.offset // detect integer overflow || (desc.offset + desc.size) > context.data_size) { dbgln_if(ICO_DEBUG, "load_ico_directory: offset: {} size: {} doesn't fit in ICO size: {}", desc.offset, desc.size, context.data_size); @@ -183,8 +183,8 @@ ErrorOr ICOImageDecoderPlugin::load_ico_bitmap(ICOLoadingContext& context, ErrorOr ICOImageDecoderPlugin::sniff(ReadonlyBytes data) { - auto stream = TRY(FixedMemoryStream::construct(data)); - return !decode_ico_header(*stream).is_error(); + FixedMemoryStream stream { data }; + return !decode_ico_header(stream).is_error(); } ErrorOr> ICOImageDecoderPlugin::create(ReadonlyBytes data) @@ -233,10 +233,8 @@ bool ICOImageDecoderPlugin::set_nonvolatile(bool& was_purged) bool ICOImageDecoderPlugin::initialize() { - auto stream_or_error = FixedMemoryStream::construct(ReadonlyBytes { m_context->data, m_context->data_size }); - if (stream_or_error.is_error()) - return false; - return !decode_ico_header(*stream_or_error.value()).is_error(); + FixedMemoryStream stream { { m_context->data, m_context->data_size } }; + return !decode_ico_header(stream).is_error(); } bool ICOImageDecoderPlugin::is_animated() diff --git a/Userland/Libraries/LibGfx/JPGLoader.cpp b/Userland/Libraries/LibGfx/JPGLoader.cpp index 8f67d4f7464..3fe1d8f2971 100644 --- a/Userland/Libraries/LibGfx/JPGLoader.cpp +++ b/Userland/Libraries/LibGfx/JPGLoader.cpp @@ -1202,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(FixedMemoryStream::construct({ context.data, context.data_size })); + context.stream = TRY(try_make(ReadonlyBytes { 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 0ecbed76cfc..0f633d567cd 100644 --- a/Userland/Libraries/LibGfx/QOILoader.cpp +++ b/Userland/Libraries/LibGfx/QOILoader.cpp @@ -202,13 +202,13 @@ bool QOIImageDecoderPlugin::initialize() ErrorOr QOIImageDecoderPlugin::sniff(ReadonlyBytes data) { - auto stream = TRY(FixedMemoryStream::construct({ data.data(), data.size() })); - return !decode_qoi_header(*stream).is_error(); + FixedMemoryStream stream { { data.data(), data.size() } }; + return !decode_qoi_header(stream).is_error(); } ErrorOr> QOIImageDecoderPlugin::create(ReadonlyBytes data) { - auto stream = TRY(FixedMemoryStream::construct(data)); + auto stream = TRY(try_make(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 4ae7724a9da..a15e8ddb90c 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -70,8 +70,8 @@ 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(FixedMemoryStream::construct({ buf.data(), buf.size() })); - auto brotli_stream = Compress::BrotliDecompressionStream { *bufstream }; + FixedMemoryStream bufstream { buf }; + auto brotli_stream = Compress::BrotliDecompressionStream { bufstream }; auto uncompressed = TRY(brotli_stream.read_until_eof()); if constexpr (JOB_DEBUG) { diff --git a/Userland/Libraries/LibPDF/DocumentParser.cpp b/Userland/Libraries/LibPDF/DocumentParser.cpp index 08ab1298474..2b55aea802b 100644 --- a/Userland/Libraries/LibPDF/DocumentParser.cpp +++ b/Userland/Libraries/LibPDF/DocumentParser.cpp @@ -596,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(FixedMemoryStream::construct(hint_stream_bytes)); + auto input_stream = TRY(try_make(hint_stream_bytes)); TRY(input_stream->seek(sizeof(PageOffsetHintTable))); LittleEndianInputBitStream bit_stream { move(input_stream) }; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 2a2856e472d..a1c383aa8e4 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -203,8 +203,8 @@ struct ConvertToRaw { { LittleEndian res; ReadonlyBytes bytes { &value, sizeof(float) }; - 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(); + FixedMemoryStream stream { bytes }; + stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors(); return static_cast(res); } }; @@ -215,8 +215,8 @@ struct ConvertToRaw { { LittleEndian res; ReadonlyBytes bytes { &value, sizeof(double) }; - 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(); + FixedMemoryStream stream { bytes }; + stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors(); return static_cast(res); } }; @@ -253,8 +253,8 @@ template T BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian value; - auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); - auto maybe_error = stream->read_entire_buffer(value.bytes()); + FixedMemoryStream stream { data }; + auto maybe_error = stream.read_entire_buffer(value.bytes()); if (maybe_error.is_error()) { dbgln("Read from {} failed", data.data()); m_trap = Trap { "Read from memory failed" }; @@ -266,8 +266,8 @@ template<> float BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian raw_value; - auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); - auto maybe_error = stream->read_entire_buffer(raw_value.bytes()); + FixedMemoryStream stream { data }; + auto maybe_error = stream.read_entire_buffer(raw_value.bytes()); if (maybe_error.is_error()) m_trap = Trap { "Read from memory failed" }; return bit_cast(static_cast(raw_value)); @@ -277,8 +277,8 @@ template<> double BytecodeInterpreter::read_value(ReadonlyBytes data) { LittleEndian raw_value; - auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); - auto maybe_error = stream->read_entire_buffer(raw_value.bytes()); + FixedMemoryStream stream { data }; + auto maybe_error = stream.read_entire_buffer(raw_value.bytes()); if (maybe_error.is_error()) m_trap = Trap { "Read from memory failed" }; return bit_cast(static_cast(raw_value)); diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 51f72d99e18..42282fb7bd3 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -260,8 +260,8 @@ ParseResult BlockType::parse(AK::Stream& stream) return BlockType {}; { - 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()) + FixedMemoryStream value_stream { ReadonlyBytes { &kind, 1 } }; + 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 bf6dc243ae1..7d6ad223905 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -121,8 +121,8 @@ JS::ThrowCompletionOr parse_module(JS::VM& vm, JS::Object* buffer_object } else { return vm.throw_completion("Not a BufferSource"); } - auto stream = FixedMemoryStream::construct(data).release_value_but_fixme_should_propagate_errors(); - auto module_result = Wasm::Module::parse(*stream); + FixedMemoryStream stream { data }; + auto module_result = Wasm::Module::parse(stream); if (module_result.is_error()) { // FIXME: Throw CompileError instead. return vm.throw_completion(Wasm::parse_error_to_deprecated_string(module_result.error())); diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp index 269582af5f2..beb497438b1 100644 --- a/Userland/Services/WebServer/Client.cpp +++ b/Userland/Services/WebServer/Client.cpp @@ -336,8 +336,8 @@ ErrorOr Client::handle_directory_listing(String const& requested_path, Str builder.append("\n"sv); auto response = builder.to_deprecated_string(); - auto stream = TRY(FixedMemoryStream::construct(response.bytes())); - return send_response(*stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() }); + FixedMemoryStream stream { response.bytes() }; + return send_response(stream, request, { .type = TRY(String::from_utf8("text/html"sv)), .length = response.length() }); } ErrorOr Client::send_error_response(unsigned code, HTTP::HttpRequest const& request, Vector const& headers) diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 2e339890e3f..fb0e2df08b6 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -342,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(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(try_make(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)) { @@ -421,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(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(try_make(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)) { @@ -490,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(FixedMemoryStream::construct(m_stream_backing_buffer.bytes()).release_value_but_fixme_should_propagate_errors()) + , m_output_stream(try_make(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)) { diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index 0ec6e4ca764..ae368f5888c 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -252,8 +252,8 @@ static Optional parse(StringView filename) return {}; } - 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); + FixedMemoryStream stream { ReadonlyBytes { result.value()->data(), result.value()->size() } }; + 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!"); warnln("The parse error was {}", Wasm::parse_error_to_deprecated_string(parse_result.error()));