mainUtils: match readline behavior when ABC_USE_READLINE is undefined#514
Merged
alanminko merged 1 commit intoJun 5, 2026
Merged
Conversation
The non-readline branch of Abc_UtilsGetUsersInput has three behavioral
gaps versus the readline branch that break callers driving abc as a
coprocess over a pipe (e.g. yosys's passes/techmap/abc.cc, which spawns
"abc -s" with piped stdin/stdout and uses read_until_abc_done to wait
for "abc NN> <command>" lines):
1. The prompt is written with fprintf() and never flushed. On a pipe
stdout is fully buffered, so the prompt never reaches the reader.
The reader waits for the prompt, abc waits in fgets(), deadlock.
2. There is no echo of the line read from stdin. readline() emits
each character to its output stream; yosys's protocol depends on
seeing "abc NN> source ...\n" in the output to advance state.
Without an echo it waits forever.
3. EOF on stdin is silently ignored: fgets() returns NULL but the
function returns a stale Prompt buffer, causing a tight loop on
pipe close. The readline branch exit(0)s on NULL.
Fix all three. Echo only when stdin is not a tty -- on a tty the kernel
already echoes typed characters during cooked input, so double-echo
would be visible to interactive users.
Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The non-readline branch of
Abc_UtilsGetUsersInputhas three behavioral gapsversus the readline branch that break callers driving abc as a coprocess
over a pipe — notably yosys's
passes/techmap/abc.cc, which spawnsabc -swith piped stdin/stdout and uses
read_until_abc_doneto wait forabc NN> <command>lines:Missing flush on the prompt. The prompt is written with
fprintf()and never flushed. On a pipe stdout is fully buffered, so the prompt
never reaches the reader. The reader waits for the prompt, abc waits
in
fgets(), deadlock.No echo of input.
readline()emits each character to its outputstream; yosys's protocol depends on seeing
abc NN> source ...\ninthe output to advance state. Without an echo it waits forever.
EOF ignored. When stdin closes,
fgets()returns NULL but thefunction returns a stale
Promptbuffer, causing a tight loop on pipeclose. The readline branch
exit(0)s on NULL.This patch fixes all three. The echo is gated on
!isatty(fileno(stdin))because on a tty the kernel already echoes during cooked input, and a
double echo would be visible to interactive users.
Reproduction
Without the patch, with an ABC_USE_READLINE=0 build:
The prompt appears (only because the pipe drained on exit, not on
flush) and the input is never echoed. yosys, which expects to see
`abc 01> source <script>` in the stream, hangs in `read()`.
With the patch, the same invocation produces:
which matches the output stream readline produces on the same input, and
unblocks yosys's coprocess driver.