From 987c56a1538f4a117da20e7d48d6b43b1cd4c8b4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 26 Oct 2016 09:06:57 +0200 Subject: [PATCH] Create a new `print` function and use it in the print macro This fixes the deadlock problem, because the format_args is now evaluated before locking the screen writer. So `println!("{:?}", {println!("");})` no longer triggers a deadlock. (cherry picked from commit d96df500a7d7c199dc6206638b49fdfd682996c8) --- src/vga_buffer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 07d48f4d..1d9d117e 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -28,11 +28,15 @@ macro_rules! println { macro_rules! print { ($($arg:tt)*) => ({ - use core::fmt::Write; - $crate::vga_buffer::WRITER.lock().write_fmt(format_args!($($arg)*)).unwrap(); + $crate::vga_buffer::print(format_args!($($arg)*)); }); } +pub fn print(args: fmt::Arguments) { + use core::fmt::Write; + WRITER.lock().write_fmt(args).unwrap(); +} + pub fn clear_screen() { for _ in 0..BUFFER_HEIGHT { println!("");