Jan Vroonhof <vroonhof(a)math.ethz.ch> writes:
> Gunnar Evermann <ge204(a)eng.cam.ac.uk> writes:
>
> > * process.c (Fprocess_input_coding_system): check whether process
> > is still alive
>
> Approved. Recommened for 21.1.
I think we should still apply the above patch to 21.1.
> > process = get_process (process);
> > + if (!PROCESS_LIVE_P (process))
> > + error ("Process %s is not active",
> > + XSTRING_DATA (XPROCESS (process)->name));
> > +
> > return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
>
> You might want to turn this into a CHECK_PROCESS_LIVE(process)
> macro[1], to be consistent with other such checks.
yes, good point. I had actually looked for.
I have now defined CHECK_LIVE_PROCESS and, to make all this consistent,
a Lisp Function process-live-p (why wasn´t that defined before? Surely
it is useful and nicer to use than process-status?).
I also made the existing PROCESS_LIVE_P consistent with the other
_LIVE_P macros and used it where possible (OK, so I got a bit carried
away hacking process.c :-).
There is one use of PROCESS_LIVE_P left (in process_send_signal) that
could be replaced by CHECK_LIVE_PROCESS. I haven´t done that yet
because the resulting error would be different (i.e. we wouldn´t print
the process name anymore). any opinions on that?
I´ll submit the crash test case for the test-suite separately.
I would appreciate comments from people more familiar with process.c
(Ben?).
1999-12-18 Gunnar Evermann <ge204(a)eng.cam.ac.uk>
* process.h (PROCESS_LIVE_P): Modify to take a Lisp_Process
instead of a Lisp_Object as argument to make it consistent with
the other LIVE_P macros.
(CHECK_LIVE_PROCESS): New macro.
* process.c: Declare Qprocess_live_p.
(Fprocess_live_p): New function.
(create_process): Use PROCESS_LIVE_P.
(read_process_output): Ditto.
(set_process_filter): Ditto.
(Fdelete_process): Ditto.
(kill_buffer_processes): Ditto
(Fprocess_input_coding_system): Check whether process is still
alive (fix PR#1061).
(Fprocess_output_coding_system): Ditto.
(Fprocess_coding_system): Ditto.
(Fset_process_input_coding_system): Ditto.
(Fset_process_output_coding_system): Ditto.
--- src/process.h.orig Sat Dec 18 16:39:02 1999
+++ src/process.h Sat Dec 18 16:39:11 1999
@@ -45,7 +45,13 @@
#define XSETPROCESS(x, p) XSETRECORD (x, p, process)
#define PROCESSP(x) RECORDP (x, process)
#define CHECK_PROCESS(x) CHECK_RECORD (x, process)
-#define PROCESS_LIVE_P(x) (!NILP (XPROCESS(x)->pipe_instream))
+#define PROCESS_LIVE_P(x) (!NILP ((x)->pipe_instream))
+
+#define CHECK_LIVE_PROCESS(x) do { \
+ CHECK_PROCESS (x); \
+ if (! PROCESS_LIVE_P (XPROCESS (x))) \
+ dead_wrong_type_argument (Qprocess_live_p, (x)); \
+} while (0)
#ifdef emacs
--- src/process.c.orig Sat Dec 18 16:43:27 1999
+++ src/process.c Sat Dec 18 17:32:40 1999
@@ -58,7 +58,7 @@
#include "systty.h"
#include "syswait.h"
-Lisp_Object Qprocessp;
+Lisp_Object Qprocessp, Qprocess_live_p;
/* Process methods */
struct process_methods the_process_methods;
@@ -257,6 +257,14 @@
return PROCESSP (obj) ? Qt : Qnil;
}
+DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /*
+Return t if OBJECT is a process that is alive.
+*/
+ (obj))
+{
+ return PROCESSP (obj) && PROCESS_LIVE_P (XPROCESS (obj)) ? Qt : Qnil;
+}
+
DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
Return a list of all processes.
*/
@@ -510,7 +518,7 @@
pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir));
p->pid = make_int (pid);
- if (!NILP(p->pipe_instream))
+ if (PROCESS_LIVE_P (p))
event_stream_select_process (p);
}
@@ -823,7 +831,7 @@
Really, the loop in execute_internal_event() should check itself
for a process-filter change, like in status_notify(); but the
struct Lisp_Process is not exported outside of this file. */
- if (NILP(p->pipe_instream))
+ if (!PROCESS_LIVE_P (p))
return -1; /* already closed */
if (!NILP (p->filter) && (p->filter_does_read))
@@ -1032,7 +1040,7 @@
set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
{
CHECK_PROCESS (proc);
- if (PROCESS_LIVE_P (proc)) {
+ if (PROCESS_LIVE_P (XPROCESS (proc))) {
if (EQ (filter, Qt))
event_stream_unselect_process (XPROCESS (proc));
else
@@ -1121,6 +1129,7 @@
(process))
{
process = get_process (process);
+ CHECK_LIVE_PROCESS (process);
return decoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_instream) );
}
@@ -1130,6 +1139,7 @@
(process))
{
process = get_process (process);
+ CHECK_LIVE_PROCESS (process);
return encoding_stream_coding_system (XLSTREAM (XPROCESS (process)->coding_outstream));
}
@@ -1139,6 +1149,7 @@
(process))
{
process = get_process (process);
+ CHECK_LIVE_PROCESS (process);
return Fcons (decoding_stream_coding_system
(XLSTREAM (XPROCESS (process)->coding_instream)),
encoding_stream_coding_system
@@ -1153,6 +1164,8 @@
{
codesys = Fget_coding_system (codesys);
process = get_process (process);
+ CHECK_LIVE_PROCESS (process);
+
set_decoding_stream_coding_system
(XLSTREAM (XPROCESS (process)->coding_instream), codesys);
return Qnil;
@@ -1166,6 +1179,8 @@
{
codesys = Fget_coding_system (codesys);
process = get_process (process);
+ CHECK_LIVE_PROCESS (process);
+
set_encoding_stream_coding_system
(XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
return Qnil;
@@ -1527,7 +1542,7 @@
if (network_connection_p (proc))
error ("Network connection %s is not a subprocess",
XSTRING_DATA (XPROCESS(proc)->name));
- if (!PROCESS_LIVE_P (proc))
+ if (!PROCESS_LIVE_P (XPROCESS (proc)))
error ("Process %s is not active",
XSTRING_DATA (XPROCESS(proc)->name));
@@ -1883,7 +1898,7 @@
p->tick++;
process_tick++;
}
- else if (!NILP(p->pipe_instream))
+ else if (PROCESS_LIVE_P (p))
{
Fkill_process (proc, Qnil);
/* Do this now, since remove_process will make sigchld_handler do nothing. */
@@ -1915,7 +1930,7 @@
{
if (network_connection_p (proc))
Fdelete_process (proc);
- else if (!NILP (XPROCESS (proc)->pipe_instream))
+ else if (PROCESS_LIVE_P (XPROCESS (proc)))
process_send_signal (proc, SIGHUP, 0, 1);
}
}
@@ -1978,6 +1993,7 @@
syms_of_process (void)
{
defsymbol (&Qprocessp, "processp");
+ defsymbol (&Qprocess_live_p, "process-live-p");
defsymbol (&Qrun, "run");
defsymbol (&Qstop, "stop");
defsymbol (&Qopen, "open");
@@ -1991,6 +2007,7 @@
#endif
DEFSUBR (Fprocessp);
+ DEFSUBR (Fprocess_live_p);
DEFSUBR (Fget_process);
DEFSUBR (Fget_buffer_process);
DEFSUBR (Fdelete_process);