Skip to content

Commit

Permalink
Use heap for stdout and stderr
Browse files Browse the repository at this point in the history
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
  • Loading branch information
Ayush1325 committed Jan 19, 2024
1 parent 07000dc commit 346472c
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions library/std/src/sys/pal/uefi/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use crate::mem::MaybeUninit;
use crate::os::uefi;
use crate::ptr::NonNull;

const MAX_BUFFER_SIZE: usize = 8192;

pub struct Stdin {
pending: Option<char>,
}
Expand Down Expand Up @@ -111,19 +109,14 @@ fn write(
protocol: *mut r_efi::protocols::simple_text_output::Protocol,
buf: &[u8],
) -> io::Result<usize> {
let mut utf16 = [0; MAX_BUFFER_SIZE / 2];

// Get valid UTF-8 buffer
let utf8 = match crate::str::from_utf8(buf) {
Ok(x) => x,
Err(e) => unsafe { crate::str::from_utf8_unchecked(&buf[..e.valid_up_to()]) },
};
// Clip UTF-8 buffer to max UTF-16 buffer we support
let utf8 = &utf8[..utf8.floor_char_boundary(utf16.len() - 1)];

for (i, ch) in utf8.encode_utf16().enumerate() {
utf16[i] = ch;
}
let mut utf16: Vec<u16> = utf8.encode_utf16().collect();
utf16.push(0);

unsafe { simple_text_output(protocol, &mut utf16) }?;

Expand Down

0 comments on commit 346472c

Please sign in to comment.