From 414a07136b7576bb1eb7ead428cc4d2ef68af9c9 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Thu, 21 Nov 2024 16:34:43 +0100 Subject: [PATCH 1/2] Make sure to flush when using `print`. --- src/primitive_core.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/primitive_core.cc b/src/primitive_core.cc index e484043ee..22dc66435 100644 --- a/src/primitive_core.cc +++ b/src/primitive_core.cc @@ -122,6 +122,9 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b } } + FILE* stream = is_stdout ? stdout : stderr; + fflush(stream); + return process->null_object(); } @@ -133,9 +136,8 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b fwrite_unlocked(bytes, 1, length, stream); if (newline) { fputc_unlocked('\n', stream); - } else { - fflush_unlocked(stream); } + fflush_unlocked(stream); funlockfile(stream); return process->null_object(); } @@ -147,9 +149,8 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b fwrite(bytes, 1, length, stream); if (newline) { fputc('\n', stream); - } else { - fflush(stream); } + fflush(stream); return process->null_object(); } From bae9974d82955ec650611348dd8288ab40729e44 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Thu, 21 Nov 2024 17:23:59 +0100 Subject: [PATCH 2/2] Feedback. --- src/primitive_core.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/primitive_core.cc b/src/primitive_core.cc index 22dc66435..b962341b6 100644 --- a/src/primitive_core.cc +++ b/src/primitive_core.cc @@ -122,9 +122,6 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b } } - FILE* stream = is_stdout ? stdout : stderr; - fflush(stream); - return process->null_object(); }