On 6/24/12 6:08 PM, Max Horn wrote:
> Dear GNU readline team,
>
> I would like to report on an issue with readline 6.2 on Mac OS X 10.6.8 which
> does not occur with 6.1 and older. I also have reports for this on 10.7 and
> also on older Mac OS X systems.
>
> To reproduce the issue,
> 1) compile the attached sample program (or any other program that sets
> rl_event_hook),
> 2) run it inside Mac OS X' Terminal.app,
> 3) paste some text, e.g. this line.
>
> What happens is that you can see the text slowly appear, character by
> character, like in a bad sci-fi flick. Pressing any key will cause the
> remaining text to appear instantly.
>
> I traced this back to the change in input.c, in rl_read_key(), from 6.1 to
> 6.2. You see, on Mac OS X, if you paste a string, then all characters are
> instantly visible as input to the program. So, if you paste 50 chars, you
> will see 50 chars pending on stdin. Now when rl_event_hook is set, then
> rl_gather_tyi() is used to read pending input. This function proceeds to read
> all 50 pending characters at once. Previously, readline would then proceed to
> feed this input to the program. Specifically, this is the old loop:
They key is that the hook needs to be run after the check for already-read-
and-queued input, and it should only be run if rl_gather_tyi doesn't
detect any input available. That was the issue with bash-4.1/readline-6.1:
the input hook got run for every input character, whether anything was
available or not, making it very hard to use it as something that got run
after a specified timeout, for instance.
Here's a patch against bash-4.2. Applying it to a standalone readline
installation is left as an exercise for the reader. :-)
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.2-patched/lib/readline/input.c 2010-05-30 18:33:01.000000000 -0400
--- lib/readline/input.c 2012-06-25 21:08:42.000000000 -0400
***************
*** 410,414 ****
rl_read_key ()
{
! int c;
rl_key_sequence_length++;
--- 412,416 ----
rl_read_key ()
{
! int c, r;
rl_key_sequence_length++;
***************
*** 430,441 ****
while (rl_event_hook)
{
! if (rl_gather_tyi () < 0) /* XXX - EIO */
{
rl_done = 1;
return ('\n');
}
RL_CHECK_SIGNALS ();
- if (rl_get_char (&c) != 0)
- break;
if (rl_done) /* XXX - experimental */
return ('\n');
--- 432,447 ----
while (rl_event_hook)
{
! if (rl_get_char (&c) != 0)
! break;
!
! if ((r = rl_gather_tyi ()) < 0) /* XXX - EIO */
{
rl_done = 1;
return ('\n');
}
+ else if (r == 1) /* read something */
+ continue;
+
RL_CHECK_SIGNALS ();
if (rl_done) /* XXX - experimental */
return ('\n');
_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline