NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/52518: prompt is interleaved with client output.



>Number:         52518
>Category:       lib
>Synopsis:       prompt is interleaved with client output.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 31 22:10:00 +0000 2017
>Originator:     Jay West
>Release:        libedit (NetBSD-current)
>Organization:
Self
>Environment:
Linux [deleted] 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
>Description:
libedit reverses the order of printing client output and prompt.  After reading input, the prompt is printed, followed by client output.  Expected order is read input, client output, prompt (upon next read request).

Applications using libedit as a drop in replacement of the GNU Readline library will see this behavior.  Specifically, this issue was found compiling python-2.7.13 with libedit instead of Gnu readline.


>How-To-Repeat:
Bad input/output:

% python # Run python compiled with libedit
>> print 5
>> 5
print 6
>> 6

Expected input/output:

% python # Run python compiled with Gnu readline
>> print 5
5
>> print 6
6
>> 


>Fix:
The problem seems to be that the prompt is printed immediately after reading input, before returning control to the client program (which may do additional printing before the next read request).  The following patch causes the prompt to be printed upon the next read request.

-------------------------

diff --git a/src/readline.c b/src/readline.c
index 2e0e2c4eaf..0841067c46 100644
--- a/src/readline.c
+++ b/src/readline.c
@@ -2016,6 +2017,8 @@ rl_add_defun(const char *name, rl_command_func_t *fun, int c)
 void
 rl_callback_read_char(void)
 {
+	el_set(e, EL_UNBUFFERED, 1);
+
 	int count = 0, done = 0;
 	const char *buf = el_gets(e, &count);
 	char *wbuf;
@@ -2035,7 +2038,6 @@ rl_callback_read_char(void)
 		} else
 			wbuf = NULL;
 		(*(void (*)(const char *))rl_linefunc)(wbuf);
-		el_set(e, EL_UNBUFFERED, 1);
 	}
 }



Home | Main Index | Thread Index | Old Index