From d5a1acfaa5671f09cbb8da211a5283394d8b907f Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Thu, 15 Aug 2013 18:52:53 +0400 Subject: [PATCH] * lisp.h (FOR_EACH_ALIST_VALUE): New macro to do `for' loops over alist values. * buffer.h (FOR_EACH_BUFFER): * process.c (FOR_EACH_PROCESS): Use it. (handle_child_signal, status_notify, Fget_buffer_process) (kill_buffer_processes): Use FOR_EACH_PROCESS. --- src/ChangeLog | 9 +++++++++ src/buffer.h | 6 ++---- src/lisp.h | 6 ++++++ src/process.c | 47 +++++++++++++++++++++-------------------------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0d3982618b7..1ad3e1cff24 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-08-15 Dmitry Antipov + + * lisp.h (FOR_EACH_ALIST_VALUE): New macro + to do `for' loops over alist values. + * buffer.h (FOR_EACH_BUFFER): + * process.c (FOR_EACH_PROCESS): Use it. + (handle_child_signal, status_notify, Fget_buffer_process) + (kill_buffer_processes): Use FOR_EACH_PROCESS. + 2013-08-15 Dmitry Antipov * term.c (get_named_tty, create_tty_output, tty_free_frame_resources) diff --git a/src/buffer.h b/src/buffer.h index 221db39329a..55a9e8d2a1c 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1132,10 +1132,8 @@ extern Lisp_Object Qpriority, Qbefore_string, Qafter_string; /* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is a `for' loop which iterates over the buffers from Vbuffer_alist. */ -#define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \ - for (list_var = Vbuffer_alist; \ - (CONSP (list_var) && (buf_var = XCDR (XCAR (list_var)), 1)); \ - list_var = XCDR (list_var)) +#define FOR_EACH_LIVE_BUFFER(list_var, buf_var) \ + FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var) /* Get text properties of B. */ diff --git a/src/lisp.h b/src/lisp.h index 6d79bb1d6a5..e6e90e1e968 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4342,6 +4342,12 @@ extern void *record_xmalloc (size_t); memory_full (SIZE_MAX); \ } while (0) +/* Do a `for' loop over alist values. */ + +#define FOR_EACH_ALIST_VALUE(head_var, list_var, value_var) \ + for (list_var = head_var; \ + (CONSP (list_var) && (value_var = XCDR (XCAR (list_var)), 1)); \ + list_var = XCDR (list_var)) /* Check whether it's time for GC, and run it if so. */ diff --git a/src/process.c b/src/process.c index c803d69d6d8..892a5aa86c5 100644 --- a/src/process.c +++ b/src/process.c @@ -361,6 +361,12 @@ static struct sockaddr_and_len { #define DATAGRAM_CONN_P(proc) (0) #endif +/* FOR_EACH_PROCESS (LIST_VAR, PROC_VAR) followed by a statement is + a `for' loop which iterates over processes from Vprocess_alist. */ + +#define FOR_EACH_PROCESS(list_var, proc_var) \ + FOR_EACH_ALIST_VALUE (Vprocess_alist, list_var, proc_var) + /* These setters are used only in this file, so they can be private. */ static void pset_buffer (struct Lisp_Process *p, Lisp_Object val) @@ -6135,7 +6141,7 @@ static signal_handler_t volatile lib_child_handler; static void handle_child_signal (int sig) { - Lisp_Object tail; + Lisp_Object tail, proc; /* Find the process that signaled us, and record its status. */ @@ -6165,9 +6171,8 @@ handle_child_signal (int sig) } /* Otherwise, if it is asynchronous, it is in Vprocess_alist. */ - for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) + FOR_EACH_PROCESS (tail, proc) { - Lisp_Object proc = XCDR (XCAR (tail)); struct Lisp_Process *p = XPROCESS (proc); int status; @@ -6322,13 +6327,10 @@ status_notify (struct Lisp_Process *deleting_process) that we run, we get called again to handle their status changes. */ update_tick = process_tick; - for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) + FOR_EACH_PROCESS (tail, proc) { Lisp_Object symbol; - register struct Lisp_Process *p; - - proc = Fcdr (XCAR (tail)); - p = XPROCESS (proc); + register struct Lisp_Process *p = XPROCESS (proc); if (p->tick != p->update_tick) { @@ -6851,12 +6853,9 @@ BUFFER may be a buffer or the name of one. */) buf = Fget_buffer (buffer); if (NILP (buf)) return Qnil; - for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) - { - proc = Fcdr (XCAR (tail)); - if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf)) - return proc; - } + FOR_EACH_PROCESS (tail, proc) + if (EQ (XPROCESS (proc)->buffer, buf)) + return proc; #endif /* subprocesses */ return Qnil; } @@ -6889,18 +6888,14 @@ kill_buffer_processes (Lisp_Object buffer) #ifdef subprocesses Lisp_Object tail, proc; - for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) - { - proc = XCDR (XCAR (tail)); - if (PROCESSP (proc) - && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))) - { - if (NETCONN_P (proc) || SERIALCONN_P (proc)) - Fdelete_process (proc); - else if (XPROCESS (proc)->infd >= 0) - process_send_signal (proc, SIGHUP, Qnil, 1); - } - } + FOR_EACH_PROCESS (tail, proc) + if (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)) + { + if (NETCONN_P (proc) || SERIALCONN_P (proc)) + Fdelete_process (proc); + else if (XPROCESS (proc)->infd >= 0) + process_send_signal (proc, SIGHUP, Qnil, 1); + } #else /* subprocesses */ /* Since we have no subprocesses, this does nothing. */ #endif /* subprocesses */ -- 2.39.5