summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2012-08-03 16:36:11 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2012-08-03 16:36:11 -0700
commit98c6f1e36ff487925280fa0b0340af9d058632b5 (patch)
tree5601a2ac9433883b753a36f8d9c15f9d9d0b0eec
parent8834c57aab03fb7ea9d92f9e995844ff7ce64b7b (diff)
downloademacs-98c6f1e36ff487925280fa0b0340af9d058632b5.tar.gz
Remove unnecessary casts involving pointers.
These casts are no longer needed now that we assume C89 or later, since they involve casting to or from void *. * alloc.c (make_pure_string, make_pure_c_string, pure_cons) (make_pure_float, make_pure_vector): * lisp.h (SAFE_ALLOCA, SAFE_ALLOCA_LISP): * macros.c (Fstart_kbd_macro): * menu.c (find_and_return_menu_selection): * minibuf.c (read_minibuf_noninteractive): * sysdep.c (closedir): * xdisp.c (x_produce_glyphs): * xfaces.c (compare_fonts_by_sort_order): * xfns.c (x_real_positions, select_visual): * xselect.c (x_stop_queuing_selection_requests) (x_get_window_property, x_get_window_property_as_lisp_data): * xterm.c (x_set_frame_alpha, x_find_modifier_meanings): Remove unnecessary pointer casts. * alloc.c (record_xmalloc): New function. * lisp.h (record_xmalloc): New decl. (SAFE_ALLOCA): Now takes just one arg -- the size -- and acts more like a function. This is because the pointer cast is not needed. All uses changed. * print.c (print_string, print_error_message): Avoid length recalc.
-rw-r--r--src/ChangeLog24
-rw-r--r--src/alloc.c36
-rw-r--r--src/callproc.c10
-rw-r--r--src/casefiddle.c5
-rw-r--r--src/character.c6
-rw-r--r--src/charset.c12
-rw-r--r--src/data.c3
-rw-r--r--src/dired.c3
-rw-r--r--src/doc.c2
-rw-r--r--src/doprnt.c7
-rw-r--r--src/editfns.c16
-rw-r--r--src/fileio.c2
-rw-r--r--src/filelock.c35
-rw-r--r--src/fns.c14
-rw-r--r--src/font.c2
-rw-r--r--src/frame.c6
-rw-r--r--src/keyboard.c4
-rw-r--r--src/keymap.c5
-rw-r--r--src/lisp.h18
-rw-r--r--src/lread.c8
-rw-r--r--src/macros.c4
-rw-r--r--src/menu.c3
-rw-r--r--src/minibuf.c2
-rw-r--r--src/print.c14
-rw-r--r--src/sysdep.c2
-rw-r--r--src/w32menu.c9
-rw-r--r--src/xdisp.c21
-rw-r--r--src/xfaces.c6
-rw-r--r--src/xfns.c4
-rw-r--r--src/xfont.c4
-rw-r--r--src/xselect.c10
-rw-r--r--src/xterm.c4
32 files changed, 143 insertions, 158 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4aa0dcb022e..c3868f521ea 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,29 @@
2012-08-03 Paul Eggert <eggert@cs.ucla.edu>
+ Remove unnecessary casts involving pointers.
+ These casts are no longer needed now that we assume C89 or later,
+ since they involve casting to or from void *.
+ * alloc.c (make_pure_string, make_pure_c_string, pure_cons)
+ (make_pure_float, make_pure_vector):
+ * lisp.h (SAFE_ALLOCA, SAFE_ALLOCA_LISP):
+ * macros.c (Fstart_kbd_macro):
+ * menu.c (find_and_return_menu_selection):
+ * minibuf.c (read_minibuf_noninteractive):
+ * sysdep.c (closedir):
+ * xdisp.c (x_produce_glyphs):
+ * xfaces.c (compare_fonts_by_sort_order):
+ * xfns.c (x_real_positions, select_visual):
+ * xselect.c (x_stop_queuing_selection_requests)
+ (x_get_window_property, x_get_window_property_as_lisp_data):
+ * xterm.c (x_set_frame_alpha, x_find_modifier_meanings):
+ Remove unnecessary pointer casts.
+ * alloc.c (record_xmalloc): New function.
+ * lisp.h (record_xmalloc): New decl.
+ (SAFE_ALLOCA): Now takes just one arg -- the size -- and acts
+ more like a function. This is because the pointer cast is not
+ needed. All uses changed.
+ * print.c (print_string, print_error_message): Avoid length recalc.
+
Improve fix for macroexp crash with debugging (Bug#12118).
* lisp.h (ASET) [ENABLE_CHECKING]: Pay attention to
ARRAY_MARK_FLAG when checking subscripts, because ASET is
diff --git a/src/alloc.c b/src/alloc.c
index aef68a1c070..3939e704978 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -898,6 +898,16 @@ safe_alloca_unwind (Lisp_Object arg)
return Qnil;
}
+/* Return a newly allocated memory block of SIZE bytes, remembering
+ to free it when unwinding. */
+void *
+record_xmalloc (size_t size)
+{
+ void *p = xmalloc (size);
+ record_unwind_protect (safe_alloca_unwind, make_save_value (p, 0));
+ return p;
+}
+
/* Like malloc but used for allocating Lisp data. NBYTES is the
number of bytes to allocate, TYPE describes the intended use of the
@@ -5210,13 +5220,11 @@ make_pure_string (const char *data,
ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
{
Lisp_Object string;
- struct Lisp_String *s;
-
- s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
+ struct Lisp_String *s = pure_alloc (sizeof *s, Lisp_String);
s->data = (unsigned char *) find_string_data_in_pure (data, nbytes);
if (s->data == NULL)
{
- s->data = (unsigned char *) pure_alloc (nbytes + 1, -1);
+ s->data = pure_alloc (nbytes + 1, -1);
memcpy (s->data, data, nbytes);
s->data[nbytes] = '\0';
}
@@ -5234,9 +5242,7 @@ Lisp_Object
make_pure_c_string (const char *data, ptrdiff_t nchars)
{
Lisp_Object string;
- struct Lisp_String *s;
-
- s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
+ struct Lisp_String *s = pure_alloc (sizeof *s, Lisp_String);
s->size = nchars;
s->size_byte = -1;
s->data = (unsigned char *) data;
@@ -5251,10 +5257,8 @@ make_pure_c_string (const char *data, ptrdiff_t nchars)
Lisp_Object
pure_cons (Lisp_Object car, Lisp_Object cdr)
{
- register Lisp_Object new;
- struct Lisp_Cons *p;
-
- p = (struct Lisp_Cons *) pure_alloc (sizeof *p, Lisp_Cons);
+ Lisp_Object new;
+ struct Lisp_Cons *p = pure_alloc (sizeof *p, Lisp_Cons);
XSETCONS (new, p);
XSETCAR (new, Fpurecopy (car));
XSETCDR (new, Fpurecopy (cdr));
@@ -5267,10 +5271,8 @@ pure_cons (Lisp_Object car, Lisp_Object cdr)
static Lisp_Object
make_pure_float (double num)
{
- register Lisp_Object new;
- struct Lisp_Float *p;
-
- p = (struct Lisp_Float *) pure_alloc (sizeof *p, Lisp_Float);
+ Lisp_Object new;
+ struct Lisp_Float *p = pure_alloc (sizeof *p, Lisp_Float);
XSETFLOAT (new, p);
XFLOAT_INIT (new, num);
return new;
@@ -5284,10 +5286,8 @@ static Lisp_Object
make_pure_vector (ptrdiff_t len)
{
Lisp_Object new;
- struct Lisp_Vector *p;
size_t size = header_size + len * word_size;
-
- p = (struct Lisp_Vector *) pure_alloc (size, Lisp_Vectorlike);
+ struct Lisp_Vector *p = pure_alloc (size, Lisp_Vectorlike);
XSETVECTOR (new, p);
XVECTOR (new)->header.size = len;
return new;
diff --git a/src/callproc.c b/src/callproc.c
index facca887772..5eabd689188 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -427,8 +427,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
&& SREF (path, 1) == ':')
path = Fsubstring (path, make_number (2), Qnil);
- SAFE_ALLOCA (new_argv, const unsigned char **,
- (nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
+ new_argv = SAFE_ALLOCA ((nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
if (nargs > 4)
{
ptrdiff_t i;
@@ -978,8 +977,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
Lisp_Object coding_systems;
Lisp_Object val, *args2;
ptrdiff_t i;
- char *tempfile;
- Lisp_Object tmpdir, pattern;
+ Lisp_Object tmpdir;
if (STRINGP (Vtemporary_file_directory))
tmpdir = Vtemporary_file_directory;
@@ -1003,8 +1001,8 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
{
USE_SAFE_ALLOCA;
- pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
- SAFE_ALLOCA (tempfile, char *, SBYTES (pattern) + 1);
+ Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
+ char *tempfile = SAFE_ALLOCA (SBYTES (pattern) + 1);
memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1);
coding_systems = Qt;
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 19fbc832288..81e84252b72 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -114,12 +114,11 @@ casify_object (enum case_action flag, Lisp_Object obj)
ptrdiff_t i, i_byte, size = SCHARS (obj);
int len;
USE_SAFE_ALLOCA;
- unsigned char *dst, *o;
ptrdiff_t o_size = (size < STRING_BYTES_BOUND / MAX_MULTIBYTE_LENGTH
? size * MAX_MULTIBYTE_LENGTH
: STRING_BYTES_BOUND);
- SAFE_ALLOCA (dst, void *, o_size);
- o = dst;
+ unsigned char *dst = SAFE_ALLOCA (o_size);
+ unsigned char *o = dst;
for (i = i_byte = 0; i < size; i++, i_byte += len)
{
diff --git a/src/character.c b/src/character.c
index 093f63d8ba7..bdb0eead740 100644
--- a/src/character.c
+++ b/src/character.c
@@ -920,12 +920,10 @@ usage: (unibyte-string &rest BYTES) */)
(ptrdiff_t n, Lisp_Object *args)
{
ptrdiff_t i;
- unsigned char *buf, *p;
Lisp_Object str;
USE_SAFE_ALLOCA;
-
- SAFE_ALLOCA (buf, unsigned char *, n);
- p = buf;
+ unsigned char *buf = SAFE_ALLOCA (n);
+ unsigned char *p = buf;
for (i = 0; i < n; i++)
{
diff --git a/src/charset.c b/src/charset.c
index 0054854e80e..fbbcefc4915 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -503,8 +503,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, int co
/* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
large (larger than MAX_ALLOCA). */
- SAFE_ALLOCA (head, struct charset_map_entries *,
- sizeof (struct charset_map_entries));
+ head = SAFE_ALLOCA (sizeof *head);
entries = head;
memset (entries, 0, sizeof (struct charset_map_entries));
@@ -535,8 +534,7 @@ load_charset_map_from_file (struct charset *charset, Lisp_Object mapfile, int co
if (n_entries > 0 && (n_entries % 0x10000) == 0)
{
- SAFE_ALLOCA (entries->next, struct charset_map_entries *,
- sizeof (struct charset_map_entries));
+ entries->next = SAFE_ALLOCA (sizeof *entries->next);
entries = entries->next;
memset (entries, 0, sizeof (struct charset_map_entries));
n_entries = 0;
@@ -572,8 +570,7 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
/* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
large (larger than MAX_ALLOCA). */
- SAFE_ALLOCA (head, struct charset_map_entries *,
- sizeof (struct charset_map_entries));
+ head = SAFE_ALLOCA (sizeof *head);
entries = head;
memset (entries, 0, sizeof (struct charset_map_entries));
@@ -604,8 +601,7 @@ load_charset_map_from_vector (struct charset *charset, Lisp_Object vec, int cont
if (n_entries > 0 && (n_entries % 0x10000) == 0)
{
- SAFE_ALLOCA (entries->next, struct charset_map_entries *,
- sizeof (struct charset_map_entries));
+ entries->next = SAFE_ALLOCA (sizeof *entries->next);
entries = entries->next;
memset (entries, 0, sizeof (struct charset_map_entries));
}
diff --git a/src/data.c b/src/data.c
index 4c6f7fe3eae..f5942a84da1 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2179,10 +2179,9 @@ bool-vector. IDX starts at 0. */)
{
/* We must relocate the string data. */
ptrdiff_t nchars = SCHARS (array);
- unsigned char *str;
USE_SAFE_ALLOCA;
+ unsigned char *str = SAFE_ALLOCA (nbytes);
- SAFE_ALLOCA (str, unsigned char *, nbytes);
memcpy (str, SDATA (array), nbytes);
allocate_string_data (XSTRING (array), nchars,
nbytes + new_bytes - prev_bytes);
diff --git a/src/dired.c b/src/dired.c
index 7c047f97e6f..771230717e3 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -810,9 +810,8 @@ file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_ad
ptrdiff_t len = NAMLEN (dp);
ptrdiff_t pos = SCHARS (dirname);
int value;
- char *fullname;
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (fullname, char *, len + pos + 2);
+ char *fullname = SAFE_ALLOCA (len + pos + 2);
#ifdef MSDOS
/* Some fields of struct stat are *very* expensive to compute on MS-DOS,
diff --git a/src/doc.c b/src/doc.c
index e57b26525e1..9445ff745be 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -123,7 +123,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
/* sizeof ("../etc/") == 8 */
if (minsize < 8)
minsize = 8;
- SAFE_ALLOCA (name, char *, minsize + SCHARS (file) + 8);
+ name = SAFE_ALLOCA (minsize + SCHARS (file) + 8);
strcpy (name, SSDATA (docdir));
strcat (name, SSDATA (file));
}
diff --git a/src/doprnt.c b/src/doprnt.c
index 44dc641d5dd..63f05cb74e2 100644
--- a/src/doprnt.c
+++ b/src/doprnt.c
@@ -161,10 +161,9 @@ doprnt (char *buffer, ptrdiff_t bufsize, const char *format,
if (format_end == 0)
format_end = format + strlen (format);
- if (format_end - format < sizeof (fixed_buffer) - 1)
- fmtcpy = fixed_buffer;
- else
- SAFE_ALLOCA (fmtcpy, char *, format_end - format + 1);
+ fmtcpy = (format_end - format < sizeof (fixed_buffer) - 1
+ ? fixed_buffer
+ : SAFE_ALLOCA (format_end - format + 1));
bufsize--;
diff --git a/src/editfns.c b/src/editfns.c
index e657b3ec532..f86b4c12f58 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1793,7 +1793,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
if (STRING_BYTES_BOUND <= len)
string_overflow ();
size = len + 1;
- SAFE_ALLOCA (buf, char *, size);
+ buf = SAFE_ALLOCA (size);
}
UNBLOCK_INPUT;
@@ -2072,7 +2072,7 @@ the data it can't find. */)
int m = offset / 60;
int am = offset < 0 ? - m : m;
char buf[sizeof "+00" + INT_STRLEN_BOUND (int)];
- zone_name = make_formatted_string (buf, "%c%02d%02d",
+ zone_name = make_formatted_string (buf, "%c%02d%02d",
(offset < 0 ? '-' : '+'),
am / 60, am % 60);
}
@@ -3686,7 +3686,7 @@ usage: (format STRING &rest OBJECTS) */)
ptrdiff_t i;
if ((SIZE_MAX - formatlen) / sizeof (struct info) <= nargs)
memory_full (SIZE_MAX);
- SAFE_ALLOCA (info, struct info *, (nargs + 1) * sizeof *info + formatlen);
+ info = SAFE_ALLOCA ((nargs + 1) * sizeof *info + formatlen);
discarded = (char *) &info[nargs + 1];
for (i = 0; i < nargs + 1; i++)
{
@@ -4645,7 +4645,7 @@ Transposing beyond buffer boundaries is an error. */)
{
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (temp, unsigned char *, len2_byte);
+ temp = SAFE_ALLOCA (len2_byte);
/* Don't precompute these addresses. We have to compute them
at the last minute, because the relocating allocator might
@@ -4663,7 +4663,7 @@ Transposing beyond buffer boundaries is an error. */)
{
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+ temp = SAFE_ALLOCA (len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
memcpy (temp, start1_addr, len1_byte);
@@ -4703,7 +4703,7 @@ Transposing beyond buffer boundaries is an error. */)
if (!NULL_INTERVAL_P (tmp_interval3))
set_text_properties_1 (startr2, endr2, Qnil, buf, tmp_interval3);
- SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+ temp = SAFE_ALLOCA (len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
memcpy (temp, start1_addr, len1_byte);
@@ -4733,7 +4733,7 @@ Transposing beyond buffer boundaries is an error. */)
set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
/* holds region 2 */
- SAFE_ALLOCA (temp, unsigned char *, len2_byte);
+ temp = SAFE_ALLOCA (len2_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
memcpy (temp, start2_addr, len2_byte);
@@ -4766,7 +4766,7 @@ Transposing beyond buffer boundaries is an error. */)
set_text_properties_1 (startr1, endr2, Qnil, buf, tmp_interval3);
/* holds region 1 */
- SAFE_ALLOCA (temp, unsigned char *, len1_byte);
+ temp = SAFE_ALLOCA (len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
memcpy (temp, start1_addr, len1_byte);
diff --git a/src/fileio.c b/src/fileio.c
index 44710323192..9578f1f9f1a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5200,7 +5200,7 @@ auto_save_error (Lisp_Object error_val)
msg = Fformat (3, args);
GCPRO1 (msg);
nbytes = SBYTES (msg);
- SAFE_ALLOCA (msgbuf, char *, nbytes);
+ msgbuf = SAFE_ALLOCA (nbytes);
memcpy (msgbuf, SDATA (msg), nbytes);
for (i = 0; i < 3; ++i)
diff --git a/src/filelock.c b/src/filelock.c
index e840d3c5c3b..d21d8e7ba02 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -337,31 +337,22 @@ fill_in_lock_file_name (register char *lockfile, register Lisp_Object fn)
static int
lock_file_1 (char *lfname, int force)
{
- register int err;
- printmax_t boot, pid;
- const char *user_name;
- const char *host_name;
- char *lock_info_str;
- ptrdiff_t lock_info_size;
+ int err;
int symlink_errno;
USE_SAFE_ALLOCA;
/* Call this first because it can GC. */
- boot = get_boot_time ();
-
- if (STRINGP (Fuser_login_name (Qnil)))
- user_name = SSDATA (Fuser_login_name (Qnil));
- else
- user_name = "";
- if (STRINGP (Fsystem_name ()))
- host_name = SSDATA (Fsystem_name ());
- else
- host_name = "";
- lock_info_size = (strlen (user_name) + strlen (host_name)
- + 2 * INT_STRLEN_BOUND (printmax_t)
- + sizeof "@.:");
- SAFE_ALLOCA (lock_info_str, char *, lock_info_size);
- pid = getpid ();
+ printmax_t boot = get_boot_time ();
+
+ Lisp_Object luser_name = Fuser_login_name (Qnil);
+ char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : "";
+ Lisp_Object lhost_name = Fsystem_name ();
+ char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : "";
+ ptrdiff_t lock_info_size = (strlen (user_name) + strlen (host_name)
+ + 2 * INT_STRLEN_BOUND (printmax_t)
+ + sizeof "@.:");
+ char *lock_info_str = SAFE_ALLOCA (lock_info_size);
+ printmax_t pid = getpid ();
esprintf (lock_info_str, boot ? "%s@%s.%"pMd":%"pMd : "%s@%s.%"pMd,
user_name, host_name, pid, boot);
@@ -593,7 +584,7 @@ lock_file (Lisp_Object fn)
locker_size = (strlen (lock_info.user) + strlen (lock_info.host)
+ INT_STRLEN_BOUND (printmax_t)
+ sizeof "@ (pid )");
- SAFE_ALLOCA (locker, char *, locker_size);
+ locker = SAFE_ALLOCA (locker_size);
pid = lock_info.pid;
esprintf (locker, "%s@%s (pid %"pMd")",
lock_info.user, lock_info.host, pid);
diff --git a/src/fns.c b/src/fns.c
index 727424b705b..3f988699a27 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -903,7 +903,7 @@ string_make_multibyte (Lisp_Object string)
if (nbytes == SBYTES (string))
return string;
- SAFE_ALLOCA (buf, unsigned char *, nbytes);
+ buf = SAFE_ALLOCA (nbytes);
copy_text (SDATA (string), buf, SBYTES (string),
0, 1);
@@ -935,7 +935,7 @@ string_to_multibyte (Lisp_Object string)
if (nbytes == SBYTES (string))
return make_multibyte_string (SSDATA (string), nbytes, nbytes);
- SAFE_ALLOCA (buf, unsigned char *, nbytes);
+ buf = SAFE_ALLOCA (nbytes);
memcpy (buf, SDATA (string), SBYTES (string));
str_to_multibyte (buf, nbytes, SBYTES (string));
@@ -961,7 +961,7 @@ string_make_unibyte (Lisp_Object string)
nchars = SCHARS (string);
- SAFE_ALLOCA (buf, unsigned char *, nchars);
+ buf = SAFE_ALLOCA (nchars);
copy_text (SDATA (string), buf, SBYTES (string),
1, 0);
@@ -2972,7 +2972,7 @@ into shorter lines. */)
allength = length + length/3 + 1;
allength += allength / MIME_LINE_LENGTH + 1 + 6;
- SAFE_ALLOCA (encoded, char *, allength);
+ encoded = SAFE_ALLOCA (allength);
encoded_length = base64_encode_1 ((char *) BYTE_POS_ADDR (ibeg),
encoded, length, NILP (no_line_break),
!NILP (BVAR (current_buffer, enable_multibyte_characters)));
@@ -3027,7 +3027,7 @@ into shorter lines. */)
allength += allength / MIME_LINE_LENGTH + 1 + 6;
/* We need to allocate enough room for decoding the text. */
- SAFE_ALLOCA (encoded, char *, allength);
+ encoded = SAFE_ALLOCA (allength);
encoded_length = base64_encode_1 (SSDATA (string),
encoded, length, NILP (no_line_break),
@@ -3171,7 +3171,7 @@ If the region can't be decoded, signal an error and don't modify the buffer. */
working on a multibyte buffer, each decoded code may occupy at
most two bytes. */
allength = multibyte ? length * 2 : length;
- SAFE_ALLOCA (decoded, char *, allength);
+ decoded = SAFE_ALLOCA (allength);
move_gap_both (XFASTINT (beg), ibeg);
decoded_length = base64_decode_1 ((char *) BYTE_POS_ADDR (ibeg),
@@ -3222,7 +3222,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string,
length = SBYTES (string);
/* We need to allocate enough room for decoding the text. */
- SAFE_ALLOCA (decoded, char *, length);
+ decoded = SAFE_ALLOCA (length);
/* The decoded result should be unibyte. */
decoded_length = base64_decode_1 (SSDATA (string), decoded, length,
diff --git a/src/font.c b/src/font.c
index b5e384140d8..c70c2abdc23 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2227,7 +2227,7 @@ font_sort_entities (Lisp_Object list, Lisp_Object prefer, Lisp_Object frame, int
maxlen = ASIZE (vec);
}
- SAFE_ALLOCA (data, struct font_sort_data *, (sizeof *data) * maxlen);
+ data = SAFE_ALLOCA (maxlen * sizeof *data);
best_score = 0xFFFFFFFF;
best_entity = Qnil;
diff --git a/src/frame.c b/src/frame.c
index 9389eccb6f2..e43352d4e24 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3697,8 +3697,6 @@ display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Objec
char *
x_get_resource_string (const char *attribute, const char *class)
{
- char *name_key;
- char *class_key;
char *result;
struct frame *sf = SELECTED_FRAME ();
ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
@@ -3706,8 +3704,8 @@ x_get_resource_string (const char *attribute, const char *class)
/* Allocate space for the components, the dots which separate them,
and the final '\0'. */
- SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
- class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
+ char *name_key = SAFE_ALLOCA (invocation_namelen + strlen (attribute) + 2);
+ char *class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
sprintf (class_key, "%s.%s", EMACS_CLASS, class);
diff --git a/src/keyboard.c b/src/keyboard.c
index 663a3956bf1..39112479eb7 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6480,7 +6480,7 @@ modify_event_symbol (ptrdiff_t symbol_num, int modifiers, Lisp_Object symbol_kin
ptrdiff_t len = (SBYTES (name_alist_or_stem)
+ sizeof "-" + INT_STRLEN_BOUND (EMACS_INT));
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (buf, char *, len);
+ buf = SAFE_ALLOCA (len);
esprintf (buf, "%s-%"pI"d", SDATA (name_alist_or_stem),
XINT (symbol_int) + 1);
value = intern (buf);
@@ -7465,7 +7465,7 @@ menu_bar_items (Lisp_Object old)
if (!NILP (Voverriding_local_map_menu_flag))
{
/* Yes, use them (if non-nil) as well as the global map. */
- maps = (Lisp_Object *) alloca (3 * sizeof (maps[0]));
+ maps = alloca (3 * sizeof (maps[0]));
nmaps = 0;
if (!NILP (KVAR (current_kboard, Voverriding_terminal_local_map)))
maps[nmaps++] = KVAR (current_kboard, Voverriding_terminal_local_map);
diff --git a/src/keymap.c b/src/keymap.c
index ed8542249e5..ed65a5f3d8a 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2304,11 +2304,10 @@ around function keys and event symbols. */)
{
if (NILP (no_angles))
{
- char *buffer;
Lisp_Object result;
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (buffer, char *,
- sizeof "<>" + SBYTES (SYMBOL_NAME (key)));
+ char *buffer = SAFE_ALLOCA (sizeof "<>"
+ + SBYTES (SYMBOL_NAME (key)));
esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
result = build_string (buffer);
SAFE_FREE ();
diff --git a/src/lisp.h b/src/lisp.h
index e77b76005cd..4a538045a80 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3441,24 +3441,16 @@ static char const DIRECTORY_SEP = '/';
enum MAX_ALLOCA { MAX_ALLOCA = 16*1024 };
extern Lisp_Object safe_alloca_unwind (Lisp_Object);
+extern void *record_xmalloc (size_t);
#define USE_SAFE_ALLOCA \
ptrdiff_t sa_count = SPECPDL_INDEX (); int sa_must_free = 0
/* SAFE_ALLOCA allocates a simple buffer. */
-#define SAFE_ALLOCA(buf, type, size) \
- do { \
- if ((size) < MAX_ALLOCA) \
- buf = (type) alloca (size); \
- else \
- { \
- buf = xmalloc (size); \
- sa_must_free = 1; \
- record_unwind_protect (safe_alloca_unwind, \
- make_save_value (buf, 0)); \
- } \
- } while (0)
+#define SAFE_ALLOCA(size) ((size) < MAX_ALLOCA \
+ ? alloca (size) \
+ : (sa_must_free = 1, record_xmalloc (size)))
/* SAFE_NALLOCA sets BUF to a newly allocated array of MULTIPLIER *
NITEMS items, each of the same type as *BUF. MULTIPLIER must
@@ -3493,7 +3485,7 @@ extern Lisp_Object safe_alloca_unwind (Lisp_Object);
#define SAFE_ALLOCA_LISP(buf, nelt) \
do { \
if ((nelt) < MAX_ALLOCA / sizeof (Lisp_Object)) \
- buf = (Lisp_Object *) alloca ((nelt) * sizeof (Lisp_Object)); \
+ buf = alloca ((nelt) * sizeof (Lisp_Object)); \
else if ((nelt) < min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object)) \
{ \
Lisp_Object arg_; \
diff --git a/src/lread.c b/src/lread.c
index d1549a34264..a31810ce463 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -4317,12 +4317,10 @@ dir_warning (const char *format, Lisp_Object dirname)
/* Don't log the warning before we've initialized!! */
if (initialized)
{
- char *buffer;
- ptrdiff_t message_len;
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (buffer, char *,
- SBYTES (dirname) + strlen (format) - (sizeof "%s" - 1) + 1);
- message_len = esprintf (buffer, format, SDATA (dirname));
+ char *buffer = SAFE_ALLOCA (SBYTES (dirname)
+ + strlen (format) - (sizeof "%s" - 1) + 1);
+ ptrdiff_t message_len = esprintf (buffer, format, SDATA (dirname));
message_dolog (buffer, message_len, 0, STRING_MULTIBYTE (dirname));
SAFE_FREE ();
}
diff --git a/src/macros.c b/src/macros.c
index 0b1eda0b8ab..a07d8ddbd23 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -72,8 +72,8 @@ macro before appending to it. */)
if (current_kboard->kbd_macro_bufsize > 200)
{
current_kboard->kbd_macro_buffer
- = (Lisp_Object *)xrealloc (current_kboard->kbd_macro_buffer,
- 30 * sizeof (Lisp_Object));
+ = xrealloc (current_kboard->kbd_macro_buffer,
+ 30 * sizeof (Lisp_Object));
current_kboard->kbd_macro_bufsize = 30;
}
current_kboard->kbd_macro_ptr = current_kboard->kbd_macro_buffer;
diff --git a/src/menu.c b/src/menu.c
index 15029390137..eaf05ff3cba 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -976,8 +976,7 @@ find_and_return_menu_selection (FRAME_PTR f, int keymaps, void *client_data)
prefix = entry = Qnil;
i = 0;
- subprefix_stack =
- (Lisp_Object *)alloca (menu_items_used * sizeof (Lisp_Object));
+ subprefix_stack = alloca (menu_items_used * sizeof (Lisp_Object));
while (i < menu_items_used)
{
diff --git a/src/minibuf.c b/src/minibuf.c
index 4b9c0a32f85..cfe813f75f4 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -264,7 +264,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial,
if (STRING_BYTES_BOUND / 2 < size)
memory_full (SIZE_MAX);
size *= 2;
- line = (char *) xrealloc (line, size);
+ line = xrealloc (line, size);
}
line[len++] = c;
}
diff --git a/src/print.c b/src/print.c
index c4b96ff88ff..d1613390310 100644
--- a/src/print.c
+++ b/src/print.c
@@ -392,16 +392,14 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
{
/* Output to echo area. */
ptrdiff_t nbytes = SBYTES (string);
- char *buffer;
/* Copy the string contents so that relocation of STRING by
GC does not cause trouble. */
USE_SAFE_ALLOCA;
-
- SAFE_ALLOCA (buffer, char *, nbytes);
+ char *buffer = SAFE_ALLOCA (nbytes);
memcpy (buffer, SDATA (string), nbytes);
- strout (buffer, chars, SBYTES (string), printcharfun);
+ strout (buffer, chars, nbytes, printcharfun);
SAFE_FREE ();
}
@@ -862,11 +860,11 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
if (!NILP (caller) && SYMBOLP (caller))
{
Lisp_Object cname = SYMBOL_NAME (caller);
- char *name;
+ ptrdiff_t cnamelen = SBYTES (cname);
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (name, char *, SBYTES (cname));
- memcpy (name, SDATA (cname), SBYTES (cname));
- message_dolog (name, SBYTES (cname), 0, 0);
+ char *name = SAFE_ALLOCA (cnamelen);
+ memcpy (name, SDATA (cname), cnamelen);
+ message_dolog (name, cnamelen, 0, 0);
message_dolog (": ", 2, 0, 0);
SAFE_FREE ();
}
diff --git a/src/sysdep.c b/src/sysdep.c
index 4452298d103..d6bddd7a502 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2031,7 +2031,7 @@ closedir (DIR *dirp /* stream from opendir */)
int rtnval;
rtnval = emacs_close (dirp->dd_fd);
- xfree ((char *) dirp);
+ xfree (dirp);
return rtnval;
}
diff --git a/src/w32menu.c b/src/w32menu.c
index d99516c8540..67bd575258e 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -1243,7 +1243,7 @@ simple_dialog_show (FRAME_PTR f, Lisp_Object contents, Lisp_Object header)
one utf16 word, so we cannot simply use the character
length of temp. */
int utf8_len = strlen (utf8_text);
- SAFE_ALLOCA (text, WCHAR *, (utf8_len + 1) * sizeof (WCHAR));
+ text = SAFE_ALLOCA ((utf8_len + 1) * sizeof (WCHAR));
utf8to16 (utf8_text, utf8_len, text);
}
else
@@ -1386,8 +1386,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
if (wv->key != NULL)
{
- SAFE_ALLOCA (out_string, char *,
- strlen (wv->name) + strlen (wv->key) + 2);
+ out_string = SAFE_ALLOCA (strlen (wv->name) + strlen (wv->key) + 2);
strcpy (out_string, wv->name);
strcat (out_string, "\t");
strcat (out_string, wv->key);
@@ -1421,7 +1420,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
if (nlen > orig_len)
{
p = out_string;
- SAFE_ALLOCA (out_string, char *, nlen + 1);
+ out_string = SAFE_ALLOCA (nlen + 1);
q = out_string;
while (*p)
{
@@ -1481,7 +1480,7 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item)
if (fuFlags & MF_OWNERDRAW)
utf16_string = local_alloc ((utf8_len + 1) * sizeof (WCHAR));
else
- SAFE_ALLOCA (utf16_string, WCHAR *, (utf8_len + 1) * sizeof (WCHAR));
+ utf16_string = SAFE_ALLOCA ((utf8_len + 1) * sizeof (WCHAR));
utf8to16 (out_string, utf8_len, utf16_string);
return_value = unicode_append_menu (menu, fuFlags,
diff --git a/src/xdisp.c b/src/xdisp.c
index 3e14b06357c..2af15acbe65 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2660,9 +2660,9 @@ init_iterator (struct it *it, struct window *w,
is invisible. >0 means lines indented more than this value are
invisible. */
it->selective = (INTEGERP (BVAR (current_buffer, selective_display))
- ? clip_to_bounds
- (-1, XINT (BVAR (current_buffer, selective_display)),
- PTRDIFF_MAX)
+ ? (clip_to_bounds
+ (-1, XINT (BVAR (current_buffer, selective_display)),
+ PTRDIFF_MAX))
: (!NILP (BVAR (current_buffer, selective_display))
? -1 : 0));
it->selective_display_ellipsis_p
@@ -9268,7 +9268,7 @@ add_to_log (const char *format, Lisp_Object arg1, Lisp_Object arg2)
msg = Fformat (3, args);
len = SBYTES (msg) + 1;
- SAFE_ALLOCA (buffer, char *, len);
+ buffer = SAFE_ALLOCA (len);
memcpy (buffer, SDATA (msg), len);
message_dolog (buffer, len - 1, 1, 0);
@@ -9595,10 +9595,8 @@ message3 (Lisp_Object m, ptrdiff_t nbytes, int multibyte)
message_log_maybe_newline ();
if (STRINGP (m))
{
- char *buffer;
USE_SAFE_ALLOCA;
-
- SAFE_ALLOCA (buffer, char *, nbytes);
+ char *buffer = SAFE_ALLOCA (nbytes);
memcpy (buffer, SDATA (m), nbytes);
message_dolog (buffer, nbytes, 1, multibyte);
SAFE_FREE ();
@@ -11173,7 +11171,7 @@ prepare_menu_bars (void)
#ifdef HAVE_NS
if (windows_or_buffers_changed
&& FRAME_NS_P (f))
- ns_set_doc_edited
+ ns_set_doc_edited
(f, Fbuffer_modified_p
(WVAR (XWINDOW (FVAR (f, selected_window)), buffer)));
#endif
@@ -11478,8 +11476,9 @@ update_tool_bar (struct frame *f, int save_match_data)
selected_frame = frame;
/* Build desired tool-bar items from keymaps. */
- new_tool_bar = tool_bar_items
- (Fcopy_sequence (FVAR (f, tool_bar_items)), &new_n_tool_bar);
+ new_tool_bar
+ = tool_bar_items (Fcopy_sequence (FVAR (f, tool_bar_items)),
+ &new_n_tool_bar);
/* Redisplay the tool-bar if we changed it. */
if (new_n_tool_bar != f->n_tool_bar_items
@@ -24956,7 +24955,7 @@ x_produce_glyphs (struct it *it)
font_descent = FONT_DESCENT (font) - boff;
font_height = FONT_HEIGHT (font);
- cmp->font = (void *) font;
+ cmp->font = font;
pcm = NULL;
if (! font_not_found_p)
diff --git a/src/xfaces.c b/src/xfaces.c
index 9d264253115..df6cf6a3684 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -1559,8 +1559,10 @@ static enum font_property_index font_props_for_sorting[FONT_SIZE_INDEX];
static int
compare_fonts_by_sort_order (const void *v1, const void *v2)
{
- Lisp_Object font1 = *(Lisp_Object *) v1;
- Lisp_Object font2 = *(Lisp_Object *) v2;
+ Lisp_Object const *p1 = v1;
+ Lisp_Object const *p2 = v2;
+ Lisp_Object font1 = *p1;
+ Lisp_Object font2 = *p2;
int i;
for (i = 0; i < FONT_SIZE_INDEX; i++)
diff --git a/src/xfns.c b/src/xfns.c
index df66cbe1ab4..5e92fe9b187 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -460,7 +460,7 @@ x_real_positions (FRAME_PTR f, int *xptr, int *yptr)
if (! success)
break;
- XFree ((char *) tmp_children);
+ XFree (tmp_children);
if (wm_window == rootw || had_errors)
break;
@@ -4001,7 +4001,7 @@ select_visual (struct x_display_info *dpyinfo)
fatal ("Can't get proper X visual info");
dpyinfo->n_planes = vinfo->depth;
- XFree ((char *) vinfo);
+ XFree (vinfo);
}
}
diff --git a/src/xfont.c b/src/xfont.c
index 736c1161e27..1ebac6100f2 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -1035,10 +1035,8 @@ xfont_draw (struct glyph_string *s, int from, int to, int x, int y, int with_bac
if (xfont->min_byte1 == 0 && xfont->max_byte1 == 0)
{
- char *str;
USE_SAFE_ALLOCA;
-
- SAFE_ALLOCA (str, char *, len);
+ char *str = SAFE_ALLOCA (len);
for (i = 0; i < len ; i++)
str[i] = XCHAR2B_BYTE2 (s->char2b + from + i);
BLOCK_INPUT;
diff --git a/src/xselect.c b/src/xselect.c
index e2da561e953..ff779b91944 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -216,7 +216,7 @@ x_stop_queuing_selection_requests (void)
TRACE1 ("RESTORE SELECTION EVENT %p", queue_tmp);
kbd_buffer_unget_event (&queue_tmp->event);
selection_queue = queue_tmp->next;
- xfree ((char *)queue_tmp);
+ xfree (queue_tmp);
}
}
@@ -1321,7 +1321,7 @@ x_get_window_property (Display *display, Window window, Atom property,
goto done;
/* This was allocated by Xlib, so use XFree. */
- XFree ((char *) tmp_data);
+ XFree (tmp_data);
if (*actual_type_ret == None || *actual_format_ret == 0)
goto done;
@@ -1403,7 +1403,7 @@ x_get_window_property (Display *display, Window window, Atom property,
offset += bytes_gotten;
/* This was allocated by Xlib, so use XFree. */
- XFree ((char *) tmp_data);
+ XFree (tmp_data);
}
XFlush (display);
@@ -1568,7 +1568,7 @@ x_get_window_property_as_lisp_data (Display *display, Window window,
BLOCK_INPUT;
/* Use xfree, not XFree, because x_get_window_property
calls xmalloc itself. */
- xfree ((char *) data);
+ xfree (data);
UNBLOCK_INPUT;
receive_incremental_selection (display, window, property, target_type,
min_size_bytes, &data, &bytes,
@@ -1589,7 +1589,7 @@ x_get_window_property_as_lisp_data (Display *display, Window window,
/* Use xfree, not XFree, because x_get_window_property
calls xmalloc itself. */
- xfree ((char *) data);
+ xfree (data);
return val;
}
diff --git a/src/xterm.c b/src/xterm.c
index 6831ef6971e..ac846f23e95 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -520,7 +520,7 @@ x_set_frame_alpha (struct frame *f)
if (rc == Success && actual != None)
{
unsigned long value = *(unsigned long *)data;
- XFree ((void *) data);
+ XFree (data);
if (value == opac)
{
x_uncatch_errors ();
@@ -3710,7 +3710,7 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask;
}
- XFree ((char *) syms);
+ XFree (syms);
XFreeModifiermap (mods);
}