]> code.delx.au - gnu-emacs/commitdiff
Remove unnecessary casts involving pointers.
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 3 Aug 2012 23:36:11 +0000 (16:36 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 3 Aug 2012 23:36:11 +0000 (16:36 -0700)
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.

32 files changed:
src/ChangeLog
src/alloc.c
src/callproc.c
src/casefiddle.c
src/character.c
src/charset.c
src/data.c
src/dired.c
src/doc.c
src/doprnt.c
src/editfns.c
src/fileio.c
src/filelock.c
src/fns.c
src/font.c
src/frame.c
src/keyboard.c
src/keymap.c
src/lisp.h
src/lread.c
src/macros.c
src/menu.c
src/minibuf.c
src/print.c
src/sysdep.c
src/w32menu.c
src/xdisp.c
src/xfaces.c
src/xfns.c
src/xfont.c
src/xselect.c
src/xterm.c

index 4aa0dcb022ece5176851183c16d35a6bcd6b8b0c..c3868f521eaadf02aeb62af24fd4b1485e87dfd3 100644 (file)
@@ -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
index aef68a1c0706f4ea455a6a20fe6752c52bd98ed1..3939e704978109861c89706ba6a8ac0fba96253e 100644 (file)
@@ -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;
index facca8877727e7fbdc0f2fc21b2042423f8d114e..5eabd689188495496e856ee8d9cbca2ef8d97e6d 100644 (file)
@@ -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;
 
index 19fbc832288a103d486693f81b09f78467d68c91..81e84252b72215bee903c9505a556aee178aa00c 100644 (file)
@@ -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)
        {
index 093f63d8ba789ce54cf3edc26c486ab611478da8..bdb0eead74075db09aced5e85fb38b72d203fbb0 100644 (file)
@@ -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++)
     {
index 0054854e80e1e09223766931c4f3b20fe045cd76..fbbcefc491571ca7df2dbf20f670e93b01dd2d08 100644 (file)
@@ -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));
        }
index 4c6f7fe3eae7fa311057774e2ee6c4c28035888b..f5942a84da1b64b959edc247e06d606e9ae9f654 100644 (file)
@@ -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);
index 7c047f97e6f9fe70020ccdab6aa459bd4aeafc7c..771230717e3dd5885cc00b55ceb960feb84c4586 100644 (file)
@@ -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,
index e57b26525e1290e6b2fe90f8440d1eeaa52b29b8..9445ff745be5dc8cd73d5fb8f22f2482c3b862d6 100644 (file)
--- 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));
     }
index 44dc641d5dde0daf384e0f611d749ec60c465b92..63f05cb74e22b4ef90ac44de001376c3e046aabf 100644 (file)
@@ -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--;
 
index e657b3ec532d89250a93a0bd485194ed7e22b80a..f86b4c12f581ac2cb6cf2a3694d5b9b1563b4a10 100644 (file)
@@ -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);
index 44710323192c050983b4c21dbf68481224e9add3..9578f1f9f1acd5d7b3be36f6bd82d51f7eba5635 100644 (file)
@@ -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)
index e840d3c5c3b4dc9c8b36a4305118a2a18c32fedb..d21d8e7ba0266d4da3432a3900539d5c2abed532 100644 (file)
@@ -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);
index 727424b705bec98faf3363f851bb06d711149b4f..3f988699a27962f7526277e86278d93ed4985bb7 100644 (file)
--- 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,
index b5e384140d8dd48180ef795790f90ab6f6fbbaf9..c70c2abdc23b05ea5c64748bf082b63ccfbf568a 100644 (file)
@@ -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;
 
index 9389eccb6f266acc3e31d18c849c6e5b1866b640..e43352d4e2457bbdd9d03dc98f286402690b78df 100644 (file)
@@ -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);
index 663a3956bf1e8593069985c63426a158ff04f2be..39112479eb7abeb0c96f9c9a7339de0b9a668bd9 100644 (file)
@@ -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);
index ed8542249e5e225309d4d013574a889d7fa717a3..ed65a5f3d8a3fd4a774037f346ba9a73c06609af 100644 (file)
@@ -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 ();
index e77b76005cdead78be24ada43ae223a8a2f6c348..4a538045a80df9bddade955422d381e93f31d5a3 100644 (file)
@@ -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_;                                 \
index d1549a34264dc154fcbf6b844cdbf6e3bbe8d48b..a31810ce463e52b85d2998f178fb67e7583ef064 100644 (file)
@@ -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 ();
     }
index 0b1eda0b8ab77d2613fe1cab61879c3ad2b9f721..a07d8ddbd23bc60564775fc1f08c0e58833e346f 100644 (file)
@@ -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;
index 15029390137a701834bffef7de2b5d65973cf035..eaf05ff3cbaf87888baf4972571a0439808a396c 100644 (file)
@@ -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)
     {
index 4b9c0a32f85e29649d984d1062c3a847f90ffaa0..cfe813f75f4e01b0de6d92ba641768a91cadd680 100644 (file)
@@ -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;
        }
index c4b96ff88ffc79d90ddf11d4d07e2eeef781f874..d16133903102ac871653da50a7a3f9666db68871 100644 (file)
@@ -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 ();
     }
index 4452298d103502f49e305c49eec438e61b150093..d6bddd7a502782f39b36c6664e28e7172a69ce31 100644 (file)
@@ -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;
 }
index d99516c8540a1cae2b48806cabca0031a7ea76d3..67bd575258edf80757e04e96670c9a0e6cc33daf 100644 (file)
@@ -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,
index 3e14b06357c94cf199f2a322ae5070de96235389..2af15acbe65d04aa47fb1766bb8a79c31f362b9e 100644 (file)
@@ -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)
index 9d264253115dd332550ff3da03132e2279dda3a5..df6cf6a36842b13392321aac5746509cdbf6cfcc 100644 (file)
@@ -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++)
index df66cbe1ab415e675a1f436d76bfebf0bab1fde9..5e92fe9b18767a5072010b01d06c3fb359027f39 100644 (file)
@@ -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);
     }
 }
 
index 736c1161e27fea51f5801ed97ecdfa89a9dfd039..1ebac6100f24be5314c1c9ec51c4fe1910e3b23f 100644 (file)
@@ -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;
index e2da561e953ef2312dd5b296b5b833f0d683590b..ff779b91944e0455348c42f51795fa5bcc22d145 100644 (file)
@@ -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);
     }
 }
 \f
@@ -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;
 }
 \f
index 6831ef6971e28b72f252dce459ba6623914d4ddc..ac846f23e95c05904bcf4e54c93f7a118a4f357b 100644 (file)
@@ -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);
 }