diff options
| author | Tom Tromey | 2013-06-03 12:25:05 -0600 |
|---|---|---|
| committer | Tom Tromey | 2013-06-03 12:25:05 -0600 |
| commit | 68359abba96d7ec4db8aab3d3dd9cf1105c3bab5 (patch) | |
| tree | 862703e7e1a1888170136a8296a5750d6b2ae2eb /src/process.c | |
| parent | cbcba8ce7f980b01c18c0fd561ef6687b1361507 (diff) | |
| parent | e2d8a6f0a229b4ebe26484b892ec4f14888f58b6 (diff) | |
| download | emacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.tar.gz emacs-68359abba96d7ec4db8aab3d3dd9cf1105c3bab5.zip | |
merge from trunk; clean up some issues
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 502 |
1 files changed, 262 insertions, 240 deletions
diff --git a/src/process.c b/src/process.c index e8e7a2be7be..c1726e7ad60 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -136,7 +136,7 @@ extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |||
| 136 | /* Work around GCC 4.7.0 bug with strict overflow checking; see | 136 | /* Work around GCC 4.7.0 bug with strict overflow checking; see |
| 137 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. | 137 | <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52904>. |
| 138 | These lines can be removed once the GCC bug is fixed. */ | 138 | These lines can be removed once the GCC bug is fixed. */ |
| 139 | #if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ | 139 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) |
| 140 | # pragma GCC diagnostic ignored "-Wstrict-overflow" | 140 | # pragma GCC diagnostic ignored "-Wstrict-overflow" |
| 141 | #endif | 141 | #endif |
| 142 | 142 | ||
| @@ -174,6 +174,8 @@ static Lisp_Object QClocal, QCremote, QCcoding; | |||
| 174 | static Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; | 174 | static Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; |
| 175 | static Lisp_Object QCsentinel, QClog, QCoptions, QCplist; | 175 | static Lisp_Object QCsentinel, QClog, QCoptions, QCplist; |
| 176 | static Lisp_Object Qlast_nonmenu_event; | 176 | static Lisp_Object Qlast_nonmenu_event; |
| 177 | static Lisp_Object Qinternal_default_process_sentinel; | ||
| 178 | static Lisp_Object Qinternal_default_process_filter; | ||
| 177 | 179 | ||
| 178 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) | 180 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) |
| 179 | #define NETCONN1_P(p) (EQ (p->type, Qnetwork)) | 181 | #define NETCONN1_P(p) (EQ (p->type, Qnetwork)) |
| @@ -334,7 +336,7 @@ pset_encoding_buf (struct Lisp_Process *p, Lisp_Object val) | |||
| 334 | static void | 336 | static void |
| 335 | pset_filter (struct Lisp_Process *p, Lisp_Object val) | 337 | pset_filter (struct Lisp_Process *p, Lisp_Object val) |
| 336 | { | 338 | { |
| 337 | p->filter = val; | 339 | p->filter = NILP (val) ? Qinternal_default_process_filter : val; |
| 338 | } | 340 | } |
| 339 | static void | 341 | static void |
| 340 | pset_log (struct Lisp_Process *p, Lisp_Object val) | 342 | pset_log (struct Lisp_Process *p, Lisp_Object val) |
| @@ -364,7 +366,7 @@ pset_plist (struct Lisp_Process *p, Lisp_Object val) | |||
| 364 | static void | 366 | static void |
| 365 | pset_sentinel (struct Lisp_Process *p, Lisp_Object val) | 367 | pset_sentinel (struct Lisp_Process *p, Lisp_Object val) |
| 366 | { | 368 | { |
| 367 | p->sentinel = val; | 369 | p->sentinel = NILP (val) ? Qinternal_default_process_sentinel : val; |
| 368 | } | 370 | } |
| 369 | static void | 371 | static void |
| 370 | pset_status (struct Lisp_Process *p, Lisp_Object val) | 372 | pset_status (struct Lisp_Process *p, Lisp_Object val) |
| @@ -846,6 +848,8 @@ make_process (Lisp_Object name) | |||
| 846 | } | 848 | } |
| 847 | name = name1; | 849 | name = name1; |
| 848 | pset_name (p, name); | 850 | pset_name (p, name); |
| 851 | pset_sentinel (p, Qinternal_default_process_sentinel); | ||
| 852 | pset_filter (p, Qinternal_default_process_filter); | ||
| 849 | XSETPROCESS (val, p); | 853 | XSETPROCESS (val, p); |
| 850 | Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist); | 854 | Vprocess_alist = Fcons (Fcons (name, val), Vprocess_alist); |
| 851 | return val; | 855 | return val; |
| @@ -1146,10 +1150,10 @@ DEFUN ("process-mark", Fprocess_mark, Sprocess_mark, | |||
| 1146 | 1150 | ||
| 1147 | DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter, | 1151 | DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter, |
| 1148 | 2, 2, 0, | 1152 | 2, 2, 0, |
| 1149 | doc: /* Give PROCESS the filter function FILTER; nil means no filter. | 1153 | doc: /* Give PROCESS the filter function FILTER; nil means default. |
| 1150 | A value of t means stop accepting output from the process. | 1154 | A value of t means stop accepting output from the process. |
| 1151 | 1155 | ||
| 1152 | When a process has a filter, its buffer is not used for output. | 1156 | When a process has a non-default filter, its buffer is not used for output. |
| 1153 | Instead, each time it does output, the entire string of output is | 1157 | Instead, each time it does output, the entire string of output is |
| 1154 | passed to the filter. | 1158 | passed to the filter. |
| 1155 | 1159 | ||
| @@ -1175,6 +1179,9 @@ The string argument is normally a multibyte string, except: | |||
| 1175 | (debug) | 1179 | (debug) |
| 1176 | (set-process-filter process ...) */ | 1180 | (set-process-filter process ...) */ |
| 1177 | 1181 | ||
| 1182 | if (NILP (filter)) | ||
| 1183 | filter = Qinternal_default_process_filter; | ||
| 1184 | |||
| 1178 | if (p->infd >= 0) | 1185 | if (p->infd >= 0) |
| 1179 | { | 1186 | { |
| 1180 | if (EQ (filter, Qt) && !EQ (p->status, Qlisten)) | 1187 | if (EQ (filter, Qt) && !EQ (p->status, Qlisten)) |
| @@ -1194,7 +1201,7 @@ The string argument is normally a multibyte string, except: | |||
| 1194 | 1201 | ||
| 1195 | DEFUN ("process-filter", Fprocess_filter, Sprocess_filter, | 1202 | DEFUN ("process-filter", Fprocess_filter, Sprocess_filter, |
| 1196 | 1, 1, 0, | 1203 | 1, 1, 0, |
| 1197 | doc: /* Returns the filter function of PROCESS; nil if none. | 1204 | doc: /* Return the filter function of PROCESS. |
| 1198 | See `set-process-filter' for more info on filter functions. */) | 1205 | See `set-process-filter' for more info on filter functions. */) |
| 1199 | (register Lisp_Object process) | 1206 | (register Lisp_Object process) |
| 1200 | { | 1207 | { |
| @@ -1204,7 +1211,7 @@ See `set-process-filter' for more info on filter functions. */) | |||
| 1204 | 1211 | ||
| 1205 | DEFUN ("set-process-sentinel", Fset_process_sentinel, Sset_process_sentinel, | 1212 | DEFUN ("set-process-sentinel", Fset_process_sentinel, Sset_process_sentinel, |
| 1206 | 2, 2, 0, | 1213 | 2, 2, 0, |
| 1207 | doc: /* Give PROCESS the sentinel SENTINEL; nil for none. | 1214 | doc: /* Give PROCESS the sentinel SENTINEL; nil for default. |
| 1208 | The sentinel is called as a function when the process changes state. | 1215 | The sentinel is called as a function when the process changes state. |
| 1209 | It gets two arguments: the process, and a string describing the change. */) | 1216 | It gets two arguments: the process, and a string describing the change. */) |
| 1210 | (register Lisp_Object process, Lisp_Object sentinel) | 1217 | (register Lisp_Object process, Lisp_Object sentinel) |
| @@ -1214,6 +1221,9 @@ It gets two arguments: the process, and a string describing the change. */) | |||
| 1214 | CHECK_PROCESS (process); | 1221 | CHECK_PROCESS (process); |
| 1215 | p = XPROCESS (process); | 1222 | p = XPROCESS (process); |
| 1216 | 1223 | ||
| 1224 | if (NILP (sentinel)) | ||
| 1225 | sentinel = Qinternal_default_process_sentinel; | ||
| 1226 | |||
| 1217 | pset_sentinel (p, sentinel); | 1227 | pset_sentinel (p, sentinel); |
| 1218 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) | 1228 | if (NETCONN1_P (p) || SERIALCONN1_P (p)) |
| 1219 | pset_childp (p, Fplist_put (p->childp, QCsentinel, sentinel)); | 1229 | pset_childp (p, Fplist_put (p->childp, QCsentinel, sentinel)); |
| @@ -1222,7 +1232,7 @@ It gets two arguments: the process, and a string describing the change. */) | |||
| 1222 | 1232 | ||
| 1223 | DEFUN ("process-sentinel", Fprocess_sentinel, Sprocess_sentinel, | 1233 | DEFUN ("process-sentinel", Fprocess_sentinel, Sprocess_sentinel, |
| 1224 | 1, 1, 0, | 1234 | 1, 1, 0, |
| 1225 | doc: /* Return the sentinel of PROCESS; nil if none. | 1235 | doc: /* Return the sentinel of PROCESS. |
| 1226 | See `set-process-sentinel' for more info on sentinels. */) | 1236 | See `set-process-sentinel' for more info on sentinels. */) |
| 1227 | (register Lisp_Object process) | 1237 | (register Lisp_Object process) |
| 1228 | { | 1238 | { |
| @@ -1575,8 +1585,8 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) | |||
| 1575 | pset_plist (XPROCESS (proc), Qnil); | 1585 | pset_plist (XPROCESS (proc), Qnil); |
| 1576 | pset_type (XPROCESS (proc), Qreal); | 1586 | pset_type (XPROCESS (proc), Qreal); |
| 1577 | pset_buffer (XPROCESS (proc), buffer); | 1587 | pset_buffer (XPROCESS (proc), buffer); |
| 1578 | pset_sentinel (XPROCESS (proc), Qnil); | 1588 | pset_sentinel (XPROCESS (proc), Qinternal_default_process_sentinel); |
| 1579 | pset_filter (XPROCESS (proc), Qnil); | 1589 | pset_filter (XPROCESS (proc), Qinternal_default_process_filter); |
| 1580 | pset_command (XPROCESS (proc), Flist (nargs - 2, args + 2)); | 1590 | pset_command (XPROCESS (proc), Flist (nargs - 2, args + 2)); |
| 1581 | 1591 | ||
| 1582 | #ifdef HAVE_GNUTLS | 1592 | #ifdef HAVE_GNUTLS |
| @@ -1998,7 +2008,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |||
| 1998 | /* Back in the parent process. */ | 2008 | /* Back in the parent process. */ |
| 1999 | 2009 | ||
| 2000 | XPROCESS (process)->pid = pid; | 2010 | XPROCESS (process)->pid = pid; |
| 2001 | if (0 <= pid) | 2011 | if (pid >= 0) |
| 2002 | XPROCESS (process)->alive = 1; | 2012 | XPROCESS (process)->alive = 1; |
| 2003 | 2013 | ||
| 2004 | /* Stop blocking signals in the parent. */ | 2014 | /* Stop blocking signals in the parent. */ |
| @@ -2346,7 +2356,7 @@ Returns nil upon error setting address, ADDRESS otherwise. */) | |||
| 2346 | channel = XPROCESS (process)->infd; | 2356 | channel = XPROCESS (process)->infd; |
| 2347 | 2357 | ||
| 2348 | len = get_lisp_to_sockaddr_size (address, &family); | 2358 | len = get_lisp_to_sockaddr_size (address, &family); |
| 2349 | if (datagram_address[channel].len != len) | 2359 | if (len == 0 || datagram_address[channel].len != len) |
| 2350 | return Qnil; | 2360 | return Qnil; |
| 2351 | conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len); | 2361 | conv_lisp_to_sockaddr (family, address, datagram_address[channel].sa, len); |
| 2352 | return address; | 2362 | return address; |
| @@ -3457,7 +3467,8 @@ usage: (make-network-process &rest ARGS) */) | |||
| 3457 | { | 3467 | { |
| 3458 | int rfamily, rlen; | 3468 | int rfamily, rlen; |
| 3459 | rlen = get_lisp_to_sockaddr_size (remote, &rfamily); | 3469 | rlen = get_lisp_to_sockaddr_size (remote, &rfamily); |
| 3460 | if (rfamily == lres->ai_family && rlen == lres->ai_addrlen) | 3470 | if (rlen != 0 && rfamily == lres->ai_family |
| 3471 | && rlen == lres->ai_addrlen) | ||
| 3461 | conv_lisp_to_sockaddr (rfamily, remote, | 3472 | conv_lisp_to_sockaddr (rfamily, remote, |
| 3462 | datagram_address[s].sa, rlen); | 3473 | datagram_address[s].sa, rlen); |
| 3463 | } | 3474 | } |
| @@ -4077,7 +4088,7 @@ Return non-nil if we received any output before the timeout expired. */) | |||
| 4077 | { | 4088 | { |
| 4078 | if (INTEGERP (seconds)) | 4089 | if (INTEGERP (seconds)) |
| 4079 | { | 4090 | { |
| 4080 | if (0 < XINT (seconds)) | 4091 | if (XINT (seconds) > 0) |
| 4081 | { | 4092 | { |
| 4082 | secs = XINT (seconds); | 4093 | secs = XINT (seconds); |
| 4083 | nsecs = 0; | 4094 | nsecs = 0; |
| @@ -4085,7 +4096,7 @@ Return non-nil if we received any output before the timeout expired. */) | |||
| 4085 | } | 4096 | } |
| 4086 | else if (FLOATP (seconds)) | 4097 | else if (FLOATP (seconds)) |
| 4087 | { | 4098 | { |
| 4088 | if (0 < XFLOAT_DATA (seconds)) | 4099 | if (XFLOAT_DATA (seconds) > 0) |
| 4089 | { | 4100 | { |
| 4090 | EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); | 4101 | EMACS_TIME t = EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (seconds)); |
| 4091 | secs = min (EMACS_SECS (t), WAIT_READING_MAX); | 4102 | secs = min (EMACS_SECS (t), WAIT_READING_MAX); |
| @@ -4215,7 +4226,8 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4215 | process name of the server process concatenated with the caller | 4226 | process name of the server process concatenated with the caller |
| 4216 | identification. */ | 4227 | identification. */ |
| 4217 | 4228 | ||
| 4218 | if (!NILP (ps->filter) && !EQ (ps->filter, Qt)) | 4229 | if (!(EQ (ps->filter, Qinternal_default_process_filter) |
| 4230 | || EQ (ps->filter, Qt))) | ||
| 4219 | buffer = Qnil; | 4231 | buffer = Qnil; |
| 4220 | else | 4232 | else |
| 4221 | { | 4233 | { |
| @@ -4278,7 +4290,7 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4278 | /* Setup coding system for new process based on server process. | 4290 | /* Setup coding system for new process based on server process. |
| 4279 | This seems to be the proper thing to do, as the coding system | 4291 | This seems to be the proper thing to do, as the coding system |
| 4280 | of the new process should reflect the settings at the time the | 4292 | of the new process should reflect the settings at the time the |
| 4281 | server socket was opened; not the current settings. */ | 4293 | server socket was opened; not the current settings. */ |
| 4282 | 4294 | ||
| 4283 | pset_decode_coding_system (p, ps->decode_coding_system); | 4295 | pset_decode_coding_system (p, ps->decode_coding_system); |
| 4284 | pset_encode_coding_system (p, ps->encode_coding_system); | 4296 | pset_encode_coding_system (p, ps->encode_coding_system); |
| @@ -4297,11 +4309,10 @@ server_accept_connection (Lisp_Object server, int channel) | |||
| 4297 | (STRINGP (host) ? host : build_string ("-")), | 4309 | (STRINGP (host) ? host : build_string ("-")), |
| 4298 | build_string ("\n"))); | 4310 | build_string ("\n"))); |
| 4299 | 4311 | ||
| 4300 | if (!NILP (p->sentinel)) | 4312 | exec_sentinel (proc, |
| 4301 | exec_sentinel (proc, | 4313 | concat3 (build_string ("open from "), |
| 4302 | concat3 (build_string ("open from "), | 4314 | (STRINGP (host) ? host : build_string ("-")), |
| 4303 | (STRINGP (host) ? host : build_string ("-")), | 4315 | build_string ("\n"))); |
| 4304 | build_string ("\n"))); | ||
| 4305 | } | 4316 | } |
| 4306 | 4317 | ||
| 4307 | static Lisp_Object | 4318 | static Lisp_Object |
| @@ -4405,7 +4416,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4405 | 4416 | ||
| 4406 | /* Since we may need to wait several times, | 4417 | /* Since we may need to wait several times, |
| 4407 | compute the absolute time to return at. */ | 4418 | compute the absolute time to return at. */ |
| 4408 | if (time_limit || 0 < nsecs) | 4419 | if (time_limit || nsecs > 0) |
| 4409 | { | 4420 | { |
| 4410 | timeout = make_emacs_time (time_limit, nsecs); | 4421 | timeout = make_emacs_time (time_limit, nsecs); |
| 4411 | end_time = add_emacs_time (current_emacs_time (), timeout); | 4422 | end_time = add_emacs_time (current_emacs_time (), timeout); |
| @@ -4427,8 +4438,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4427 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 4438 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| 4428 | break; | 4439 | break; |
| 4429 | 4440 | ||
| 4430 | /* Compute time from now till when time limit is up */ | 4441 | /* Compute time from now till when time limit is up. */ |
| 4431 | /* Exit if already run out */ | 4442 | /* Exit if already run out. */ |
| 4432 | if (nsecs < 0) | 4443 | if (nsecs < 0) |
| 4433 | { | 4444 | { |
| 4434 | /* A negative timeout means | 4445 | /* A negative timeout means |
| @@ -4437,7 +4448,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4437 | 4448 | ||
| 4438 | timeout = make_emacs_time (0, 0); | 4449 | timeout = make_emacs_time (0, 0); |
| 4439 | } | 4450 | } |
| 4440 | else if (time_limit || 0 < nsecs) | 4451 | else if (time_limit || nsecs > 0) |
| 4441 | { | 4452 | { |
| 4442 | EMACS_TIME now = current_emacs_time (); | 4453 | EMACS_TIME now = current_emacs_time (); |
| 4443 | if (EMACS_TIME_LE (end_time, now)) | 4454 | if (EMACS_TIME_LE (end_time, now)) |
| @@ -4489,7 +4500,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4489 | break; | 4500 | break; |
| 4490 | 4501 | ||
| 4491 | /* A negative timeout means do not wait at all. */ | 4502 | /* A negative timeout means do not wait at all. */ |
| 4492 | if (0 <= nsecs) | 4503 | if (nsecs >= 0) |
| 4493 | { | 4504 | { |
| 4494 | if (EMACS_TIME_VALID_P (timer_delay)) | 4505 | if (EMACS_TIME_VALID_P (timer_delay)) |
| 4495 | { | 4506 | { |
| @@ -4571,7 +4582,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4571 | if (nread == 0) | 4582 | if (nread == 0) |
| 4572 | break; | 4583 | break; |
| 4573 | 4584 | ||
| 4574 | if (0 < nread) | 4585 | if (nread > 0) |
| 4575 | { | 4586 | { |
| 4576 | total_nread += nread; | 4587 | total_nread += nread; |
| 4577 | got_some_input = 1; | 4588 | got_some_input = 1; |
| @@ -5029,8 +5040,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 5029 | } | 5040 | } |
| 5030 | } | 5041 | } |
| 5031 | #endif /* NON_BLOCKING_CONNECT */ | 5042 | #endif /* NON_BLOCKING_CONNECT */ |
| 5032 | } /* end for each file descriptor */ | 5043 | } /* End for each file descriptor. */ |
| 5033 | } /* end while exit conditions not met */ | 5044 | } /* End while exit conditions not met. */ |
| 5034 | 5045 | ||
| 5035 | unbind_to (count, Qnil); | 5046 | unbind_to (count, Qnil); |
| 5036 | 5047 | ||
| @@ -5065,6 +5076,11 @@ read_process_output_error_handler (Lisp_Object error_val) | |||
| 5065 | return Qt; | 5076 | return Qt; |
| 5066 | } | 5077 | } |
| 5067 | 5078 | ||
| 5079 | static void | ||
| 5080 | read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, | ||
| 5081 | ssize_t nbytes, | ||
| 5082 | struct coding_system *coding); | ||
| 5083 | |||
| 5068 | /* Read pending output from the process channel, | 5084 | /* Read pending output from the process channel, |
| 5069 | starting with our buffered-ahead character if we have one. | 5085 | starting with our buffered-ahead character if we have one. |
| 5070 | Yield number of decoded characters read. | 5086 | Yield number of decoded characters read. |
| @@ -5081,9 +5097,7 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5081 | { | 5097 | { |
| 5082 | register ssize_t nbytes; | 5098 | register ssize_t nbytes; |
| 5083 | char *chars; | 5099 | char *chars; |
| 5084 | register Lisp_Object outstream; | ||
| 5085 | register struct Lisp_Process *p = XPROCESS (proc); | 5100 | register struct Lisp_Process *p = XPROCESS (proc); |
| 5086 | register ptrdiff_t opoint; | ||
| 5087 | struct coding_system *coding = proc_decode_coding_system[channel]; | 5101 | struct coding_system *coding = proc_decode_coding_system[channel]; |
| 5088 | int carryover = p->decoding_carryover; | 5102 | int carryover = p->decoding_carryover; |
| 5089 | int readmax = 4096; | 5103 | int readmax = 4096; |
| @@ -5106,7 +5120,7 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5106 | else | 5120 | else |
| 5107 | #endif | 5121 | #endif |
| 5108 | { | 5122 | { |
| 5109 | bool buffered = 0 <= proc_buffered_char[channel]; | 5123 | bool buffered = proc_buffered_char[channel] >= 0; |
| 5110 | if (buffered) | 5124 | if (buffered) |
| 5111 | { | 5125 | { |
| 5112 | chars[carryover] = proc_buffered_char[channel]; | 5126 | chars[carryover] = proc_buffered_char[channel]; |
| @@ -5171,122 +5185,144 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5171 | friends don't expect current-buffer to be changed from under them. */ | 5185 | friends don't expect current-buffer to be changed from under them. */ |
| 5172 | record_unwind_current_buffer (); | 5186 | record_unwind_current_buffer (); |
| 5173 | 5187 | ||
| 5174 | /* Read and dispose of the process output. */ | 5188 | read_and_dispose_of_process_output (p, chars, nbytes, coding); |
| 5175 | outstream = p->filter; | 5189 | |
| 5176 | if (!NILP (outstream)) | 5190 | /* Handling the process output should not deactivate the mark. */ |
| 5177 | { | 5191 | Vdeactivate_mark = odeactivate; |
| 5178 | Lisp_Object text; | 5192 | |
| 5179 | bool outer_running_asynch_code = running_asynch_code; | 5193 | unbind_to (count, Qnil); |
| 5180 | int waiting = waiting_for_user_input_p; | 5194 | return nbytes; |
| 5195 | } | ||
| 5181 | 5196 | ||
| 5182 | /* No need to gcpro these, because all we do with them later | 5197 | static void |
| 5183 | is test them for EQness, and none of them should be a string. */ | 5198 | read_and_dispose_of_process_output (struct Lisp_Process *p, char *chars, |
| 5199 | ssize_t nbytes, | ||
| 5200 | struct coding_system *coding) | ||
| 5201 | { | ||
| 5202 | Lisp_Object outstream = p->filter; | ||
| 5203 | Lisp_Object text; | ||
| 5204 | bool outer_running_asynch_code = running_asynch_code; | ||
| 5205 | int waiting = waiting_for_user_input_p; | ||
| 5206 | |||
| 5207 | /* No need to gcpro these, because all we do with them later | ||
| 5208 | is test them for EQness, and none of them should be a string. */ | ||
| 5184 | #if 0 | 5209 | #if 0 |
| 5185 | Lisp_Object obuffer, okeymap; | 5210 | Lisp_Object obuffer, okeymap; |
| 5186 | XSETBUFFER (obuffer, current_buffer); | 5211 | XSETBUFFER (obuffer, current_buffer); |
| 5187 | okeymap = BVAR (current_buffer, keymap); | 5212 | okeymap = BVAR (current_buffer, keymap); |
| 5188 | #endif | 5213 | #endif |
| 5189 | 5214 | ||
| 5190 | /* We inhibit quit here instead of just catching it so that | 5215 | /* We inhibit quit here instead of just catching it so that |
| 5191 | hitting ^G when a filter happens to be running won't screw | 5216 | hitting ^G when a filter happens to be running won't screw |
| 5192 | it up. */ | 5217 | it up. */ |
| 5193 | specbind (Qinhibit_quit, Qt); | 5218 | specbind (Qinhibit_quit, Qt); |
| 5194 | specbind (Qlast_nonmenu_event, Qt); | 5219 | specbind (Qlast_nonmenu_event, Qt); |
| 5195 | |||
| 5196 | /* In case we get recursively called, | ||
| 5197 | and we already saved the match data nonrecursively, | ||
| 5198 | save the same match data in safely recursive fashion. */ | ||
| 5199 | if (outer_running_asynch_code) | ||
| 5200 | { | ||
| 5201 | Lisp_Object tem; | ||
| 5202 | /* Don't clobber the CURRENT match data, either! */ | ||
| 5203 | tem = Fmatch_data (Qnil, Qnil, Qnil); | ||
| 5204 | restore_search_regs (); | ||
| 5205 | record_unwind_save_match_data (); | ||
| 5206 | Fset_match_data (tem, Qt); | ||
| 5207 | } | ||
| 5208 | 5220 | ||
| 5209 | /* For speed, if a search happens within this code, | 5221 | /* In case we get recursively called, |
| 5210 | save the match data in a special nonrecursive fashion. */ | 5222 | and we already saved the match data nonrecursively, |
| 5211 | running_asynch_code = 1; | 5223 | save the same match data in safely recursive fashion. */ |
| 5224 | if (outer_running_asynch_code) | ||
| 5225 | { | ||
| 5226 | Lisp_Object tem; | ||
| 5227 | /* Don't clobber the CURRENT match data, either! */ | ||
| 5228 | tem = Fmatch_data (Qnil, Qnil, Qnil); | ||
| 5229 | restore_search_regs (); | ||
| 5230 | record_unwind_save_match_data (); | ||
| 5231 | Fset_match_data (tem, Qt); | ||
| 5232 | } | ||
| 5212 | 5233 | ||
| 5213 | decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); | 5234 | /* For speed, if a search happens within this code, |
| 5214 | text = coding->dst_object; | 5235 | save the match data in a special nonrecursive fashion. */ |
| 5215 | Vlast_coding_system_used = CODING_ID_NAME (coding->id); | 5236 | running_asynch_code = 1; |
| 5216 | /* A new coding system might be found. */ | ||
| 5217 | if (!EQ (p->decode_coding_system, Vlast_coding_system_used)) | ||
| 5218 | { | ||
| 5219 | pset_decode_coding_system (p, Vlast_coding_system_used); | ||
| 5220 | 5237 | ||
| 5221 | /* Don't call setup_coding_system for | 5238 | decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); |
| 5222 | proc_decode_coding_system[channel] here. It is done in | 5239 | text = coding->dst_object; |
| 5223 | detect_coding called via decode_coding above. */ | 5240 | Vlast_coding_system_used = CODING_ID_NAME (coding->id); |
| 5241 | /* A new coding system might be found. */ | ||
| 5242 | if (!EQ (p->decode_coding_system, Vlast_coding_system_used)) | ||
| 5243 | { | ||
| 5244 | pset_decode_coding_system (p, Vlast_coding_system_used); | ||
| 5224 | 5245 | ||
| 5225 | /* If a coding system for encoding is not yet decided, we set | 5246 | /* Don't call setup_coding_system for |
| 5226 | it as the same as coding-system for decoding. | 5247 | proc_decode_coding_system[channel] here. It is done in |
| 5248 | detect_coding called via decode_coding above. */ | ||
| 5227 | 5249 | ||
| 5228 | But, before doing that we must check if | 5250 | /* If a coding system for encoding is not yet decided, we set |
| 5229 | proc_encode_coding_system[p->outfd] surely points to a | 5251 | it as the same as coding-system for decoding. |
| 5230 | valid memory because p->outfd will be changed once EOF is | ||
| 5231 | sent to the process. */ | ||
| 5232 | if (NILP (p->encode_coding_system) | ||
| 5233 | && proc_encode_coding_system[p->outfd]) | ||
| 5234 | { | ||
| 5235 | pset_encode_coding_system | ||
| 5236 | (p, coding_inherit_eol_type (Vlast_coding_system_used, Qnil)); | ||
| 5237 | setup_coding_system (p->encode_coding_system, | ||
| 5238 | proc_encode_coding_system[p->outfd]); | ||
| 5239 | } | ||
| 5240 | } | ||
| 5241 | 5252 | ||
| 5242 | if (coding->carryover_bytes > 0) | 5253 | But, before doing that we must check if |
| 5254 | proc_encode_coding_system[p->outfd] surely points to a | ||
| 5255 | valid memory because p->outfd will be changed once EOF is | ||
| 5256 | sent to the process. */ | ||
| 5257 | if (NILP (p->encode_coding_system) | ||
| 5258 | && proc_encode_coding_system[p->outfd]) | ||
| 5243 | { | 5259 | { |
| 5244 | if (SCHARS (p->decoding_buf) < coding->carryover_bytes) | 5260 | pset_encode_coding_system |
| 5245 | pset_decoding_buf (p, make_uninit_string (coding->carryover_bytes)); | 5261 | (p, coding_inherit_eol_type (Vlast_coding_system_used, Qnil)); |
| 5246 | memcpy (SDATA (p->decoding_buf), coding->carryover, | 5262 | setup_coding_system (p->encode_coding_system, |
| 5247 | coding->carryover_bytes); | 5263 | proc_encode_coding_system[p->outfd]); |
| 5248 | p->decoding_carryover = coding->carryover_bytes; | ||
| 5249 | } | 5264 | } |
| 5250 | if (SBYTES (text) > 0) | 5265 | } |
| 5251 | /* FIXME: It's wrong to wrap or not based on debug-on-error, and | ||
| 5252 | sometimes it's simply wrong to wrap (e.g. when called from | ||
| 5253 | accept-process-output). */ | ||
| 5254 | internal_condition_case_1 (read_process_output_call, | ||
| 5255 | Fcons (outstream, | ||
| 5256 | Fcons (proc, Fcons (text, Qnil))), | ||
| 5257 | !NILP (Vdebug_on_error) ? Qnil : Qerror, | ||
| 5258 | read_process_output_error_handler); | ||
| 5259 | |||
| 5260 | /* If we saved the match data nonrecursively, restore it now. */ | ||
| 5261 | restore_search_regs (); | ||
| 5262 | running_asynch_code = outer_running_asynch_code; | ||
| 5263 | 5266 | ||
| 5264 | /* Restore waiting_for_user_input_p as it was | 5267 | if (coding->carryover_bytes > 0) |
| 5265 | when we were called, in case the filter clobbered it. */ | 5268 | { |
| 5266 | waiting_for_user_input_p = waiting; | 5269 | if (SCHARS (p->decoding_buf) < coding->carryover_bytes) |
| 5270 | pset_decoding_buf (p, make_uninit_string (coding->carryover_bytes)); | ||
| 5271 | memcpy (SDATA (p->decoding_buf), coding->carryover, | ||
| 5272 | coding->carryover_bytes); | ||
| 5273 | p->decoding_carryover = coding->carryover_bytes; | ||
| 5274 | } | ||
| 5275 | if (SBYTES (text) > 0) | ||
| 5276 | /* FIXME: It's wrong to wrap or not based on debug-on-error, and | ||
| 5277 | sometimes it's simply wrong to wrap (e.g. when called from | ||
| 5278 | accept-process-output). */ | ||
| 5279 | internal_condition_case_1 (read_process_output_call, | ||
| 5280 | Fcons (outstream, | ||
| 5281 | Fcons (make_lisp_proc (p), | ||
| 5282 | Fcons (text, Qnil))), | ||
| 5283 | !NILP (Vdebug_on_error) ? Qnil : Qerror, | ||
| 5284 | read_process_output_error_handler); | ||
| 5285 | |||
| 5286 | /* If we saved the match data nonrecursively, restore it now. */ | ||
| 5287 | restore_search_regs (); | ||
| 5288 | running_asynch_code = outer_running_asynch_code; | ||
| 5289 | |||
| 5290 | /* Restore waiting_for_user_input_p as it was | ||
| 5291 | when we were called, in case the filter clobbered it. */ | ||
| 5292 | waiting_for_user_input_p = waiting; | ||
| 5267 | 5293 | ||
| 5268 | #if 0 /* Call record_asynch_buffer_change unconditionally, | 5294 | #if 0 /* Call record_asynch_buffer_change unconditionally, |
| 5269 | because we might have changed minor modes or other things | 5295 | because we might have changed minor modes or other things |
| 5270 | that affect key bindings. */ | 5296 | that affect key bindings. */ |
| 5271 | if (! EQ (Fcurrent_buffer (), obuffer) | 5297 | if (! EQ (Fcurrent_buffer (), obuffer) |
| 5272 | || ! EQ (current_buffer->keymap, okeymap)) | 5298 | || ! EQ (current_buffer->keymap, okeymap)) |
| 5273 | #endif | 5299 | #endif |
| 5274 | /* But do it only if the caller is actually going to read events. | 5300 | /* But do it only if the caller is actually going to read events. |
| 5275 | Otherwise there's no need to make him wake up, and it could | 5301 | Otherwise there's no need to make him wake up, and it could |
| 5276 | cause trouble (for example it would make sit_for return). */ | 5302 | cause trouble (for example it would make sit_for return). */ |
| 5277 | if (waiting_for_user_input_p == -1) | 5303 | if (waiting_for_user_input_p == -1) |
| 5278 | record_asynch_buffer_change (); | 5304 | record_asynch_buffer_change (); |
| 5279 | } | 5305 | } |
| 5280 | 5306 | ||
| 5281 | /* If no filter, write into buffer if it isn't dead. */ | 5307 | DEFUN ("internal-default-process-filter", Finternal_default_process_filter, |
| 5282 | else if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) | 5308 | Sinternal_default_process_filter, 2, 2, 0, |
| 5309 | doc: /* Function used as default process filter. */) | ||
| 5310 | (Lisp_Object proc, Lisp_Object text) | ||
| 5311 | { | ||
| 5312 | struct Lisp_Process *p; | ||
| 5313 | ptrdiff_t opoint; | ||
| 5314 | |||
| 5315 | CHECK_PROCESS (proc); | ||
| 5316 | p = XPROCESS (proc); | ||
| 5317 | CHECK_STRING (text); | ||
| 5318 | |||
| 5319 | if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) | ||
| 5283 | { | 5320 | { |
| 5284 | Lisp_Object old_read_only; | 5321 | Lisp_Object old_read_only; |
| 5285 | ptrdiff_t old_begv, old_zv; | 5322 | ptrdiff_t old_begv, old_zv; |
| 5286 | ptrdiff_t old_begv_byte, old_zv_byte; | 5323 | ptrdiff_t old_begv_byte, old_zv_byte; |
| 5287 | ptrdiff_t before, before_byte; | 5324 | ptrdiff_t before, before_byte; |
| 5288 | ptrdiff_t opoint_byte; | 5325 | ptrdiff_t opoint_byte; |
| 5289 | Lisp_Object text; | ||
| 5290 | struct buffer *b; | 5326 | struct buffer *b; |
| 5291 | 5327 | ||
| 5292 | Fset_buffer (p->buffer); | 5328 | Fset_buffer (p->buffer); |
| @@ -5319,31 +5355,6 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5319 | if (! (BEGV <= PT && PT <= ZV)) | 5355 | if (! (BEGV <= PT && PT <= ZV)) |
| 5320 | Fwiden (); | 5356 | Fwiden (); |
| 5321 | 5357 | ||
| 5322 | decode_coding_c_string (coding, (unsigned char *) chars, nbytes, Qt); | ||
| 5323 | text = coding->dst_object; | ||
| 5324 | Vlast_coding_system_used = CODING_ID_NAME (coding->id); | ||
| 5325 | /* A new coding system might be found. See the comment in the | ||
| 5326 | similar code in the previous `if' block. */ | ||
| 5327 | if (!EQ (p->decode_coding_system, Vlast_coding_system_used)) | ||
| 5328 | { | ||
| 5329 | pset_decode_coding_system (p, Vlast_coding_system_used); | ||
| 5330 | if (NILP (p->encode_coding_system) | ||
| 5331 | && proc_encode_coding_system[p->outfd]) | ||
| 5332 | { | ||
| 5333 | pset_encode_coding_system | ||
| 5334 | (p, coding_inherit_eol_type (Vlast_coding_system_used, Qnil)); | ||
| 5335 | setup_coding_system (p->encode_coding_system, | ||
| 5336 | proc_encode_coding_system[p->outfd]); | ||
| 5337 | } | ||
| 5338 | } | ||
| 5339 | if (coding->carryover_bytes > 0) | ||
| 5340 | { | ||
| 5341 | if (SCHARS (p->decoding_buf) < coding->carryover_bytes) | ||
| 5342 | pset_decoding_buf (p, make_uninit_string (coding->carryover_bytes)); | ||
| 5343 | memcpy (SDATA (p->decoding_buf), coding->carryover, | ||
| 5344 | coding->carryover_bytes); | ||
| 5345 | p->decoding_carryover = coding->carryover_bytes; | ||
| 5346 | } | ||
| 5347 | /* Adjust the multibyteness of TEXT to that of the buffer. */ | 5358 | /* Adjust the multibyteness of TEXT to that of the buffer. */ |
| 5348 | if (NILP (BVAR (current_buffer, enable_multibyte_characters)) | 5359 | if (NILP (BVAR (current_buffer, enable_multibyte_characters)) |
| 5349 | != ! STRING_MULTIBYTE (text)) | 5360 | != ! STRING_MULTIBYTE (text)) |
| @@ -5388,18 +5399,13 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5388 | if (old_begv != BEGV || old_zv != ZV) | 5399 | if (old_begv != BEGV || old_zv != ZV) |
| 5389 | Fnarrow_to_region (make_number (old_begv), make_number (old_zv)); | 5400 | Fnarrow_to_region (make_number (old_begv), make_number (old_zv)); |
| 5390 | 5401 | ||
| 5391 | |||
| 5392 | bset_read_only (current_buffer, old_read_only); | 5402 | bset_read_only (current_buffer, old_read_only); |
| 5393 | SET_PT_BOTH (opoint, opoint_byte); | 5403 | SET_PT_BOTH (opoint, opoint_byte); |
| 5394 | } | 5404 | } |
| 5395 | /* Handling the process output should not deactivate the mark. */ | 5405 | return Qnil; |
| 5396 | Vdeactivate_mark = odeactivate; | ||
| 5397 | |||
| 5398 | unbind_to (count, Qnil); | ||
| 5399 | return nbytes; | ||
| 5400 | } | 5406 | } |
| 5401 | 5407 | ||
| 5402 | /* Sending data to subprocess */ | 5408 | /* Sending data to subprocess. */ |
| 5403 | 5409 | ||
| 5404 | /* In send_process, when a write fails temporarily, | 5410 | /* In send_process, when a write fails temporarily, |
| 5405 | wait_reading_process_output is called. It may execute user code, | 5411 | wait_reading_process_output is called. It may execute user code, |
| @@ -5613,7 +5619,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len, | |||
| 5613 | rv = sendto (outfd, cur_buf, cur_len, | 5619 | rv = sendto (outfd, cur_buf, cur_len, |
| 5614 | 0, datagram_address[outfd].sa, | 5620 | 0, datagram_address[outfd].sa, |
| 5615 | datagram_address[outfd].len); | 5621 | datagram_address[outfd].len); |
| 5616 | if (0 <= rv) | 5622 | if (rv >= 0) |
| 5617 | written = rv; | 5623 | written = rv; |
| 5618 | else if (errno == EMSGSIZE) | 5624 | else if (errno == EMSGSIZE) |
| 5619 | report_file_error ("sending datagram", Fcons (proc, Qnil)); | 5625 | report_file_error ("sending datagram", Fcons (proc, Qnil)); |
| @@ -6308,7 +6314,8 @@ handle_child_signal (int sig) | |||
| 6308 | struct Lisp_Process *p = XPROCESS (proc); | 6314 | struct Lisp_Process *p = XPROCESS (proc); |
| 6309 | int status; | 6315 | int status; |
| 6310 | 6316 | ||
| 6311 | if (p->alive && child_status_changed (p->pid, &status, WUNTRACED)) | 6317 | if (p->alive |
| 6318 | && child_status_changed (p->pid, &status, WUNTRACED | WCONTINUED)) | ||
| 6312 | { | 6319 | { |
| 6313 | /* Change the status of the process that was found. */ | 6320 | /* Change the status of the process that was found. */ |
| 6314 | p->tick = ++process_tick; | 6321 | p->tick = ++process_tick; |
| @@ -6339,13 +6346,6 @@ deliver_child_signal (int sig) | |||
| 6339 | 6346 | ||
| 6340 | 6347 | ||
| 6341 | static Lisp_Object | 6348 | static Lisp_Object |
| 6342 | exec_sentinel_unwind (Lisp_Object data) | ||
| 6343 | { | ||
| 6344 | pset_sentinel (XPROCESS (XCAR (data)), XCDR (data)); | ||
| 6345 | return Qnil; | ||
| 6346 | } | ||
| 6347 | |||
| 6348 | static Lisp_Object | ||
| 6349 | exec_sentinel_error_handler (Lisp_Object error_val) | 6349 | exec_sentinel_error_handler (Lisp_Object error_val) |
| 6350 | { | 6350 | { |
| 6351 | cmd_error_internal (error_val, "error in process sentinel: "); | 6351 | cmd_error_internal (error_val, "error in process sentinel: "); |
| @@ -6382,13 +6382,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) | |||
| 6382 | record_unwind_current_buffer (); | 6382 | record_unwind_current_buffer (); |
| 6383 | 6383 | ||
| 6384 | sentinel = p->sentinel; | 6384 | sentinel = p->sentinel; |
| 6385 | if (NILP (sentinel)) | ||
| 6386 | return; | ||
| 6387 | 6385 | ||
| 6388 | /* Zilch the sentinel while it's running, to avoid recursive invocations; | ||
| 6389 | assure that it gets restored no matter how the sentinel exits. */ | ||
| 6390 | pset_sentinel (p, Qnil); | ||
| 6391 | record_unwind_protect (exec_sentinel_unwind, Fcons (proc, sentinel)); | ||
| 6392 | /* Inhibit quit so that random quits don't screw up a running filter. */ | 6386 | /* Inhibit quit so that random quits don't screw up a running filter. */ |
| 6393 | specbind (Qinhibit_quit, Qt); | 6387 | specbind (Qinhibit_quit, Qt); |
| 6394 | specbind (Qlast_nonmenu_event, Qt); /* Why? --Stef */ | 6388 | specbind (Qlast_nonmenu_event, Qt); /* Why? --Stef */ |
| @@ -6446,7 +6440,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) | |||
| 6446 | static void | 6440 | static void |
| 6447 | status_notify (struct Lisp_Process *deleting_process) | 6441 | status_notify (struct Lisp_Process *deleting_process) |
| 6448 | { | 6442 | { |
| 6449 | register Lisp_Object proc, buffer; | 6443 | register Lisp_Object proc; |
| 6450 | Lisp_Object tail, msg; | 6444 | Lisp_Object tail, msg; |
| 6451 | struct gcpro gcpro1, gcpro2; | 6445 | struct gcpro gcpro1, gcpro2; |
| 6452 | 6446 | ||
| @@ -6484,8 +6478,6 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6484 | && p != deleting_process | 6478 | && p != deleting_process |
| 6485 | && read_process_output (proc, p->infd) > 0); | 6479 | && read_process_output (proc, p->infd) > 0); |
| 6486 | 6480 | ||
| 6487 | buffer = p->buffer; | ||
| 6488 | |||
| 6489 | /* Get the text to use for the message. */ | 6481 | /* Get the text to use for the message. */ |
| 6490 | if (p->raw_status_new) | 6482 | if (p->raw_status_new) |
| 6491 | update_status (p); | 6483 | update_status (p); |
| @@ -6506,66 +6498,83 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6506 | } | 6498 | } |
| 6507 | 6499 | ||
| 6508 | /* The actions above may have further incremented p->tick. | 6500 | /* The actions above may have further incremented p->tick. |
| 6509 | So set p->update_tick again | 6501 | So set p->update_tick again so that an error in the sentinel will |
| 6510 | so that an error in the sentinel will not cause | 6502 | not cause this code to be run again. */ |
| 6511 | this code to be run again. */ | ||
| 6512 | p->update_tick = p->tick; | 6503 | p->update_tick = p->tick; |
| 6513 | /* Now output the message suitably. */ | 6504 | /* Now output the message suitably. */ |
| 6514 | if (!NILP (p->sentinel)) | 6505 | exec_sentinel (proc, msg); |
| 6515 | exec_sentinel (proc, msg); | ||
| 6516 | /* Don't bother with a message in the buffer | ||
| 6517 | when a process becomes runnable. */ | ||
| 6518 | else if (!EQ (symbol, Qrun) && !NILP (buffer)) | ||
| 6519 | { | ||
| 6520 | Lisp_Object tem; | ||
| 6521 | struct buffer *old = current_buffer; | ||
| 6522 | ptrdiff_t opoint, opoint_byte; | ||
| 6523 | ptrdiff_t before, before_byte; | ||
| 6524 | |||
| 6525 | /* Avoid error if buffer is deleted | ||
| 6526 | (probably that's why the process is dead, too) */ | ||
| 6527 | if (!BUFFER_LIVE_P (XBUFFER (buffer))) | ||
| 6528 | continue; | ||
| 6529 | Fset_buffer (buffer); | ||
| 6530 | |||
| 6531 | opoint = PT; | ||
| 6532 | opoint_byte = PT_BYTE; | ||
| 6533 | /* Insert new output into buffer | ||
| 6534 | at the current end-of-output marker, | ||
| 6535 | thus preserving logical ordering of input and output. */ | ||
| 6536 | if (XMARKER (p->mark)->buffer) | ||
| 6537 | Fgoto_char (p->mark); | ||
| 6538 | else | ||
| 6539 | SET_PT_BOTH (ZV, ZV_BYTE); | ||
| 6540 | |||
| 6541 | before = PT; | ||
| 6542 | before_byte = PT_BYTE; | ||
| 6543 | |||
| 6544 | tem = BVAR (current_buffer, read_only); | ||
| 6545 | bset_read_only (current_buffer, Qnil); | ||
| 6546 | insert_string ("\nProcess "); | ||
| 6547 | { /* FIXME: temporary kludge */ | ||
| 6548 | Lisp_Object tem2 = p->name; Finsert (1, &tem2); } | ||
| 6549 | insert_string (" "); | ||
| 6550 | Finsert (1, &msg); | ||
| 6551 | bset_read_only (current_buffer, tem); | ||
| 6552 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); | ||
| 6553 | |||
| 6554 | if (opoint >= before) | ||
| 6555 | SET_PT_BOTH (opoint + (PT - before), | ||
| 6556 | opoint_byte + (PT_BYTE - before_byte)); | ||
| 6557 | else | ||
| 6558 | SET_PT_BOTH (opoint, opoint_byte); | ||
| 6559 | |||
| 6560 | set_buffer_internal (old); | ||
| 6561 | } | ||
| 6562 | } | 6506 | } |
| 6563 | } /* end for */ | 6507 | } /* end for */ |
| 6564 | 6508 | ||
| 6565 | update_mode_lines++; /* in case buffers use %s in mode-line-format */ | 6509 | update_mode_lines++; /* In case buffers use %s in mode-line-format. */ |
| 6566 | UNGCPRO; | 6510 | UNGCPRO; |
| 6567 | } | 6511 | } |
| 6568 | 6512 | ||
| 6513 | DEFUN ("internal-default-process-sentinel", Finternal_default_process_sentinel, | ||
| 6514 | Sinternal_default_process_sentinel, 2, 2, 0, | ||
| 6515 | doc: /* Function used as default sentinel for processes. */) | ||
| 6516 | (Lisp_Object proc, Lisp_Object msg) | ||
| 6517 | { | ||
| 6518 | Lisp_Object buffer, symbol; | ||
| 6519 | struct Lisp_Process *p; | ||
| 6520 | CHECK_PROCESS (proc); | ||
| 6521 | p = XPROCESS (proc); | ||
| 6522 | buffer = p->buffer; | ||
| 6523 | symbol = p->status; | ||
| 6524 | if (CONSP (symbol)) | ||
| 6525 | symbol = XCAR (symbol); | ||
| 6526 | |||
| 6527 | if (!EQ (symbol, Qrun) && !NILP (buffer)) | ||
| 6528 | { | ||
| 6529 | Lisp_Object tem; | ||
| 6530 | struct buffer *old = current_buffer; | ||
| 6531 | ptrdiff_t opoint, opoint_byte; | ||
| 6532 | ptrdiff_t before, before_byte; | ||
| 6533 | |||
| 6534 | /* Avoid error if buffer is deleted | ||
| 6535 | (probably that's why the process is dead, too). */ | ||
| 6536 | if (!BUFFER_LIVE_P (XBUFFER (buffer))) | ||
| 6537 | return Qnil; | ||
| 6538 | Fset_buffer (buffer); | ||
| 6539 | |||
| 6540 | if (NILP (BVAR (current_buffer, enable_multibyte_characters))) | ||
| 6541 | msg = (code_convert_string_norecord | ||
| 6542 | (msg, Vlocale_coding_system, 1)); | ||
| 6543 | |||
| 6544 | opoint = PT; | ||
| 6545 | opoint_byte = PT_BYTE; | ||
| 6546 | /* Insert new output into buffer | ||
| 6547 | at the current end-of-output marker, | ||
| 6548 | thus preserving logical ordering of input and output. */ | ||
| 6549 | if (XMARKER (p->mark)->buffer) | ||
| 6550 | Fgoto_char (p->mark); | ||
| 6551 | else | ||
| 6552 | SET_PT_BOTH (ZV, ZV_BYTE); | ||
| 6553 | |||
| 6554 | before = PT; | ||
| 6555 | before_byte = PT_BYTE; | ||
| 6556 | |||
| 6557 | tem = BVAR (current_buffer, read_only); | ||
| 6558 | bset_read_only (current_buffer, Qnil); | ||
| 6559 | insert_string ("\nProcess "); | ||
| 6560 | { /* FIXME: temporary kludge. */ | ||
| 6561 | Lisp_Object tem2 = p->name; Finsert (1, &tem2); } | ||
| 6562 | insert_string (" "); | ||
| 6563 | Finsert (1, &msg); | ||
| 6564 | bset_read_only (current_buffer, tem); | ||
| 6565 | set_marker_both (p->mark, p->buffer, PT, PT_BYTE); | ||
| 6566 | |||
| 6567 | if (opoint >= before) | ||
| 6568 | SET_PT_BOTH (opoint + (PT - before), | ||
| 6569 | opoint_byte + (PT_BYTE - before_byte)); | ||
| 6570 | else | ||
| 6571 | SET_PT_BOTH (opoint, opoint_byte); | ||
| 6572 | |||
| 6573 | set_buffer_internal (old); | ||
| 6574 | } | ||
| 6575 | return Qnil; | ||
| 6576 | } | ||
| 6577 | |||
| 6569 | 6578 | ||
| 6570 | DEFUN ("set-process-coding-system", Fset_process_coding_system, | 6579 | DEFUN ("set-process-coding-system", Fset_process_coding_system, |
| 6571 | Sset_process_coding_system, 1, 3, 0, | 6580 | Sset_process_coding_system, 1, 3, 0, |
| @@ -6729,7 +6738,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6729 | time_limit = TYPE_MAXIMUM (time_t); | 6738 | time_limit = TYPE_MAXIMUM (time_t); |
| 6730 | 6739 | ||
| 6731 | /* What does time_limit really mean? */ | 6740 | /* What does time_limit really mean? */ |
| 6732 | if (time_limit || 0 < nsecs) | 6741 | if (time_limit || nsecs > 0) |
| 6733 | { | 6742 | { |
| 6734 | timeout = make_emacs_time (time_limit, nsecs); | 6743 | timeout = make_emacs_time (time_limit, nsecs); |
| 6735 | end_time = add_emacs_time (current_emacs_time (), timeout); | 6744 | end_time = add_emacs_time (current_emacs_time (), timeout); |
| @@ -6757,17 +6766,17 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6757 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 6766 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| 6758 | break; | 6767 | break; |
| 6759 | 6768 | ||
| 6760 | /* Compute time from now till when time limit is up */ | 6769 | /* Compute time from now till when time limit is up. */ |
| 6761 | /* Exit if already run out */ | 6770 | /* Exit if already run out. */ |
| 6762 | if (nsecs < 0) | 6771 | if (nsecs < 0) |
| 6763 | { | 6772 | { |
| 6764 | /* A negative timeout means | 6773 | /* A negative timeout means |
| 6765 | gobble output available now | 6774 | gobble output available now |
| 6766 | but don't wait at all. */ | 6775 | but don't wait at all. */ |
| 6767 | 6776 | ||
| 6768 | timeout = make_emacs_time (0, 0); | 6777 | timeout = make_emacs_time (0, 0); |
| 6769 | } | 6778 | } |
| 6770 | else if (time_limit || 0 < nsecs) | 6779 | else if (time_limit || nsecs > 0) |
| 6771 | { | 6780 | { |
| 6772 | EMACS_TIME now = current_emacs_time (); | 6781 | EMACS_TIME now = current_emacs_time (); |
| 6773 | if (EMACS_TIME_LE (end_time, now)) | 6782 | if (EMACS_TIME_LE (end_time, now)) |
| @@ -6805,7 +6814,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6805 | && requeued_events_pending_p ()) | 6814 | && requeued_events_pending_p ()) |
| 6806 | break; | 6815 | break; |
| 6807 | 6816 | ||
| 6808 | if (EMACS_TIME_VALID_P (timer_delay) && 0 <= nsecs) | 6817 | if (EMACS_TIME_VALID_P (timer_delay) && nsecs >= 0) |
| 6809 | { | 6818 | { |
| 6810 | if (EMACS_TIME_LT (timer_delay, timeout)) | 6819 | if (EMACS_TIME_LT (timer_delay, timeout)) |
| 6811 | { | 6820 | { |
| @@ -6956,9 +6965,8 @@ setup_process_coding_systems (Lisp_Object process) | |||
| 6956 | if (!proc_decode_coding_system[inch]) | 6965 | if (!proc_decode_coding_system[inch]) |
| 6957 | proc_decode_coding_system[inch] = xmalloc (sizeof (struct coding_system)); | 6966 | proc_decode_coding_system[inch] = xmalloc (sizeof (struct coding_system)); |
| 6958 | coding_system = p->decode_coding_system; | 6967 | coding_system = p->decode_coding_system; |
| 6959 | if (! NILP (p->filter)) | 6968 | if (EQ (p->filter, Qinternal_default_process_filter) |
| 6960 | ; | 6969 | && BUFFERP (p->buffer)) |
| 6961 | else if (BUFFERP (p->buffer)) | ||
| 6962 | { | 6970 | { |
| 6963 | if (NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters))) | 6971 | if (NILP (BVAR (XBUFFER (p->buffer), enable_multibyte_characters))) |
| 6964 | coding_system = raw_text_coding_system (coding_system); | 6972 | coding_system = raw_text_coding_system (coding_system); |
| @@ -7067,7 +7075,7 @@ kill_buffer_processes (Lisp_Object buffer) | |||
| 7067 | 7075 | ||
| 7068 | DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, | 7076 | DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, |
| 7069 | Swaiting_for_user_input_p, 0, 0, 0, | 7077 | Swaiting_for_user_input_p, 0, 0, 0, |
| 7070 | doc: /* Returns non-nil if Emacs is waiting for input from the user. | 7078 | doc: /* Return non-nil if Emacs is waiting for input from the user. |
| 7071 | This is intended for use by asynchronous process output filters and sentinels. */) | 7079 | This is intended for use by asynchronous process output filters and sentinels. */) |
| 7072 | (void) | 7080 | (void) |
| 7073 | { | 7081 | { |
| @@ -7173,6 +7181,16 @@ integer or floating point values. | |||
| 7173 | return system_process_attributes (pid); | 7181 | return system_process_attributes (pid); |
| 7174 | } | 7182 | } |
| 7175 | 7183 | ||
| 7184 | void | ||
| 7185 | catch_child_signal (void) | ||
| 7186 | { | ||
| 7187 | #ifdef SIGCHLD | ||
| 7188 | struct sigaction action; | ||
| 7189 | emacs_sigaction_init (&action, deliver_child_signal); | ||
| 7190 | sigaction (SIGCHLD, &action, 0); | ||
| 7191 | #endif | ||
| 7192 | } | ||
| 7193 | |||
| 7176 | 7194 | ||
| 7177 | /* This is not called "init_process" because that is the name of a | 7195 | /* This is not called "init_process" because that is the name of a |
| 7178 | Mach system call, so it would cause problems on Darwin systems. */ | 7196 | Mach system call, so it would cause problems on Darwin systems. */ |
| @@ -7188,9 +7206,7 @@ init_process_emacs (void) | |||
| 7188 | if (! noninteractive || initialized) | 7206 | if (! noninteractive || initialized) |
| 7189 | #endif | 7207 | #endif |
| 7190 | { | 7208 | { |
| 7191 | struct sigaction action; | 7209 | catch_child_signal (); |
| 7192 | emacs_sigaction_init (&action, deliver_child_signal); | ||
| 7193 | sigaction (SIGCHLD, &action, 0); | ||
| 7194 | } | 7210 | } |
| 7195 | 7211 | ||
| 7196 | max_desc = 0; | 7212 | max_desc = 0; |
| @@ -7368,6 +7384,10 @@ syms_of_process (void) | |||
| 7368 | DEFSYM (Qcutime, "cutime"); | 7384 | DEFSYM (Qcutime, "cutime"); |
| 7369 | DEFSYM (Qcstime, "cstime"); | 7385 | DEFSYM (Qcstime, "cstime"); |
| 7370 | DEFSYM (Qctime, "ctime"); | 7386 | DEFSYM (Qctime, "ctime"); |
| 7387 | DEFSYM (Qinternal_default_process_sentinel, | ||
| 7388 | "internal-default-process-sentinel"); | ||
| 7389 | DEFSYM (Qinternal_default_process_filter, | ||
| 7390 | "internal-default-process-filter"); | ||
| 7371 | DEFSYM (Qpri, "pri"); | 7391 | DEFSYM (Qpri, "pri"); |
| 7372 | DEFSYM (Qnice, "nice"); | 7392 | DEFSYM (Qnice, "nice"); |
| 7373 | DEFSYM (Qthcount, "thcount"); | 7393 | DEFSYM (Qthcount, "thcount"); |
| @@ -7465,6 +7485,8 @@ The variable takes effect when `start-process' is called. */); | |||
| 7465 | defsubr (&Ssignal_process); | 7485 | defsubr (&Ssignal_process); |
| 7466 | defsubr (&Swaiting_for_user_input_p); | 7486 | defsubr (&Swaiting_for_user_input_p); |
| 7467 | defsubr (&Sprocess_type); | 7487 | defsubr (&Sprocess_type); |
| 7488 | defsubr (&Sinternal_default_process_sentinel); | ||
| 7489 | defsubr (&Sinternal_default_process_filter); | ||
| 7468 | defsubr (&Sset_process_coding_system); | 7490 | defsubr (&Sset_process_coding_system); |
| 7469 | defsubr (&Sprocess_coding_system); | 7491 | defsubr (&Sprocess_coding_system); |
| 7470 | defsubr (&Sset_process_filter_multibyte); | 7492 | defsubr (&Sset_process_filter_multibyte); |