[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r113719: * process.c: Fix minor off-by-one issues in
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] trunk r113719: * process.c: Fix minor off-by-one issues in descriptor counts. |
Date: |
Tue, 06 Aug 2013 14:17:28 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 113719
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Tue 2013-08-06 07:17:25 -0700
message:
* process.c: Fix minor off-by-one issues in descriptor counts.
This shouldn't fix any real bugs, but it cleans up the code a bit.
(max_process_desc, max_input_desc): -1, not 0, means none.
All uses changed.
(delete_input_desc): New function.
(delete_write_fd, delete_keyboard_wait_descriptor): Use it.
(deactivate_process): Scan backwards when recomuting max_process_desc;
that should be faster.
(init_process_emacs): Initialize max_input_desc.
modified:
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/process.c process.c-20091113204419-o5vbwnq5f7feedwu-462
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-08-06 06:53:09 +0000
+++ b/src/ChangeLog 2013-08-06 14:17:25 +0000
@@ -1,3 +1,15 @@
+2013-08-06 Paul Eggert <address@hidden>
+
+ * process.c: Fix minor off-by-one issues in descriptor counts.
+ This shouldn't fix any real bugs, but it cleans up the code a bit.
+ (max_process_desc, max_input_desc): -1, not 0, means none.
+ All uses changed.
+ (delete_input_desc): New function.
+ (delete_write_fd, delete_keyboard_wait_descriptor): Use it.
+ (deactivate_process): Scan backwards when recomuting max_process_desc;
+ that should be faster.
+ (init_process_emacs): Initialize max_input_desc.
+
2013-08-06 Dmitry Antipov <address@hidden>
Use region cache to speedup bidi_find_paragraph_start.
=== modified file 'src/process.c'
--- a/src/process.c 2013-07-26 18:48:05 +0000
+++ b/src/process.c 2013-08-06 14:17:25 +0000
@@ -323,10 +323,10 @@
static int num_pending_connects;
#endif /* NON_BLOCKING_CONNECT */
-/* The largest descriptor currently in use for a process object. */
+/* The largest descriptor currently in use for a process object; -1 if none.
*/
static int max_process_desc;
-/* The largest descriptor currently in use for input. */
+/* The largest descriptor currently in use for input; -1 if none. */
static int max_input_desc;
/* Indexed by descriptor, gives the process (if any) for that descriptor */
@@ -500,13 +500,27 @@
fd_callback_info[fd].condition |= FOR_WRITE;
}
+/* FD is no longer an input descriptor; update max_input_desc accordingly. */
+
+static void
+delete_input_desc (int fd)
+{
+ if (fd == max_input_desc)
+ {
+ do
+ fd--;
+ while (0 <= fd && ! (FD_ISSET (fd, &input_wait_mask)
+ || FD_ISSET (fd, &write_mask)));
+
+ max_input_desc = fd;
+ }
+}
+
/* Stop monitoring file descriptor FD for when write is possible. */
void
delete_write_fd (int fd)
{
- int lim = max_input_desc;
-
eassert (fd < MAXDESC);
FD_CLR (fd, &write_mask);
fd_callback_info[fd].condition &= ~FOR_WRITE;
@@ -514,15 +528,7 @@
{
fd_callback_info[fd].func = 0;
fd_callback_info[fd].data = 0;
-
- if (fd == max_input_desc)
- for (fd = lim; fd >= 0; fd--)
- if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
- {
- max_input_desc = fd;
- break;
- }
-
+ delete_input_desc (fd);
}
}
@@ -3831,13 +3837,14 @@
#endif
if (inchannel == max_process_desc)
{
- int i;
/* We just closed the highest-numbered process input descriptor,
so recompute the highest-numbered one now. */
- max_process_desc = 0;
- for (i = 0; i < MAXDESC; i++)
- if (!NILP (chan_process[i]))
- max_process_desc = i;
+ int i = inchannel;
+ do
+ i--;
+ while (0 <= i && NILP (chan_process[i]));
+
+ max_process_desc = i;
}
}
}
@@ -6763,16 +6770,9 @@
delete_keyboard_wait_descriptor (int desc)
{
#ifdef subprocesses
- int fd;
- int lim = max_input_desc;
-
FD_CLR (desc, &input_wait_mask);
FD_CLR (desc, &non_process_wait_mask);
-
- if (desc == max_input_desc)
- for (fd = 0; fd < lim; fd++)
- if (FD_ISSET (fd, &input_wait_mask) || FD_ISSET (fd, &write_mask))
- max_input_desc = fd;
+ delete_input_desc (desc);
#endif
}
@@ -7037,7 +7037,7 @@
FD_ZERO (&non_keyboard_wait_mask);
FD_ZERO (&non_process_wait_mask);
FD_ZERO (&write_mask);
- max_process_desc = 0;
+ max_process_desc = max_input_desc = -1;
memset (fd_callback_info, 0, sizeof (fd_callback_info));
#ifdef NON_BLOCKING_CONNECT
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r113719: * process.c: Fix minor off-by-one issues in descriptor counts.,
Paul Eggert <=