Commit 518c40a2 authored by Paul Eggert's avatar Paul Eggert

Minor fixes for recent openp changes.

* lisp.h (GCPRO7): New macro.
* lread.c (openp): Use bool for boolean; all callers changed.
Protect save_string from GC.  Don't assume that file descriptors
are nonzero.  Redo save_mtime comparison to avoid bogus GCC
warning about uninitialized variable.
parent 1d1c55dc
2013-12-18 Paul Eggert <eggert@cs.ucla.edu>
Minor fixes for recent openp changes.
* lisp.h (GCPRO7): New macro.
* lread.c (openp): Use bool for boolean; all callers changed.
Protect save_string from GC. Don't assume that file descriptors
are nonzero. Redo save_mtime comparison to avoid bogus GCC
warning about uninitialized variable.
2013-12-18 Eli Zaretskii <eliz@gnu.org>
* w32fns.c (emacs_abort): Use intptr_t as argument of
......
......@@ -465,7 +465,8 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
int ok;
GCPRO3 (buffer, current_dir, error_file);
ok = openp (Vexec_path, args[0], Vexec_suffixes, &path, make_number (X_OK), 0);
ok = openp (Vexec_path, args[0], Vexec_suffixes, &path,
make_number (X_OK), false);
UNGCPRO;
if (ok < 0)
report_file_error ("Searching for program", args[0]);
......
......@@ -495,7 +495,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile,
count = SPECPDL_INDEX ();
record_unwind_protect_nothing ();
specbind (Qfile_name_handler_alist, Qnil);
fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, 0);
fd = openp (Vcharset_map_path, mapfile, suffixes, NULL, Qnil, false);
fp = fd < 0 ? 0 : fdopen (fd, "r");
if (!fp)
{
......
......@@ -424,7 +424,7 @@ init_cmdargs (int argc, char **argv, int skip_args, char *original_pwd)
{
Lisp_Object found;
int yes = openp (Vexec_path, Vinvocation_name,
Vexec_suffixes, &found, make_number (X_OK), 0);
Vexec_suffixes, &found, make_number (X_OK), false);
if (yes == 1)
{
/* Add /: to the front of the name
......
......@@ -327,7 +327,9 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
}
/* Search bitmap-file-path for the file, if appropriate. */
if (openp (Vx_bitmap_file_path, file, Qnil, &found, make_number (R_OK), 0) < 0)
if (openp (Vx_bitmap_file_path, file, Qnil, &found,
make_number (R_OK), false)
< 0)
return -1;
filename = SSDATA (found);
......@@ -2242,7 +2244,7 @@ x_find_image_file (Lisp_Object file)
Vx_bitmap_file_path);
/* Try to find FILE in data-directory/images, then x-bitmap-file-path. */
fd = openp (search_path, file, Qnil, &file_found, Qnil, 0);
fd = openp (search_path, file, Qnil, &file_found, Qnil, false);
if (fd == -1)
file_found = Qnil;
......
......@@ -3032,6 +3032,7 @@ struct gcpro
#define GCPRO6(varname1, varname2, varname3, varname4, varname5, varname6) \
((void) gcpro6, (void) gcpro5, (void) gcpro4, (void) gcpro3, (void) gcpro2, \
(void) gcpro1)
#define GCPRO7(a, b, c, d, e, f, g) (GCPRO6 (a, b, c, d, e, f), (void) gcpro7)
#define UNGCPRO ((void) 0)
#else /* GC_MARK_STACK != GC_MAKE_GCPROS_NOOPS */
......@@ -3077,6 +3078,16 @@ struct gcpro
gcpro6.next = &gcpro5; gcpro6.var = &varname6; gcpro6.nvars = 1; \
gcprolist = &gcpro6; }
#define GCPRO7(a, b, c, d, e, f, g) \
{gcpro1.next = gcprolist; gcpro1.var = &(a); gcpro1.nvars = 1; \
gcpro2.next = &gcpro1; gcpro2.var = &(b); gcpro2.nvars = 1; \
gcpro3.next = &gcpro2; gcpro3.var = &(c); gcpro3.nvars = 1; \
gcpro4.next = &gcpro3; gcpro4.var = &(d); gcpro4.nvars = 1; \
gcpro5.next = &gcpro4; gcpro5.var = &(e); gcpro5.nvars = 1; \
gcpro6.next = &gcpro5; gcpro6.var = &(f); gcpro6.nvars = 1; \
gcpro7.next = &gcpro6; gcpro7.var = &(g); gcpro7.nvars = 1; \
gcprolist = &gcpro7; }
#define UNGCPRO (gcprolist = gcpro1.next)
#else
......@@ -3133,6 +3144,18 @@ extern int gcpro_level;
gcpro6.level = gcpro_level++; \
gcprolist = &gcpro6; }
#define GCPRO7(a, b, c, d, e, f, g) \
{gcpro1.next = gcprolist; gcpro1.var = &(a); gcpro1.nvars = 1; \
gcpro1.level = gcpro_level; \
gcpro2.next = &gcpro1; gcpro2.var = &(b); gcpro2.nvars = 1; \
gcpro3.next = &gcpro2; gcpro3.var = &(c); gcpro3.nvars = 1; \
gcpro4.next = &gcpro3; gcpro4.var = &(d); gcpro4.nvars = 1; \
gcpro5.next = &gcpro4; gcpro5.var = &(e); gcpro5.nvars = 1; \
gcpro6.next = &gcpro5; gcpro6.var = &(f); gcpro6.nvars = 1; \
gcpro7.next = &gcpro6; gcpro7.var = &(g); gcpro7.nvars = 1; \
gcpro7.level = gcpro_level++; \
gcprolist = &gcpro7; }
#define UNGCPRO \
(--gcpro_level != gcpro1.level \
? emacs_abort () \
......@@ -3791,7 +3814,7 @@ LOADHIST_ATTACH (Lisp_Object x)
Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
}
extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
Lisp_Object *, Lisp_Object, int);
Lisp_Object *, Lisp_Object, bool);
extern Lisp_Object string_to_number (char const *, int, bool);
extern void map_obarray (Lisp_Object, void (*) (Lisp_Object, Lisp_Object),
Lisp_Object);
......
......@@ -1420,7 +1420,7 @@ directories, make sure the PREDICATE function returns `dir-ok' for them. */)
(Lisp_Object filename, Lisp_Object path, Lisp_Object suffixes, Lisp_Object predicate)
{
Lisp_Object file;
int fd = openp (path, filename, suffixes, &file, predicate, 0);
int fd = openp (path, filename, suffixes, &file, predicate, false);
if (NILP (predicate) && fd >= 0)
emacs_close (fd);
return file;
......@@ -1455,20 +1455,20 @@ static Lisp_Object Qdir_ok;
int
openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
Lisp_Object *storeptr, Lisp_Object predicate, int newer)
Lisp_Object *storeptr, Lisp_Object predicate, bool newer)
{
ptrdiff_t fn_size = 100;
char buf[100];
char *fn = buf;
bool absolute = 0;
bool absolute;
ptrdiff_t want_length;
Lisp_Object filename;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6, gcpro7;
Lisp_Object string, tail, encoded_fn, save_string;
ptrdiff_t max_suffix_len = 0;
int last_errno = ENOENT;
struct timespec save_mtime;
int save_fd = 0;
struct timespec save_mtime = make_timespec (TYPE_MINIMUM (time_t), -1);
int save_fd = -1;
CHECK_STRING (str);
......@@ -1479,14 +1479,13 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
SBYTES (XCAR (tail)));
}
string = filename = encoded_fn = Qnil;
GCPRO6 (str, string, filename, path, suffixes, encoded_fn);
string = filename = encoded_fn = save_string = Qnil;
GCPRO7 (str, string, save_string, filename, path, suffixes, encoded_fn);
if (storeptr)
*storeptr = Qnil;
if (complete_filename_p (str))
absolute = 1;
absolute = complete_filename_p (str);
for (; CONSP (path); path = XCDR (path))
{
......@@ -1556,13 +1555,13 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
{
Lisp_Object tmp = call1 (predicate, string);
if (NILP (tmp))
exists = 0;
exists = false;
else if (EQ (tmp, Qdir_ok)
|| NILP (Ffile_directory_p (string)))
exists = 1;
exists = true;
else
{
exists = 0;
exists = false;
last_errno = EISDIR;
}
}
......@@ -1628,14 +1627,16 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
{
struct timespec mtime = get_stat_mtime (&st);
if (!save_fd || timespec_cmp (save_mtime, mtime) < 0)
if (timespec_cmp (mtime, save_mtime) <= 0)
emacs_close (fd);
else
{
if (save_fd) emacs_close (save_fd);
if (0 <= save_fd)
emacs_close (save_fd);
save_fd = fd;
save_mtime = mtime;
save_string = string;
}
else emacs_close (fd);
}
else
{
......@@ -1648,7 +1649,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes,
}
/* No more suffixes. Return the newest. */
if (newer && save_fd && ! CONSP (XCDR (tail)))
if (0 <= save_fd && ! CONSP (XCDR (tail)))
{
if (storeptr)
*storeptr = save_string;
......
......@@ -1530,7 +1530,8 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
tem = Qnil;
GCPRO4 (name, program, buffer, current_dir);
openp (Vexec_path, program, Vexec_suffixes, &tem, make_number (X_OK), 0);
openp (Vexec_path, program, Vexec_suffixes, &tem,
make_number (X_OK), false);
UNGCPRO;
if (NILP (tem))
report_file_error ("Searching for program", program);
......
......@@ -1332,7 +1332,7 @@ Internal use only, use `play-sound' instead. */)
{
/* Open the sound file. */
current_sound->fd = openp (list1 (Vdata_directory),
attrs[SOUND_FILE], Qnil, &file, Qnil, 0);
attrs[SOUND_FILE], Qnil, &file, Qnil, false);
if (current_sound->fd < 0)
sound_perror ("Could not open sound file");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment