aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c131
1 files changed, 63 insertions, 68 deletions
diff --git a/src/process.c b/src/process.c
index 90ad9c21681..d604415bdd0 100644
--- a/src/process.c
+++ b/src/process.c
@@ -761,9 +761,7 @@ nil, indicating the current buffer's process. */)
761 { 761 {
762#ifdef SIGCHLD 762#ifdef SIGCHLD
763 Lisp_Object symbol; 763 Lisp_Object symbol;
764 /* Assignment to EMACS_INT stops GCC whining about limited range 764 pid_t pid = p->pid;
765 of data type. */
766 EMACS_INT pid = p->pid;
767 765
768 /* No problem storing the pid here, as it is still in Vprocess_alist. */ 766 /* No problem storing the pid here, as it is still in Vprocess_alist. */
769 deleted_pid_list = Fcons (make_fixnum_or_float (pid), 767 deleted_pid_list = Fcons (make_fixnum_or_float (pid),
@@ -860,9 +858,7 @@ This is the pid of the external process which PROCESS uses or talks to.
860For a network connection, this value is nil. */) 858For a network connection, this value is nil. */)
861 (register Lisp_Object process) 859 (register Lisp_Object process)
862{ 860{
863 /* Assignment to EMACS_INT stops GCC whining about limited range of 861 pid_t pid;
864 data type. */
865 EMACS_INT pid;
866 862
867 CHECK_PROCESS (process); 863 CHECK_PROCESS (process);
868 pid = XPROCESS (process)->pid; 864 pid = XPROCESS (process)->pid;
@@ -1037,8 +1033,8 @@ DEFUN ("set-process-window-size", Fset_process_window_size,
1037 (register Lisp_Object process, Lisp_Object height, Lisp_Object width) 1033 (register Lisp_Object process, Lisp_Object height, Lisp_Object width)
1038{ 1034{
1039 CHECK_PROCESS (process); 1035 CHECK_PROCESS (process);
1040 CHECK_NATNUM (height); 1036 CHECK_RANGED_INTEGER (0, height, INT_MAX);
1041 CHECK_NATNUM (width); 1037 CHECK_RANGED_INTEGER (0, width, INT_MAX);
1042 1038
1043 if (XPROCESS (process)->infd < 0 1039 if (XPROCESS (process)->infd < 0
1044 || set_window_size (XPROCESS (process)->infd, 1040 || set_window_size (XPROCESS (process)->infd,
@@ -1198,7 +1194,7 @@ Returns nil if format of ADDRESS is invalid. */)
1198 if (VECTORP (address)) /* AF_INET or AF_INET6 */ 1194 if (VECTORP (address)) /* AF_INET or AF_INET6 */
1199 { 1195 {
1200 register struct Lisp_Vector *p = XVECTOR (address); 1196 register struct Lisp_Vector *p = XVECTOR (address);
1201 EMACS_INT size = p->header.size; 1197 ptrdiff_t size = p->header.size;
1202 Lisp_Object args[10]; 1198 Lisp_Object args[10];
1203 int nargs, i; 1199 int nargs, i;
1204 1200
@@ -1227,14 +1223,12 @@ Returns nil if format of ADDRESS is invalid. */)
1227 1223
1228 for (i = 0; i < nargs; i++) 1224 for (i = 0; i < nargs; i++)
1229 { 1225 {
1230 EMACS_INT element = XINT (p->contents[i]); 1226 if (! RANGED_INTEGERP (0, p->contents[i], 65535))
1231
1232 if (element < 0 || element > 65535)
1233 return Qnil; 1227 return Qnil;
1234 1228
1235 if (nargs <= 5 /* IPv4 */ 1229 if (nargs <= 5 /* IPv4 */
1236 && i < 4 /* host, not port */ 1230 && i < 4 /* host, not port */
1237 && element > 255) 1231 && XINT (p->contents[i]) > 255)
1238 return Qnil; 1232 return Qnil;
1239 1233
1240 args[i+1] = p->contents[i]; 1234 args[i+1] = p->contents[i];
@@ -1289,7 +1283,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1289 Lisp_Object buffer, name, program, proc, current_dir, tem; 1283 Lisp_Object buffer, name, program, proc, current_dir, tem;
1290 register unsigned char **new_argv; 1284 register unsigned char **new_argv;
1291 ptrdiff_t i; 1285 ptrdiff_t i;
1292 int count = SPECPDL_INDEX (); 1286 ptrdiff_t count = SPECPDL_INDEX ();
1293 1287
1294 buffer = args[1]; 1288 buffer = args[1];
1295 if (!NILP (buffer)) 1289 if (!NILP (buffer))
@@ -2098,7 +2092,8 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
2098 return sizeof (struct sockaddr_un); 2092 return sizeof (struct sockaddr_un);
2099 } 2093 }
2100#endif 2094#endif
2101 else if (CONSP (address) && INTEGERP (XCAR (address)) && VECTORP (XCDR (address))) 2095 else if (CONSP (address) && TYPE_RANGED_INTEGERP (int, XCAR (address))
2096 && VECTORP (XCDR (address)))
2102 { 2097 {
2103 struct sockaddr *sa; 2098 struct sockaddr *sa;
2104 *familyp = XINT (XCAR (address)); 2099 *familyp = XINT (XCAR (address));
@@ -2121,6 +2116,7 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2121 register struct Lisp_Vector *p; 2116 register struct Lisp_Vector *p;
2122 register unsigned char *cp = NULL; 2117 register unsigned char *cp = NULL;
2123 register int i; 2118 register int i;
2119 EMACS_INT hostport;
2124 2120
2125 memset (sa, 0, len); 2121 memset (sa, 0, len);
2126 2122
@@ -2131,8 +2127,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2131 { 2127 {
2132 struct sockaddr_in *sin = (struct sockaddr_in *) sa; 2128 struct sockaddr_in *sin = (struct sockaddr_in *) sa;
2133 len = sizeof (sin->sin_addr) + 1; 2129 len = sizeof (sin->sin_addr) + 1;
2134 i = XINT (p->contents[--len]); 2130 hostport = XINT (p->contents[--len]);
2135 sin->sin_port = htons (i); 2131 sin->sin_port = htons (hostport);
2136 cp = (unsigned char *)&sin->sin_addr; 2132 cp = (unsigned char *)&sin->sin_addr;
2137 sa->sa_family = family; 2133 sa->sa_family = family;
2138 } 2134 }
@@ -2142,8 +2138,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
2142 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa; 2138 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
2143 uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr; 2139 uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr;
2144 len = sizeof (sin6->sin6_addr) + 1; 2140 len = sizeof (sin6->sin6_addr) + 1;
2145 i = XINT (p->contents[--len]); 2141 hostport = XINT (p->contents[--len]);
2146 sin6->sin6_port = htons (i); 2142 sin6->sin6_port = htons (hostport);
2147 for (i = 0; i < len; i++) 2143 for (i = 0; i < len; i++)
2148 if (INTEGERP (p->contents[i])) 2144 if (INTEGERP (p->contents[i]))
2149 { 2145 {
@@ -2298,7 +2294,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2298 case SOPT_INT: 2294 case SOPT_INT:
2299 { 2295 {
2300 int optval; 2296 int optval;
2301 if (INTEGERP (val)) 2297 if (TYPE_RANGED_INTEGERP (int, val))
2302 optval = XINT (val); 2298 optval = XINT (val);
2303 else 2299 else
2304 error ("Bad option value for %s", name); 2300 error ("Bad option value for %s", name);
@@ -2337,7 +2333,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2337 2333
2338 linger.l_onoff = 1; 2334 linger.l_onoff = 1;
2339 linger.l_linger = 0; 2335 linger.l_linger = 0;
2340 if (INTEGERP (val)) 2336 if (TYPE_RANGED_INTEGERP (int, val))
2341 linger.l_linger = XINT (val); 2337 linger.l_linger = XINT (val);
2342 else 2338 else
2343 linger.l_onoff = NILP (val) ? 0 : 1; 2339 linger.l_onoff = NILP (val) ? 0 : 1;
@@ -2577,7 +2573,7 @@ usage: (make-serial-process &rest ARGS) */)
2577 struct gcpro gcpro1; 2573 struct gcpro gcpro1;
2578 Lisp_Object name, buffer; 2574 Lisp_Object name, buffer;
2579 Lisp_Object tem, val; 2575 Lisp_Object tem, val;
2580 int specpdl_count = -1; 2576 ptrdiff_t specpdl_count = -1;
2581 2577
2582 if (nargs == 0) 2578 if (nargs == 0)
2583 return Qnil; 2579 return Qnil;
@@ -2877,8 +2873,8 @@ usage: (make-network-process &rest ARGS) */)
2877 int xerrno = 0; 2873 int xerrno = 0;
2878 int s = -1, outch, inch; 2874 int s = -1, outch, inch;
2879 struct gcpro gcpro1; 2875 struct gcpro gcpro1;
2880 int count = SPECPDL_INDEX (); 2876 ptrdiff_t count = SPECPDL_INDEX ();
2881 int count1; 2877 ptrdiff_t count1;
2882 Lisp_Object QCaddress; /* one of QClocal or QCremote */ 2878 Lisp_Object QCaddress; /* one of QClocal or QCremote */
2883 Lisp_Object tem; 2879 Lisp_Object tem;
2884 Lisp_Object name, buffer, host, service, address; 2880 Lisp_Object name, buffer, host, service, address;
@@ -2925,7 +2921,7 @@ usage: (make-network-process &rest ARGS) */)
2925 error ("Network servers not supported"); 2921 error ("Network servers not supported");
2926#else 2922#else
2927 is_server = 1; 2923 is_server = 1;
2928 if (INTEGERP (tem)) 2924 if (TYPE_RANGED_INTEGERP (int, tem))
2929 backlog = XINT (tem); 2925 backlog = XINT (tem);
2930#endif 2926#endif
2931 } 2927 }
@@ -2991,7 +2987,7 @@ usage: (make-network-process &rest ARGS) */)
2991#endif 2987#endif
2992 else if (EQ (tem, Qipv4)) 2988 else if (EQ (tem, Qipv4))
2993 family = AF_INET; 2989 family = AF_INET;
2994 else if (INTEGERP (tem)) 2990 else if (TYPE_RANGED_INTEGERP (int, tem))
2995 family = XINT (tem); 2991 family = XINT (tem);
2996 else 2992 else
2997 error ("Unknown address family"); 2993 error ("Unknown address family");
@@ -3943,7 +3939,7 @@ If JUST-THIS-ONE is an integer, don't run any timers either.
3943Return non-nil if we received any output before the timeout expired. */) 3939Return non-nil if we received any output before the timeout expired. */)
3944 (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one) 3940 (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one)
3945{ 3941{
3946 int secs, usecs = 0; 3942 int secs = -1, usecs = 0;
3947 3943
3948 if (! NILP (process)) 3944 if (! NILP (process))
3949 CHECK_PROCESS (process); 3945 CHECK_PROCESS (process);
@@ -3964,22 +3960,12 @@ Return non-nil if we received any output before the timeout expired. */)
3964 3960
3965 if (!NILP (seconds)) 3961 if (!NILP (seconds))
3966 { 3962 {
3967 if (INTEGERP (seconds)) 3963 double duration = extract_float (duration);
3968 secs = XINT (seconds); 3964 if (0 < duration)
3969 else if (FLOATP (seconds)) 3965 duration_to_sec_usec (duration, &secs, &usecs);
3970 {
3971 double timeout = XFLOAT_DATA (seconds);
3972 secs = (int) timeout;
3973 usecs = (int) ((timeout - (double) secs) * 1000000);
3974 }
3975 else
3976 wrong_type_argument (Qnumberp, seconds);
3977
3978 if (secs < 0 || (secs == 0 && usecs == 0))
3979 secs = -1, usecs = 0;
3980 } 3966 }
3981 else 3967 else if (!NILP (process))
3982 secs = NILP (process) ? -1 : 0; 3968 secs = 0;
3983 3969
3984 return 3970 return
3985 (wait_reading_process_output (secs, usecs, 0, 0, 3971 (wait_reading_process_output (secs, usecs, 0, 0,
@@ -4292,7 +4278,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4292 EMACS_TIME timeout, end_time; 4278 EMACS_TIME timeout, end_time;
4293 int wait_channel = -1; 4279 int wait_channel = -1;
4294 int got_some_input = 0; 4280 int got_some_input = 0;
4295 int count = SPECPDL_INDEX (); 4281 ptrdiff_t count = SPECPDL_INDEX ();
4296 4282
4297 FD_ZERO (&Available); 4283 FD_ZERO (&Available);
4298 FD_ZERO (&Writeok); 4284 FD_ZERO (&Writeok);
@@ -4995,11 +4981,11 @@ read_process_output (Lisp_Object proc, register int channel)
4995 char *chars; 4981 char *chars;
4996 register Lisp_Object outstream; 4982 register Lisp_Object outstream;
4997 register struct Lisp_Process *p = XPROCESS (proc); 4983 register struct Lisp_Process *p = XPROCESS (proc);
4998 register EMACS_INT opoint; 4984 register ptrdiff_t opoint;
4999 struct coding_system *coding = proc_decode_coding_system[channel]; 4985 struct coding_system *coding = proc_decode_coding_system[channel];
5000 int carryover = p->decoding_carryover; 4986 int carryover = p->decoding_carryover;
5001 int readmax = 4096; 4987 int readmax = 4096;
5002 int count = SPECPDL_INDEX (); 4988 ptrdiff_t count = SPECPDL_INDEX ();
5003 Lisp_Object odeactivate; 4989 Lisp_Object odeactivate;
5004 4990
5005 chars = (char *) alloca (carryover + readmax); 4991 chars = (char *) alloca (carryover + readmax);
@@ -5195,10 +5181,10 @@ read_process_output (Lisp_Object proc, register int channel)
5195 else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name))) 5181 else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name)))
5196 { 5182 {
5197 Lisp_Object old_read_only; 5183 Lisp_Object old_read_only;
5198 EMACS_INT old_begv, old_zv; 5184 ptrdiff_t old_begv, old_zv;
5199 EMACS_INT old_begv_byte, old_zv_byte; 5185 ptrdiff_t old_begv_byte, old_zv_byte;
5200 EMACS_INT before, before_byte; 5186 ptrdiff_t before, before_byte;
5201 EMACS_INT opoint_byte; 5187 ptrdiff_t opoint_byte;
5202 Lisp_Object text; 5188 Lisp_Object text;
5203 struct buffer *b; 5189 struct buffer *b;
5204 5190
@@ -5339,7 +5325,7 @@ send_process_trap (int ignore)
5339 5325
5340static void 5326static void
5341send_process (volatile Lisp_Object proc, const char *volatile buf, 5327send_process (volatile Lisp_Object proc, const char *volatile buf,
5342 volatile EMACS_INT len, volatile Lisp_Object object) 5328 volatile ptrdiff_t len, volatile Lisp_Object object)
5343{ 5329{
5344 /* Use volatile to protect variables from being clobbered by longjmp. */ 5330 /* Use volatile to protect variables from being clobbered by longjmp. */
5345 struct Lisp_Process *p = XPROCESS (proc); 5331 struct Lisp_Process *p = XPROCESS (proc);
@@ -5409,8 +5395,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5409 coding->dst_object = Qt; 5395 coding->dst_object = Qt;
5410 if (BUFFERP (object)) 5396 if (BUFFERP (object))
5411 { 5397 {
5412 EMACS_INT from_byte, from, to; 5398 ptrdiff_t from_byte, from, to;
5413 EMACS_INT save_pt, save_pt_byte; 5399 ptrdiff_t save_pt, save_pt_byte;
5414 struct buffer *cur = current_buffer; 5400 struct buffer *cur = current_buffer;
5415 5401
5416 set_buffer_internal (XBUFFER (object)); 5402 set_buffer_internal (XBUFFER (object));
@@ -5464,12 +5450,12 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5464 process_sent_to = proc; 5450 process_sent_to = proc;
5465 while (len > 0) 5451 while (len > 0)
5466 { 5452 {
5467 EMACS_INT this = len; 5453 ptrdiff_t this = len;
5468 5454
5469 /* Send this batch, using one or more write calls. */ 5455 /* Send this batch, using one or more write calls. */
5470 while (this > 0) 5456 while (this > 0)
5471 { 5457 {
5472 EMACS_INT written = 0; 5458 ptrdiff_t written = 0;
5473 int outfd = p->outfd; 5459 int outfd = p->outfd;
5474 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); 5460 old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap);
5475#ifdef DATAGRAM_SOCKETS 5461#ifdef DATAGRAM_SOCKETS
@@ -5524,7 +5510,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
5524 that may allow the program 5510 that may allow the program
5525 to finish doing output and read more. */ 5511 to finish doing output and read more. */
5526 { 5512 {
5527 EMACS_INT offset = 0; 5513 ptrdiff_t offset = 0;
5528 5514
5529#ifdef BROKEN_PTY_READ_AFTER_EAGAIN 5515#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
5530 /* A gross hack to work around a bug in FreeBSD. 5516 /* A gross hack to work around a bug in FreeBSD.
@@ -5608,7 +5594,7 @@ Output from processes can arrive in between bunches. */)
5608 (Lisp_Object process, Lisp_Object start, Lisp_Object end) 5594 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5609{ 5595{
5610 Lisp_Object proc; 5596 Lisp_Object proc;
5611 EMACS_INT start1, end1; 5597 ptrdiff_t start1, end1;
5612 5598
5613 proc = get_process (process); 5599 proc = get_process (process);
5614 validate_region (&start, &end); 5600 validate_region (&start, &end);
@@ -5974,24 +5960,33 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
5974 5960
5975 if (INTEGERP (process)) 5961 if (INTEGERP (process))
5976 { 5962 {
5963 CHECK_TYPE_RANGED_INTEGER (pid_t, process);
5977 pid = XINT (process); 5964 pid = XINT (process);
5978 goto got_it; 5965 goto got_it;
5979 } 5966 }
5980 5967
5981 if (FLOATP (process)) 5968 if (FLOATP (process))
5982 { 5969 {
5983 pid = (pid_t) XFLOAT_DATA (process); 5970 double v = XFLOAT_DATA (process);
5971 if (! (TYPE_MINIMUM (pid_t) <= v && v < TYPE_MAXIMUM (pid_t) + 1.0))
5972 args_out_of_range_3 (process,
5973 make_fixnum_or_float (TYPE_MINIMUM (pid_t)),
5974 make_fixnum_or_float (TYPE_MAXIMUM (pid_t)));
5975 pid = v;
5984 goto got_it; 5976 goto got_it;
5985 } 5977 }
5986 5978
5987 if (STRINGP (process)) 5979 if (STRINGP (process))
5988 { 5980 {
5989 Lisp_Object tem; 5981 Lisp_Object tem = Fget_process (process);
5990 if (tem = Fget_process (process), NILP (tem)) 5982 if (NILP (tem))
5991 { 5983 {
5992 pid = XINT (Fstring_to_number (process, make_number (10))); 5984 EMACS_INT v = XINT (Fstring_to_number (process, make_number (10)));
5993 if (pid > 0) 5985 if (0 < v && v <= TYPE_MAXIMUM (pid_t))
5994 goto got_it; 5986 {
5987 pid = v;
5988 goto got_it;
5989 }
5995 } 5990 }
5996 process = tem; 5991 process = tem;
5997 } 5992 }
@@ -6013,7 +6008,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6013 XSETINT (sigcode, VALUE) 6008 XSETINT (sigcode, VALUE)
6014 6009
6015 if (INTEGERP (sigcode)) 6010 if (INTEGERP (sigcode))
6016 ; 6011 CHECK_TYPE_RANGED_INTEGER (int, sigcode);
6017 else 6012 else
6018 { 6013 {
6019 char *name; 6014 char *name;
@@ -6276,8 +6271,8 @@ sigchld_handler (int signo)
6276 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail)) 6271 for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail))
6277 { 6272 {
6278 Lisp_Object xpid = XCAR (tail); 6273 Lisp_Object xpid = XCAR (tail);
6279 if ((INTEGERP (xpid) && pid == (pid_t) XINT (xpid)) 6274 if ((INTEGERP (xpid) && pid == XINT (xpid))
6280 || (FLOATP (xpid) && pid == (pid_t) XFLOAT_DATA (xpid))) 6275 || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid)))
6281 { 6276 {
6282 XSETCAR (tail, Qnil); 6277 XSETCAR (tail, Qnil);
6283 goto sigchld_end_of_loop; 6278 goto sigchld_end_of_loop;
@@ -6393,7 +6388,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6393{ 6388{
6394 Lisp_Object sentinel, odeactivate; 6389 Lisp_Object sentinel, odeactivate;
6395 register struct Lisp_Process *p = XPROCESS (proc); 6390 register struct Lisp_Process *p = XPROCESS (proc);
6396 int count = SPECPDL_INDEX (); 6391 ptrdiff_t count = SPECPDL_INDEX ();
6397 int outer_running_asynch_code = running_asynch_code; 6392 int outer_running_asynch_code = running_asynch_code;
6398 int waiting = waiting_for_user_input_p; 6393 int waiting = waiting_for_user_input_p;
6399 6394
@@ -6552,8 +6547,8 @@ status_notify (struct Lisp_Process *deleting_process)
6552 { 6547 {
6553 Lisp_Object tem; 6548 Lisp_Object tem;
6554 struct buffer *old = current_buffer; 6549 struct buffer *old = current_buffer;
6555 EMACS_INT opoint, opoint_byte; 6550 ptrdiff_t opoint, opoint_byte;
6556 EMACS_INT before, before_byte; 6551 ptrdiff_t before, before_byte;
6557 6552
6558 /* Avoid error if buffer is deleted 6553 /* Avoid error if buffer is deleted
6559 (probably that's why the process is dead, too) */ 6554 (probably that's why the process is dead, too) */