mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
This commit is contained in:
parent
d5871f5717
commit
a3f73e7d85
Notes:
sideshowbarker
2024-07-17 03:05:16 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/a3f73e7d85 Pull-request: https://github.com/SerenityOS/serenity/pull/17684 Reviewed-by: https://github.com/JanDeVisser ✅ Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg ✅
@ -11,7 +11,7 @@
|
||||
|
||||
namespace AK {
|
||||
|
||||
ErrorOr<void> Stream::read_entire_buffer(Bytes buffer)
|
||||
ErrorOr<void> Stream::read_until_filled(Bytes buffer)
|
||||
{
|
||||
size_t nread = 0;
|
||||
while (nread < buffer.size()) {
|
||||
|
@ -26,13 +26,13 @@ public:
|
||||
virtual ErrorOr<Bytes> read_some(Bytes) = 0;
|
||||
/// Tries to fill the entire buffer through reading. Returns whether the
|
||||
/// buffer was filled without an error.
|
||||
virtual ErrorOr<void> read_entire_buffer(Bytes);
|
||||
virtual ErrorOr<void> read_until_filled(Bytes);
|
||||
/// Reads the stream until EOF, storing the contents into a ByteBuffer which
|
||||
/// is returned once EOF is encountered. The block size determines the size
|
||||
/// of newly allocated chunks while reading.
|
||||
virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096);
|
||||
/// Discards the given number of bytes from the stream. As this is usually used
|
||||
/// as an efficient version of `read_entire_buffer`, it returns an error
|
||||
/// as an efficient version of `read_until_filled`, it returns an error
|
||||
/// if reading failed or if not all bytes could be discarded.
|
||||
/// Unless specifically overwritten, this just uses read() to read into an
|
||||
/// internal stack-based buffer.
|
||||
@ -58,7 +58,7 @@ public:
|
||||
ErrorOr<T> read_value()
|
||||
{
|
||||
alignas(T) u8 buffer[sizeof(T)] = {};
|
||||
TRY(read_entire_buffer({ &buffer, sizeof(buffer) }));
|
||||
TRY(read_until_filled({ &buffer, sizeof(buffer) }));
|
||||
return bit_cast<T>(buffer);
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ ErrorOr<NonnullRefPtr<StringData>> StringData::from_utf8(char const* utf8_data,
|
||||
|
||||
static ErrorOr<void> read_stream_into_buffer(Stream& stream, Bytes buffer)
|
||||
{
|
||||
TRY(stream.read_entire_buffer(buffer));
|
||||
TRY(stream.read_until_filled(buffer));
|
||||
|
||||
if (!Utf8View { StringView { buffer } }.validate())
|
||||
return Error::from_string_literal("String::from_stream: Input was not valid UTF-8");
|
||||
|
@ -540,7 +540,7 @@ ErrorOr<JsonValue> read_entire_file_as_json(StringView filename)
|
||||
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Read));
|
||||
auto json_size = TRY(file->size());
|
||||
auto json_data = TRY(ByteBuffer::create_uninitialized(json_size));
|
||||
TRY(file->read_entire_buffer(json_data.bytes()));
|
||||
TRY(file->read_until_filled(json_data.bytes()));
|
||||
return JsonValue::from_string(json_data);
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,6 @@ ErrorOr<JsonValue> read_entire_file_as_json(StringView filename)
|
||||
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Read));
|
||||
auto json_size = TRY(file->size());
|
||||
auto json_data = TRY(ByteBuffer::create_uninitialized(json_size));
|
||||
TRY(file->read_entire_buffer(json_data.bytes()));
|
||||
TRY(file->read_until_filled(json_data.bytes()));
|
||||
return JsonValue::from_string(json_data);
|
||||
}
|
||||
|
@ -90,17 +90,17 @@ TEST_CASE(file_seeking_around)
|
||||
|
||||
EXPECT(!file->seek(500, SeekMode::SetPosition).is_error());
|
||||
EXPECT_EQ(file->tell().release_value(), 500ul);
|
||||
EXPECT(!file->read_entire_buffer(buffer).is_error());
|
||||
EXPECT(!file->read_until_filled(buffer).is_error());
|
||||
EXPECT_EQ(buffer_contents, expected_seek_contents1);
|
||||
|
||||
EXPECT(!file->seek(234, SeekMode::FromCurrentPosition).is_error());
|
||||
EXPECT_EQ(file->tell().release_value(), 750ul);
|
||||
EXPECT(!file->read_entire_buffer(buffer).is_error());
|
||||
EXPECT(!file->read_until_filled(buffer).is_error());
|
||||
EXPECT_EQ(buffer_contents, expected_seek_contents2);
|
||||
|
||||
EXPECT(!file->seek(-105, SeekMode::FromEndPosition).is_error());
|
||||
EXPECT_EQ(file->tell().release_value(), 8597ul);
|
||||
EXPECT(!file->read_entire_buffer(buffer).is_error());
|
||||
EXPECT(!file->read_until_filled(buffer).is_error());
|
||||
EXPECT_EQ(buffer_contents, expected_seek_contents3);
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ TEST_CASE(file_adopt_fd)
|
||||
|
||||
EXPECT(!file->seek(500, SeekMode::SetPosition).is_error());
|
||||
EXPECT_EQ(file->tell().release_value(), 500ul);
|
||||
EXPECT(!file->read_entire_buffer(buffer).is_error());
|
||||
EXPECT(!file->read_until_filled(buffer).is_error());
|
||||
EXPECT_EQ(buffer_contents, expected_seek_contents1);
|
||||
|
||||
// A single seek & read test should be fine for now.
|
||||
|
@ -18,7 +18,7 @@ static DeprecatedString read_all(DeprecatedString const& path)
|
||||
auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read));
|
||||
auto file_size = MUST(file->size());
|
||||
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
|
||||
MUST(file->read_entire_buffer(content.bytes()));
|
||||
MUST(file->read_until_filled(content.bytes()));
|
||||
return DeprecatedString { content.bytes() };
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ static DeprecatedString read_all(DeprecatedString const& path)
|
||||
auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read));
|
||||
auto file_size = MUST(file->size());
|
||||
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
|
||||
MUST(file->read_entire_buffer(content.bytes()));
|
||||
MUST(file->read_until_filled(content.bytes()));
|
||||
return DeprecatedString { content.bytes() };
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ TEST_SETUP
|
||||
auto file = file_or_error.release_value();
|
||||
auto file_size = MUST(file->size());
|
||||
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
|
||||
MUST(file->read_entire_buffer(content.bytes()));
|
||||
MUST(file->read_until_filled(content.bytes()));
|
||||
DeprecatedString test_data { content.bytes() };
|
||||
|
||||
auto tests = JsonParser(test_data).parse().value().as_array();
|
||||
|
@ -490,7 +490,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)
|
||||
auto search_engines_file = TRY(Core::File::open(Browser::search_engines_file_path(), Core::File::OpenMode::Read));
|
||||
auto file_size = TRY(search_engines_file->size());
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(file_size));
|
||||
if (!search_engines_file->read_entire_buffer(buffer).is_error()) {
|
||||
if (!search_engines_file->read_until_filled(buffer).is_error()) {
|
||||
StringView buffer_contents { buffer.bytes() };
|
||||
if (auto json = TRY(JsonValue::from_string(buffer_contents)); json.is_array()) {
|
||||
auto json_array = json.as_array();
|
||||
|
@ -81,7 +81,7 @@ inline ErrorOr<void> TarInputStream::for_each_extended_header(F func)
|
||||
|
||||
auto header_size = TRY(header().size());
|
||||
ByteBuffer file_contents_buffer = TRY(ByteBuffer::create_zeroed(header_size));
|
||||
TRY(file_stream.read_entire_buffer(file_contents_buffer));
|
||||
TRY(file_stream.read_until_filled(file_contents_buffer));
|
||||
|
||||
StringView file_contents { file_contents_buffer };
|
||||
|
||||
|
@ -232,7 +232,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header
|
||||
auto& buffer = maybe_buffer.value();
|
||||
|
||||
size_t old_reservoir_size = m_bit_reservoir.used_buffer_size();
|
||||
LOADER_TRY(m_bitstream->read_entire_buffer(buffer));
|
||||
LOADER_TRY(m_bitstream->read_until_filled(buffer));
|
||||
// FIXME: This should write the entire span.
|
||||
if (LOADER_TRY(m_bit_reservoir.write_some(buffer)) != header.slot_count)
|
||||
return LoaderError { LoaderError::Category::IO, m_loaded_samples, "Could not write frame into bit reservoir." };
|
||||
|
@ -93,7 +93,7 @@ template<typename T>
|
||||
static ErrorOr<double> read_sample(Stream& stream)
|
||||
{
|
||||
T sample { 0 };
|
||||
TRY(stream.read_entire_buffer(Bytes { &sample, sizeof(T) }));
|
||||
TRY(stream.read_until_filled(Bytes { &sample, sizeof(T) }));
|
||||
// Remap integer samples to normalized floating-point range of -1 to 1.
|
||||
if constexpr (IsIntegral<T>) {
|
||||
if constexpr (NumericLimits<T>::is_signed()) {
|
||||
@ -157,7 +157,7 @@ ErrorOr<Vector<FixedArray<Sample>>, LoaderError> WavLoaderPlugin::load_chunks(si
|
||||
pcm_bits_per_sample(m_sample_format), sample_format_name(m_sample_format));
|
||||
|
||||
auto sample_data = LOADER_TRY(ByteBuffer::create_zeroed(bytes_to_read));
|
||||
LOADER_TRY(m_stream->read_entire_buffer(sample_data.bytes()));
|
||||
LOADER_TRY(m_stream->read_until_filled(sample_data.bytes()));
|
||||
|
||||
// m_loaded_samples should contain the amount of actually loaded samples
|
||||
m_loaded_samples += samples_to_read;
|
||||
|
@ -329,7 +329,7 @@ ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
|
||||
}
|
||||
|
||||
auto output_buffer = TRY(ByteBuffer::create_uninitialized(output_stream.used_buffer_size()));
|
||||
TRY(output_stream.read_entire_buffer(output_buffer));
|
||||
TRY(output_stream.read_until_filled(output_buffer));
|
||||
return output_buffer;
|
||||
}
|
||||
|
||||
@ -1027,7 +1027,7 @@ ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, Compres
|
||||
TRY(deflate_stream->final_flush());
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
|
||||
TRY(output_stream->read_entire_buffer(buffer));
|
||||
TRY(output_stream->read_until_filled(buffer));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
|
||||
}
|
||||
|
||||
auto output_buffer = TRY(ByteBuffer::create_uninitialized(output_stream.used_buffer_size()));
|
||||
TRY(output_stream.read_entire_buffer(output_buffer));
|
||||
TRY(output_stream.read_until_filled(output_buffer));
|
||||
return output_buffer;
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes)
|
||||
TRY(gzip_stream.write_entire_buffer(bytes));
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
|
||||
TRY(output_stream->read_entire_buffer(buffer.bytes()));
|
||||
TRY(output_stream->read_until_filled(buffer.bytes()));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompre
|
||||
TRY(zlib_stream->finish());
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(output_stream->used_buffer_size()));
|
||||
TRY(output_stream->read_entire_buffer(buffer.bytes()));
|
||||
TRY(output_stream->read_until_filled(buffer.bytes()));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
|
||||
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request trailer");
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
|
||||
TRY(stream.read_entire_buffer(buffer.bytes()));
|
||||
TRY(stream.read_until_filled(buffer.bytes()));
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
size = TRY(socket.write_some({ buffer.data(), buffer.size() }));
|
||||
@ -263,7 +263,7 @@ ErrorOr<u8> send_username_password_authentication_message(Core::Socket& socket,
|
||||
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
|
||||
TRY(stream.read_entire_buffer(buffer.bytes()));
|
||||
TRY(stream.read_until_filled(buffer.bytes()));
|
||||
|
||||
// FIXME: This should write the entire span.
|
||||
size = TRY(socket.write_some(buffer));
|
||||
|
@ -72,7 +72,7 @@ ErrorOr<ByteBuffer> Packet::to_byte_buffer() const
|
||||
}
|
||||
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
|
||||
TRY(stream.read_entire_buffer(buffer));
|
||||
TRY(stream.read_until_filled(buffer));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,11 @@ struct [[gnu::packed]] CompilationUnitHeader {
|
||||
static ErrorOr<CompilationUnitHeader> read_from_stream(Stream& stream)
|
||||
{
|
||||
CompilationUnitHeader header;
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.common, sizeof(header.common) }));
|
||||
if (header.common.version <= 4)
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.v4, sizeof(header.v4) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.v4, sizeof(header.v4) }));
|
||||
else
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.v5, sizeof(header.v5) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.v5, sizeof(header.v5) }));
|
||||
return header;
|
||||
}
|
||||
};
|
||||
|
@ -68,12 +68,12 @@ struct [[gnu::packed]] LineProgramUnitHeader32 {
|
||||
static ErrorOr<LineProgramUnitHeader32> read_from_stream(Stream& stream)
|
||||
{
|
||||
LineProgramUnitHeader32 header;
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.common, sizeof(header.common) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.common, sizeof(header.common) }));
|
||||
if (header.common.version <= 4)
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.v4, sizeof(header.v4) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.v4, sizeof(header.v4) }));
|
||||
else
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.v5, sizeof(header.v5) }));
|
||||
TRY(stream.read_entire_buffer(Bytes { &header.std_opcode_lengths, min(sizeof(header.std_opcode_lengths), (header.opcode_base() - 1) * sizeof(header.std_opcode_lengths[0])) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.v5, sizeof(header.v5) }));
|
||||
TRY(stream.read_until_filled(Bytes { &header.std_opcode_lengths, min(sizeof(header.std_opcode_lengths), (header.opcode_base() - 1) * sizeof(header.std_opcode_lengths[0])) }));
|
||||
return header;
|
||||
}
|
||||
};
|
||||
|
@ -94,7 +94,7 @@ static ErrorOr<GIFFormat> decode_gif_header(Stream& stream)
|
||||
static auto valid_header_89 = "GIF89a"sv;
|
||||
|
||||
Array<u8, 6> header;
|
||||
TRY(stream.read_entire_buffer(header));
|
||||
TRY(stream.read_until_filled(header));
|
||||
|
||||
if (header.span() == valid_header_87.bytes())
|
||||
return GIFFormat::GIF87a;
|
||||
@ -424,7 +424,7 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
|
||||
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_until_filled(sub_block.span().slice_from_end(sub_block_length)));
|
||||
}
|
||||
|
||||
if (extension_type == 0xF9) {
|
||||
@ -501,7 +501,7 @@ static ErrorOr<void> load_gif_frame_descriptors(GIFLoadingContext& context)
|
||||
break;
|
||||
|
||||
Array<u8, 256> buffer;
|
||||
TRY(stream.read_entire_buffer(buffer.span().trim(lzw_encoded_bytes_expected)));
|
||||
TRY(stream.read_until_filled(buffer.span().trim(lzw_encoded_bytes_expected)));
|
||||
|
||||
for (int i = 0; i < lzw_encoded_bytes_expected; ++i) {
|
||||
image->lzw_encoded_bytes.append(buffer[i]);
|
||||
|
@ -769,7 +769,7 @@ static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPEGLoadingContext
|
||||
return Error::from_string_literal("Duplicate ICC chunk at sequence number");
|
||||
|
||||
chunk_state->chunks[index] = TRY(ByteBuffer::create_zeroed(bytes_to_read));
|
||||
TRY(stream.read_entire_buffer(chunk_state->chunks[index]));
|
||||
TRY(stream.read_until_filled(chunk_state->chunks[index]));
|
||||
|
||||
chunk_state->seen_number_of_icc_chunks++;
|
||||
|
||||
|
@ -35,7 +35,7 @@ static ErrorOr<Color> decode_qoi_op_rgb(Stream& stream, u8 first_byte, Color pix
|
||||
{
|
||||
VERIFY(first_byte == QOI_OP_RGB);
|
||||
u8 bytes[3];
|
||||
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
|
||||
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
|
||||
|
||||
// The alpha value remains unchanged from the previous pixel.
|
||||
return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() };
|
||||
@ -45,7 +45,7 @@ static ErrorOr<Color> decode_qoi_op_rgba(Stream& stream, u8 first_byte)
|
||||
{
|
||||
VERIFY(first_byte == QOI_OP_RGBA);
|
||||
u8 bytes[4];
|
||||
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
|
||||
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
|
||||
return Color { bytes[0], bytes[1], bytes[2], bytes[3] };
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ static ErrorOr<u8> decode_qoi_op_run(Stream&, u8 first_byte)
|
||||
static ErrorOr<void> decode_qoi_end_marker(Stream& stream)
|
||||
{
|
||||
u8 bytes[array_size(END_MARKER)];
|
||||
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
|
||||
TRY(stream.read_until_filled({ &bytes, array_size(bytes) }));
|
||||
if (!stream.is_eof())
|
||||
return Error::from_string_literal("Invalid QOI image: expected end of stream but more bytes are available");
|
||||
if (memcmp(&END_MARKER, &bytes, array_size(bytes)) != 0)
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
ErrorOr<void> decode_into(Bytes bytes)
|
||||
{
|
||||
TRY(m_stream.read_entire_buffer(bytes));
|
||||
TRY(m_stream.read_until_filled(bytes));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1346,7 +1346,7 @@ ErrorOr<void> Editor::refresh_display()
|
||||
return;
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(output_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
|
||||
output_stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
output_stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
fwrite(buffer.data(), sizeof(char), buffer.size(), stderr);
|
||||
}
|
||||
};
|
||||
|
@ -90,7 +90,7 @@ void Request::set_should_buffer_all_input(bool value)
|
||||
|
||||
on_finish = [this](auto success, u32 total_size) {
|
||||
auto output_buffer = ByteBuffer::create_uninitialized(m_internal_buffered_data->payload_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
|
||||
m_internal_buffered_data->payload_stream.read_entire_buffer(output_buffer).release_value_but_fixme_should_propagate_errors();
|
||||
m_internal_buffered_data->payload_stream.read_until_filled(output_buffer).release_value_but_fixme_should_propagate_errors();
|
||||
on_buffered_request_finish(
|
||||
success,
|
||||
total_size,
|
||||
|
@ -210,7 +210,7 @@ struct ConvertToRaw<float> {
|
||||
LittleEndian<u32> res;
|
||||
ReadonlyBytes bytes { &value, sizeof(float) };
|
||||
FixedMemoryStream stream { bytes };
|
||||
stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
return static_cast<u32>(res);
|
||||
}
|
||||
};
|
||||
@ -222,7 +222,7 @@ struct ConvertToRaw<double> {
|
||||
LittleEndian<u64> res;
|
||||
ReadonlyBytes bytes { &value, sizeof(double) };
|
||||
FixedMemoryStream stream { bytes };
|
||||
stream.read_entire_buffer(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
return static_cast<u64>(res);
|
||||
}
|
||||
};
|
||||
@ -260,7 +260,7 @@ T BytecodeInterpreter::read_value(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<T> value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_entire_buffer(value.bytes());
|
||||
auto maybe_error = stream.read_until_filled(value.bytes());
|
||||
if (maybe_error.is_error()) {
|
||||
dbgln("Read from {} failed", data.data());
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
@ -273,7 +273,7 @@ float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<u32> raw_value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
|
||||
auto maybe_error = stream.read_until_filled(raw_value.bytes());
|
||||
if (maybe_error.is_error())
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
return bit_cast<float>(static_cast<u32>(raw_value));
|
||||
@ -284,7 +284,7 @@ double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<u64> raw_value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_entire_buffer(raw_value.bytes());
|
||||
auto maybe_error = stream.read_until_filled(raw_value.bytes());
|
||||
if (maybe_error.is_error())
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
return bit_cast<double>(static_cast<u64>(raw_value));
|
||||
|
@ -89,7 +89,7 @@ void Configuration::dump_stack()
|
||||
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();
|
||||
memory_stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
dbgln(format.view(), StringView(buffer).trim_whitespace());
|
||||
};
|
||||
for (auto const& entry : stack().entries()) {
|
||||
|
@ -64,7 +64,7 @@ static auto parse_vector(Stream& stream)
|
||||
if (count > Constants::max_allowed_vector_size)
|
||||
return ParseResult<Vector<T>> { ParseError::HugeAllocationRequested };
|
||||
entries.resize(count);
|
||||
if (stream.read_entire_buffer({ entries.data(), entries.size() }).is_error())
|
||||
if (stream.read_until_filled({ entries.data(), entries.size() }).is_error())
|
||||
return ParseResult<Vector<T>> { with_eof_check(stream, ParseError::InvalidInput) };
|
||||
break; // Note: We read this all in one go!
|
||||
}
|
||||
@ -486,7 +486,7 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
|
||||
case Instructions::f32_const.value(): {
|
||||
// op literal
|
||||
LittleEndian<u32> value;
|
||||
if (stream.read_entire_buffer(value.bytes()).is_error())
|
||||
if (stream.read_until_filled(value.bytes()).is_error())
|
||||
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
|
||||
|
||||
auto floating = bit_cast<float>(static_cast<u32>(value));
|
||||
@ -496,7 +496,7 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
|
||||
case Instructions::f64_const.value(): {
|
||||
// op literal
|
||||
LittleEndian<u64> value;
|
||||
if (stream.read_entire_buffer(value.bytes()).is_error())
|
||||
if (stream.read_until_filled(value.bytes()).is_error())
|
||||
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
|
||||
|
||||
auto floating = bit_cast<double>(static_cast<u64>(value));
|
||||
@ -1276,12 +1276,12 @@ ParseResult<Module> Module::parse(Stream& stream)
|
||||
{
|
||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Module"sv);
|
||||
u8 buf[4];
|
||||
if (stream.read_entire_buffer({ buf, 4 }).is_error())
|
||||
if (stream.read_until_filled({ buf, 4 }).is_error())
|
||||
return with_eof_check(stream, ParseError::InvalidInput);
|
||||
if (Bytes { buf, 4 } != wasm_magic.span())
|
||||
return with_eof_check(stream, ParseError::InvalidModuleMagic);
|
||||
|
||||
if (stream.read_entire_buffer({ buf, 4 }).is_error())
|
||||
if (stream.read_until_filled({ buf, 4 }).is_error())
|
||||
return with_eof_check(stream, ParseError::InvalidInput);
|
||||
if (Bytes { buf, 4 } != wasm_version.span())
|
||||
return with_eof_check(stream, ParseError::InvalidModuleVersion);
|
||||
|
@ -1772,7 +1772,7 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
|
||||
return Break;
|
||||
}
|
||||
auto entry = entry_result.release_value();
|
||||
TRY(stream.read_entire_buffer(entry));
|
||||
TRY(stream.read_until_filled(entry));
|
||||
|
||||
auto str = TRY(String::from_utf8(StringView(entry.data(), entry.size() - ifs.length())));
|
||||
if (TRY(callback(make_ref_counted<StringValue>(move(str)))) == IterationDecision::Break) {
|
||||
@ -1862,7 +1862,7 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
|
||||
return {};
|
||||
}
|
||||
auto entry = entry_result.release_value();
|
||||
TRY(stream.read_entire_buffer(entry));
|
||||
TRY(stream.read_until_filled(entry));
|
||||
TRY(callback(make_ref_counted<StringValue>(TRY(String::from_utf8(entry)))));
|
||||
}
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
else
|
||||
argument_builder.append(", "sv);
|
||||
auto buffer = ByteBuffer::create_uninitialized(stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
|
||||
stream.read_entire_buffer(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
stream.read_until_filled(buffer).release_value_but_fixme_should_propagate_errors();
|
||||
argument_builder.append(StringView(buffer).trim_whitespace());
|
||||
}
|
||||
dbgln("[wasm runtime] Stub function {} was called with the following arguments: {}", name, argument_builder.to_deprecated_string());
|
||||
|
Loading…
Reference in New Issue
Block a user