NetBSD Problem Report #52518

From www@NetBSD.org  Thu Aug 31 22:08:32 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id AD5507A1AE
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 31 Aug 2017 22:08:32 +0000 (UTC)
Message-Id: <20170831220831.7F5367A2A5@mollari.NetBSD.org>
Date: Thu, 31 Aug 2017 22:08:31 +0000 (UTC)
From: jhdub23@gmail.com
Reply-To: jhdub23@gmail.com
To: gnats-bugs@NetBSD.org
Subject: prompt is interleaved with client output.
X-Send-Pr-Version: www-1.0

>Number:         52518
>Category:       lib
>Synopsis:       prompt is interleaved with client output.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 31 22:10:00 +0000 2017
>Closed-Date:    Mon Jun 04 10:56:00 +0000 2018
>Last-Modified:  Mon Jun 04 10:56:00 +0000 2018
>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);
 	}
 }

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Mon, 04 Jun 2018 10:56:00 +0000
State-Changed-Why:
Committed by christos who referenced the wrong PR. Thanks for the patch & report!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.