From a7c79c4f23a378c9793e3d0c8f6f6e041738f82e Mon Sep 17 00:00:00 2001 From: Guillaume Endignoux Date: Wed, 18 Mar 2020 15:28:37 +0100 Subject: [PATCH] Resolve review comments. --- patches/libtock-rs/08-buffered-console.patch | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/patches/libtock-rs/08-buffered-console.patch b/patches/libtock-rs/08-buffered-console.patch index 5d8a4fc..ba4c525 100644 --- a/patches/libtock-rs/08-buffered-console.patch +++ b/patches/libtock-rs/08-buffered-console.patch @@ -1,8 +1,8 @@ diff --git a/src/console.rs b/src/console.rs -index ecd7ad1..785de01 100644 +index ecd7ad1..ae1b826 100644 --- a/src/console.rs +++ b/src/console.rs -@@ -16,33 +16,58 @@ mod allow_nr { +@@ -16,33 +16,63 @@ mod allow_nr { pub const SHARE_BUFFER: usize = 1; } @@ -55,7 +55,12 @@ index ecd7ad1..785de01 100644 } - fn flush(&mut self, num_bytes_to_print: usize) { -+ fn flush(&mut self) { ++ pub fn flush(&mut self) { ++ if self.is_empty() { ++ // Don't trigger any syscall if the buffer is empty. ++ return; ++ } ++ + let count = self.count_pending; + // Clear the buffer even in case of error, to avoid an infinite loop. + self.count_pending = 0; @@ -68,7 +73,7 @@ index ecd7ad1..785de01 100644 ); if result.is_err() { return; -@@ -59,8 +84,7 @@ impl Console { +@@ -59,8 +89,7 @@ impl Console { return; } @@ -78,15 +83,13 @@ index ecd7ad1..785de01 100644 if result_code < 0 { return; } -@@ -69,6 +93,14 @@ impl Console { +@@ -69,6 +98,12 @@ impl Console { } } +impl Drop for Console { + fn drop(&mut self) { -+ if !self.is_empty() { -+ self.flush(); -+ } ++ self.flush(); + } +} +