[llvm] [LineEditor] Flush the output stream after printing the prompt (PR #107755)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 8 07:32:33 PDT 2024
https://github.com/YerinAlexey created https://github.com/llvm/llvm-project/pull/107755
Despite that a lot of libc implementations implicitly flush before read operations in interactive environments, this behaviour is not guaranteed. For example, [musl libc](https://musl.libc.org) does not do that, which causes the prompt to either not get printed or get printed at unexpected times.
>From 3a5198b9b88c8db5c38b5ae60ca9c159550bb430 Mon Sep 17 00:00:00 2001
From: Alexey Yerin <yyp at disroot.org>
Date: Sun, 8 Sep 2024 17:02:32 +0300
Subject: [PATCH] [LineEditor] Flush the output stream after printing the
prompt
Despite that a lot of libc implementations implicitly flush before
read operations in interactive environments, this behaviour is not
guaranteed. For example, musl libc does not do that, which causes the
prompt to either not get printed or get printed at unexpected times.
---
llvm/lib/LineEditor/LineEditor.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/LineEditor/LineEditor.cpp b/llvm/lib/LineEditor/LineEditor.cpp
index d0d138bb1f9d8d..66e40325db75af 100644
--- a/llvm/lib/LineEditor/LineEditor.cpp
+++ b/llvm/lib/LineEditor/LineEditor.cpp
@@ -294,6 +294,7 @@ void LineEditor::loadHistory() {}
std::optional<std::string> LineEditor::readLine() const {
::fprintf(Data->Out, "%s", Prompt.c_str());
+ ::fflush(Data->Out);
std::string Line;
do {
More information about the llvm-commits
mailing list