summaryrefslogtreecommitdiff
path: root/src/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c158
1 files changed, 68 insertions, 90 deletions
diff --git a/src/process.c b/src/process.c
index 53382d804f2..71da2e17670 100644
--- a/src/process.c
+++ b/src/process.c
@@ -764,9 +764,7 @@ nil, indicating the current buffer's process. */)
{
#ifdef SIGCHLD
Lisp_Object symbol;
- /* Assignment to EMACS_INT stops GCC whining about limited range
- of data type. */
- EMACS_INT pid = p->pid;
+ pid_t pid = p->pid;
/* No problem storing the pid here, as it is still in Vprocess_alist. */
deleted_pid_list = Fcons (make_fixnum_or_float (pid),
@@ -863,9 +861,7 @@ This is the pid of the external process which PROCESS uses or talks to.
For a network connection, this value is nil. */)
(register Lisp_Object process)
{
- /* Assignment to EMACS_INT stops GCC whining about limited range of
- data type. */
- EMACS_INT pid;
+ pid_t pid;
CHECK_PROCESS (process);
pid = XPROCESS (process)->pid;
@@ -1040,8 +1036,8 @@ DEFUN ("set-process-window-size", Fset_process_window_size,
(register Lisp_Object process, Lisp_Object height, Lisp_Object width)
{
CHECK_PROCESS (process);
- CHECK_NATNUM (height);
- CHECK_NATNUM (width);
+ CHECK_RANGED_INTEGER (0, height, INT_MAX);
+ CHECK_RANGED_INTEGER (0, width, INT_MAX);
if (XPROCESS (process)->infd < 0
|| set_window_size (XPROCESS (process)->infd,
@@ -1201,7 +1197,7 @@ Returns nil if format of ADDRESS is invalid. */)
if (VECTORP (address)) /* AF_INET or AF_INET6 */
{
register struct Lisp_Vector *p = XVECTOR (address);
- EMACS_INT size = p->header.size;
+ ptrdiff_t size = p->header.size;
Lisp_Object args[10];
int nargs, i;
@@ -1230,14 +1226,12 @@ Returns nil if format of ADDRESS is invalid. */)
for (i = 0; i < nargs; i++)
{
- EMACS_INT element = XINT (p->contents[i]);
-
- if (element < 0 || element > 65535)
+ if (! RANGED_INTEGERP (0, p->contents[i], 65535))
return Qnil;
if (nargs <= 5 /* IPv4 */
&& i < 4 /* host, not port */
- && element > 255)
+ && XINT (p->contents[i]) > 255)
return Qnil;
args[i+1] = p->contents[i];
@@ -1292,7 +1286,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
Lisp_Object buffer, name, program, proc, current_dir, tem;
register unsigned char **new_argv;
ptrdiff_t i;
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
buffer = args[1];
if (!NILP (buffer))
@@ -2101,7 +2095,8 @@ get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
return sizeof (struct sockaddr_un);
}
#endif
- else if (CONSP (address) && INTEGERP (XCAR (address)) && VECTORP (XCDR (address)))
+ else if (CONSP (address) && TYPE_RANGED_INTEGERP (int, XCAR (address))
+ && VECTORP (XCDR (address)))
{
struct sockaddr *sa;
*familyp = XINT (XCAR (address));
@@ -2124,6 +2119,7 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
register struct Lisp_Vector *p;
register unsigned char *cp = NULL;
register int i;
+ EMACS_INT hostport;
memset (sa, 0, len);
@@ -2134,8 +2130,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
{
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
len = sizeof (sin->sin_addr) + 1;
- i = XINT (p->contents[--len]);
- sin->sin_port = htons (i);
+ hostport = XINT (p->contents[--len]);
+ sin->sin_port = htons (hostport);
cp = (unsigned char *)&sin->sin_addr;
sa->sa_family = family;
}
@@ -2145,8 +2141,8 @@ conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr;
len = sizeof (sin6->sin6_addr) + 1;
- i = XINT (p->contents[--len]);
- sin6->sin6_port = htons (i);
+ hostport = XINT (p->contents[--len]);
+ sin6->sin6_port = htons (hostport);
for (i = 0; i < len; i++)
if (INTEGERP (p->contents[i]))
{
@@ -2301,7 +2297,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
case SOPT_INT:
{
int optval;
- if (INTEGERP (val))
+ if (TYPE_RANGED_INTEGERP (int, val))
optval = XINT (val);
else
error ("Bad option value for %s", name);
@@ -2340,7 +2336,7 @@ set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
linger.l_onoff = 1;
linger.l_linger = 0;
- if (INTEGERP (val))
+ if (TYPE_RANGED_INTEGERP (int, val))
linger.l_linger = XINT (val);
else
linger.l_onoff = NILP (val) ? 0 : 1;
@@ -2580,7 +2576,7 @@ usage: (make-serial-process &rest ARGS) */)
struct gcpro gcpro1;
Lisp_Object name, buffer;
Lisp_Object tem, val;
- int specpdl_count = -1;
+ ptrdiff_t specpdl_count = -1;
if (nargs == 0)
return Qnil;
@@ -2880,8 +2876,8 @@ usage: (make-network-process &rest ARGS) */)
int xerrno = 0;
int s = -1, outch, inch;
struct gcpro gcpro1;
- int count = SPECPDL_INDEX ();
- int count1;
+ ptrdiff_t count = SPECPDL_INDEX ();
+ ptrdiff_t count1;
Lisp_Object QCaddress; /* one of QClocal or QCremote */
Lisp_Object tem;
Lisp_Object name, buffer, host, service, address;
@@ -2928,7 +2924,7 @@ usage: (make-network-process &rest ARGS) */)
error ("Network servers not supported");
#else
is_server = 1;
- if (INTEGERP (tem))
+ if (TYPE_RANGED_INTEGERP (int, tem))
backlog = XINT (tem);
#endif
}
@@ -2994,7 +2990,7 @@ usage: (make-network-process &rest ARGS) */)
#endif
else if (EQ (tem, Qipv4))
family = AF_INET;
- else if (INTEGERP (tem))
+ else if (TYPE_RANGED_INTEGERP (int, tem))
family = XINT (tem);
else
error ("Unknown address family");
@@ -3951,7 +3947,7 @@ If JUST-THIS-ONE is an integer, don't run any timers either.
Return non-nil if we received any output before the timeout expired. */)
(register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one)
{
- int secs, usecs = 0;
+ int secs = -1, usecs = 0;
if (! NILP (process))
CHECK_PROCESS (process);
@@ -3972,22 +3968,12 @@ Return non-nil if we received any output before the timeout expired. */)
if (!NILP (seconds))
{
- if (INTEGERP (seconds))
- secs = XINT (seconds);
- else if (FLOATP (seconds))
- {
- double timeout = XFLOAT_DATA (seconds);
- secs = (int) timeout;
- usecs = (int) ((timeout - (double) secs) * 1000000);
- }
- else
- wrong_type_argument (Qnumberp, seconds);
-
- if (secs < 0 || (secs == 0 && usecs == 0))
- secs = -1, usecs = 0;
+ double duration = extract_float (seconds);
+ if (0 < duration)
+ duration_to_sec_usec (duration, &secs, &usecs);
}
- else
- secs = NILP (process) ? -1 : 0;
+ else if (!NILP (process))
+ secs = 0;
return
(wait_reading_process_output (secs, usecs, 0, 0,
@@ -4300,7 +4286,7 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
EMACS_TIME timeout, end_time;
int wait_channel = -1;
int got_some_input = 0;
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
FD_ZERO (&Available);
FD_ZERO (&Writeok);
@@ -4998,11 +4984,11 @@ read_process_output (Lisp_Object proc, register int channel)
char *chars;
register Lisp_Object outstream;
register struct Lisp_Process *p = XPROCESS (proc);
- register EMACS_INT opoint;
+ register ptrdiff_t opoint;
struct coding_system *coding = proc_decode_coding_system[channel];
int carryover = p->decoding_carryover;
int readmax = 4096;
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object odeactivate;
chars = (char *) alloca (carryover + readmax);
@@ -5198,10 +5184,10 @@ read_process_output (Lisp_Object proc, register int channel)
else if (!NILP (p->buffer) && !NILP (BVAR (XBUFFER (p->buffer), name)))
{
Lisp_Object old_read_only;
- EMACS_INT old_begv, old_zv;
- EMACS_INT old_begv_byte, old_zv_byte;
- EMACS_INT before, before_byte;
- EMACS_INT opoint_byte;
+ ptrdiff_t old_begv, old_zv;
+ ptrdiff_t old_begv_byte, old_zv_byte;
+ ptrdiff_t before, before_byte;
+ ptrdiff_t opoint_byte;
Lisp_Object text;
struct buffer *b;
@@ -5342,7 +5328,7 @@ send_process_trap (int ignore)
static void
send_process (volatile Lisp_Object proc, const char *volatile buf,
- volatile EMACS_INT len, volatile Lisp_Object object)
+ volatile ptrdiff_t len, volatile Lisp_Object object)
{
/* Use volatile to protect variables from being clobbered by longjmp. */
struct Lisp_Process *p = XPROCESS (proc);
@@ -5413,8 +5399,8 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
coding->dst_object = Qt;
if (BUFFERP (object))
{
- EMACS_INT from_byte, from, to;
- EMACS_INT save_pt, save_pt_byte;
+ ptrdiff_t from_byte, from, to;
+ ptrdiff_t save_pt, save_pt_byte;
struct buffer *cur = current_buffer;
set_buffer_internal (XBUFFER (object));
@@ -5468,12 +5454,12 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
process_sent_to = proc;
while (len > 0)
{
- EMACS_INT this = len;
+ ptrdiff_t this = len;
/* Send this batch, using one or more write calls. */
while (this > 0)
{
- EMACS_INT written = 0;
+ ptrdiff_t written = 0;
int outfd = p->outfd;
old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap);
#ifdef DATAGRAM_SOCKETS
@@ -5528,7 +5514,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf,
that may allow the program
to finish doing output and read more. */
{
- EMACS_INT offset = 0;
+ ptrdiff_t offset = 0;
#ifdef BROKEN_PTY_READ_AFTER_EAGAIN
/* A gross hack to work around a bug in FreeBSD.
@@ -5612,7 +5598,7 @@ Output from processes can arrive in between bunches. */)
(Lisp_Object process, Lisp_Object start, Lisp_Object end)
{
Lisp_Object proc;
- EMACS_INT start1, end1;
+ ptrdiff_t start1, end1;
proc = get_process (process);
validate_region (&start, &end);
@@ -5648,10 +5634,10 @@ Output from processes can arrive in between bunches. */)
/* Return the foreground process group for the tty/pty that
the process P uses. */
-static int
+static pid_t
emacs_get_tty_pgrp (struct Lisp_Process *p)
{
- int gid = -1;
+ pid_t gid = -1;
#ifdef TIOCGPGRP
if (ioctl (p->infd, TIOCGPGRP, &gid) == -1 && ! NILP (p->tty_name))
@@ -5681,7 +5667,7 @@ return t unconditionally. */)
{
/* Initialize in case ioctl doesn't exist or gives an error,
in a way that will cause returning t. */
- int gid;
+ pid_t gid;
Lisp_Object proc;
struct Lisp_Process *p;
@@ -5722,7 +5708,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
{
Lisp_Object proc;
register struct Lisp_Process *p;
- int gid;
+ pid_t gid;
int no_pgrp = 0;
proc = get_process (process);
@@ -5976,48 +5962,40 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
{
pid_t pid;
- if (INTEGERP (process))
- {
- pid = XINT (process);
- goto got_it;
- }
-
- if (FLOATP (process))
- {
- pid = (pid_t) XFLOAT_DATA (process);
- goto got_it;
- }
-
if (STRINGP (process))
{
- Lisp_Object tem;
- if (tem = Fget_process (process), NILP (tem))
+ Lisp_Object tem = Fget_process (process);
+ if (NILP (tem))
{
- pid = XINT (Fstring_to_number (process, make_number (10)));
- if (pid > 0)
- goto got_it;
+ Lisp_Object process_number =
+ string_to_number (SSDATA (process), 10, 1);
+ if (INTEGERP (process_number) || FLOATP (process_number))
+ tem = process_number;
}
process = tem;
}
- else
+ else if (!NUMBERP (process))
process = get_process (process);
if (NILP (process))
return process;
- CHECK_PROCESS (process);
- pid = XPROCESS (process)->pid;
- if (pid <= 0)
- error ("Cannot signal process %s", SDATA (XPROCESS (process)->name));
-
- got_it:
+ if (NUMBERP (process))
+ CONS_TO_INTEGER (process, pid_t, pid);
+ else
+ {
+ CHECK_PROCESS (process);
+ pid = XPROCESS (process)->pid;
+ if (pid <= 0)
+ error ("Cannot signal process %s", SDATA (XPROCESS (process)->name));
+ }
#define parse_signal(NAME, VALUE) \
else if (!xstrcasecmp (name, NAME)) \
XSETINT (sigcode, VALUE)
if (INTEGERP (sigcode))
- ;
+ CHECK_TYPE_RANGED_INTEGER (int, sigcode);
else
{
char *name;
@@ -6280,8 +6258,8 @@ sigchld_handler (int signo)
for (tail = deleted_pid_list; CONSP (tail); tail = XCDR (tail))
{
Lisp_Object xpid = XCAR (tail);
- if ((INTEGERP (xpid) && pid == (pid_t) XINT (xpid))
- || (FLOATP (xpid) && pid == (pid_t) XFLOAT_DATA (xpid)))
+ if ((INTEGERP (xpid) && pid == XINT (xpid))
+ || (FLOATP (xpid) && pid == XFLOAT_DATA (xpid)))
{
XSETCAR (tail, Qnil);
goto sigchld_end_of_loop;
@@ -6397,7 +6375,7 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason)
{
Lisp_Object sentinel, odeactivate;
register struct Lisp_Process *p = XPROCESS (proc);
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
int outer_running_asynch_code = running_asynch_code;
int waiting = waiting_for_user_input_p;
@@ -6556,8 +6534,8 @@ status_notify (struct Lisp_Process *deleting_process)
{
Lisp_Object tem;
struct buffer *old = current_buffer;
- EMACS_INT opoint, opoint_byte;
- EMACS_INT before, before_byte;
+ ptrdiff_t opoint, opoint_byte;
+ ptrdiff_t before, before_byte;
/* Avoid error if buffer is deleted
(probably that's why the process is dead, too) */