Approved. You did exactly right, except for this:
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?
When a process is printed, so is its name, so why wouldn't it be printed here?
But ...
If you want to be more adventurous, I'd suggest some more general changes to make
these type
errors clearer. I've always hated these. For example:
1. How about this:
Wrong type: wanted an event, got a vector: [down-button 2]
instead of
Wrong type argument: eventp, [down-button 2]
I think it especially helps with inexperienced Lisp users (or migrating FSF Emacsers), who
tend to
substitute amorphous types for objects. To fix this, all you'd have to change is
display-error (I
think).
2. How about this:
Wrong type: wanted a live process, got a dead one: #<process ...>
instead of
Wrong type argument: process-live-p, #<process ...>
Again, just a change to display-error.
3. BLUE SKY ALERT: What would be even better would be if the error would also print
something
about what function it's in, but that's harder. Depending on exactly what we
would want to do, it
might require as much as a truly Martin-like feat such as expanding the CHECK_* macros to
contain
an extra argument (the name of the Lisp primitive that's being called) and fixing
*every*
invocation to include this; or it could take the much simpler (but less accurate) approach
of just
looking at the Lisp call stack and munging appropriately. (Hmm, isn't there a one- or
two-line
backtrace output function that I wrote at some point that might be useful?)
ben
Gunnar Evermann wrote:
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);
--
In order to save my hands, I am cutting back on my responses, especially
to XEmacs-related mail. You _will_ get a response, but please be patient.
If you need an immediate response and it is not apparent in your message,
please say so. Thanks for your understanding.