aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKim F. Storm2004-02-16 23:13:13 +0000
committerKim F. Storm2004-02-16 23:13:13 +0000
commit9940231136a3a88bce8439d20e19928dbbc2edd1 (patch)
tree5ca94ec2b71c01e17716c3e347f092c4ce7c9018 /src
parentab90a54d2f8d29c5c441bf11564c81e4c2c9d5e5 (diff)
downloademacs-9940231136a3a88bce8439d20e19928dbbc2edd1.tar.gz
emacs-9940231136a3a88bce8439d20e19928dbbc2edd1.zip
Rework previous change; it didn't consider that the
buf array was allocated on the stack. (prev_read): Remove variable. (read_avail_input_buf): New static event buffer array. (in_read_avail_input): New static variable to avoid re-entrancy. (read_avail_input): Change buf to pinter to read_avail_input_buf. Use in_read_avail_input to guard against re-entry. Do not initialize read_avail_input_buf here; instead assume it is always cleared on entry. To ensure that, we clear (just) the entries that were used before we return. (init_keyboard): Initialize read_avail_input_buf here.
Diffstat (limited to 'src')
-rw-r--r--src/keyboard.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 3b9447f24b1..22610212c26 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6556,10 +6556,13 @@ record_asynch_buffer_change ()
6556 6556
6557#ifndef VMS 6557#ifndef VMS
6558 6558
6559/* This remembers the last number of characters read, so we could 6559/* We make the read_avail_input buffer static to avoid zeroing out the
6560 avoid zeroing out the whole struct input_event buf and instead zero 6560 whole struct input_event buf on every call. */
6561 out only its used slots. */ 6561static struct input_event read_avail_input_buf[KBD_BUFFER_SIZE];
6562static int prev_read = KBD_BUFFER_SIZE; 6562
6563/* I don't know whether it is necessary, but make read_avail_input
6564 re-entrant. */
6565static int in_read_avail_input = 0;
6563 6566
6564/* Read any terminal input already buffered up by the system 6567/* Read any terminal input already buffered up by the system
6565 into the kbd_buffer, but do not wait. 6568 into the kbd_buffer, but do not wait.
@@ -6577,12 +6580,14 @@ static int
6577read_avail_input (expected) 6580read_avail_input (expected)
6578 int expected; 6581 int expected;
6579{ 6582{
6580 struct input_event buf[KBD_BUFFER_SIZE]; 6583 struct input_event *buf = read_avail_input_buf;
6581 register int i; 6584 register int i;
6582 int nread; 6585 int nread;
6583 6586
6584 for (i = 0; i < prev_read; i++) 6587 /* Trivial hack to make read_avail_input re-entrant. */
6585 EVENT_INIT (buf[i]); 6588 if (in_read_avail_input)
6589 return 0;
6590 in_read_avail_input = 1;
6586 6591
6587 if (read_socket_hook) 6592 if (read_socket_hook)
6588 /* No need for FIONREAD or fcntl; just say don't wait. */ 6593 /* No need for FIONREAD or fcntl; just say don't wait. */
@@ -6597,12 +6602,12 @@ read_avail_input (expected)
6597 6602
6598 /* Determine how many characters we should *try* to read. */ 6603 /* Determine how many characters we should *try* to read. */
6599#ifdef WINDOWSNT 6604#ifdef WINDOWSNT
6600 return (prev_read = 0); 6605 return (in_read_avail_input = 0);
6601#else /* not WINDOWSNT */ 6606#else /* not WINDOWSNT */
6602#ifdef MSDOS 6607#ifdef MSDOS
6603 n_to_read = dos_keysns (); 6608 n_to_read = dos_keysns ();
6604 if (n_to_read == 0) 6609 if (n_to_read == 0)
6605 return (prev_read = 0); 6610 return (in_read_avail_input = 0);
6606#else /* not MSDOS */ 6611#else /* not MSDOS */
6607#ifdef FIONREAD 6612#ifdef FIONREAD
6608 /* Find out how much input is available. */ 6613 /* Find out how much input is available. */
@@ -6620,7 +6625,7 @@ read_avail_input (expected)
6620 n_to_read = 0; 6625 n_to_read = 0;
6621 } 6626 }
6622 if (n_to_read == 0) 6627 if (n_to_read == 0)
6623 return (prev_read = 0); 6628 return (in_read_avail_input = 0);
6624 if (n_to_read > sizeof cbuf) 6629 if (n_to_read > sizeof cbuf)
6625 n_to_read = sizeof cbuf; 6630 n_to_read = sizeof cbuf;
6626#else /* no FIONREAD */ 6631#else /* no FIONREAD */
@@ -6711,7 +6716,12 @@ read_avail_input (expected)
6711 break; 6716 break;
6712 } 6717 }
6713 6718
6714 return (prev_read = nread); 6719 /* Clear used events */
6720 for (i = 0; i < nread; i++)
6721 EVENT_INIT (buf[i]);
6722
6723 in_read_avail_input = 0;
6724 return nread;
6715} 6725}
6716#endif /* not VMS */ 6726#endif /* not VMS */
6717 6727
@@ -10541,6 +10551,14 @@ init_keyboard ()
10541 do_mouse_tracking = Qnil; 10551 do_mouse_tracking = Qnil;
10542#endif 10552#endif
10543 input_pending = 0; 10553 input_pending = 0;
10554#ifndef VMS
10555 {
10556 int i;
10557 for (i = 0; i < KBD_BUFFER_SIZE; i++)
10558 EVENT_INIT (read_avail_input_buf[i]);
10559 }
10560#endif
10561
10544 10562
10545 /* This means that command_loop_1 won't try to select anything the first 10563 /* This means that command_loop_1 won't try to select anything the first
10546 time through. */ 10564 time through. */