summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-01-09 12:06:13 +0100
committerLinus Groh <mail@linusgroh.de>2023-01-20 20:48:40 +0000
commit52cb066caec7ea4f467d173dc57d95e9d9409436 (patch)
treeb5ae85cf79b3b90d701317c0048eb07aa94b9380 /Userland
parent7d4a30af56a7376f1c0cf55673abd5776e21f8a1 (diff)
downloadserenity-52cb066caec7ea4f467d173dc57d95e9d9409436.zip
LibWasm: Use `AllocatingMemoryStream` around `Wasm::Printer`
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp9
-rw-r--r--Userland/Utilities/wasm.cpp9
2 files changed, 12 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
index 0bb260ee5b..88de3a1459 100644
--- a/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
+++ b/Userland/Libraries/LibWasm/AbstractMachine/Configuration.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibCore/MemoryStream.h>
#include <LibWasm/AbstractMachine/Configuration.h>
#include <LibWasm/AbstractMachine/Interpreter.h>
#include <LibWasm/Printer/Printer.h>
@@ -85,9 +86,11 @@ Result Configuration::execute(Interpreter& interpreter)
void Configuration::dump_stack()
{
auto print_value = []<typename... Ts>(CheckedFormatString<Ts...> format, Ts... vs) {
- DuplexMemoryStream memory_stream;
- Printer { memory_stream }.print(vs...);
- ByteBuffer buffer = memory_stream.copy_into_contiguous_buffer();
+ Core::Stream::AllocatingMemoryStream memory_stream;
+ Core::Stream::WrapInAKOutputStream wrapped_memory_stream { memory_stream };
+ Printer { wrapped_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();
dbgln(format.view(), StringView(buffer).trim_whitespace());
};
for (auto const& entry : stack().entries()) {
diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp
index fabb40c2c1..3bd79b4a05 100644
--- a/Userland/Utilities/wasm.cpp
+++ b/Userland/Utilities/wasm.cpp
@@ -9,6 +9,7 @@
#include <LibCore/File.h>
#include <LibCore/FileStream.h>
#include <LibCore/MappedFile.h>
+#include <LibCore/MemoryStream.h>
#include <LibLine/Editor.h>
#include <LibMain/Main.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
@@ -396,13 +397,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
StringBuilder argument_builder;
bool first = true;
for (auto& argument : arguments) {
- DuplexMemoryStream stream;
- Wasm::Printer { stream }.print(argument);
+ Core::Stream::AllocatingMemoryStream stream;
+ Core::Stream::WrapInAKOutputStream wrapped_stream { stream };
+ Wasm::Printer { wrapped_stream }.print(argument);
if (first)
first = false;
else
argument_builder.append(", "sv);
- ByteBuffer buffer = stream.copy_into_contiguous_buffer();
+ 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();
argument_builder.append(StringView(buffer).trim_whitespace());
}
dbgln("[wasm runtime] Stub function {} was called with the following arguments: {}", name, argument_builder.to_deprecated_string());