From 5aba6b44ab0ccd1acdf834649d7719dcd1fb5dd1 Mon Sep 17 00:00:00 2001 From: Yu Zhang Date: Mon, 2 Dec 2024 15:07:41 +0800 Subject: [PATCH] test driver: avoid using mutation on bytes (#501) --- crates/moonbuild/template/test_driver/wasm_args.mbt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/moonbuild/template/test_driver/wasm_args.mbt b/crates/moonbuild/template/test_driver/wasm_args.mbt index 7f1b80d0..b02128d5 100644 --- a/crates/moonbuild/template/test_driver/wasm_args.mbt +++ b/crates/moonbuild/template/test_driver/wasm_args.mbt @@ -13,8 +13,10 @@ fn moonbit_test_driver_internal_string_read_char(handle : MoonbitTestDriverInter fn moonbit_test_driver_internal_finish_read_string(handle : MoonbitTestDriverInternalStringReadHandle) = "__moonbit_fs_unstable" "finish_read_string" +fn fixedarray_to_bytes(arr : FixedArray[Byte]) -> Bytes = "%identity" + fn moonbit_test_driver_internal_string_from_extern(e : MoonbitTestDriverInternalExternString) -> String { - let buf = Bytes::new(512) + let buf = FixedArray::make(512, Byte::default()) let mut len = 0 let handle = moonbit_test_driver_internal_begin_read_string(e) while true { @@ -22,10 +24,10 @@ fn moonbit_test_driver_internal_string_from_extern(e : MoonbitTestDriverInternal if ch == -1 { break } else { - let written_bytes_len = buf.set_utf16_char(len, Char::from_int(ch)) + let written_bytes_len = buf.set_utf16le_char(len, Char::from_int(ch)) len += written_bytes_len } } moonbit_test_driver_internal_finish_read_string(handle) - buf.to_unchecked_string(offset = 0, length = len).to_string() + fixedarray_to_bytes(buf).to_unchecked_string(offset = 0, length = len).to_string() }