emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r109421: Remove unnecessary casts inv


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109421: Remove unnecessary casts involving pointers.
Date: Fri, 03 Aug 2012 16:36:11 -0700
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109421
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Fri 2012-08-03 16:36:11 -0700
message:
  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.
modified:
  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
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-08-03 20:55:27 +0000
+++ b/src/ChangeLog     2012-08-03 23:36:11 +0000
@@ -1,5 +1,29 @@
 2012-08-03  Paul Eggert  <address@hidden>
 
+       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

=== modified file 'src/alloc.c'
--- a/src/alloc.c       2012-08-02 07:31:34 +0000
+++ b/src/alloc.c       2012-08-03 23:36:11 +0000
@@ -898,6 +898,16 @@
   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 @@
                  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 @@
 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 @@
 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 @@
 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 @@
 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;

=== modified file 'src/callproc.c'
--- a/src/callproc.c    2012-07-09 21:28:39 +0000
+++ b/src/callproc.c    2012-08-03 23:36:11 +0000
@@ -427,8 +427,7 @@
       && 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 @@
   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 @@
 
   {
     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;
 

=== modified file 'src/casefiddle.c'
--- a/src/casefiddle.c  2012-06-16 12:24:15 +0000
+++ b/src/casefiddle.c  2012-08-03 23:36:11 +0000
@@ -114,12 +114,11 @@
       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)
        {

=== modified file 'src/character.c'
--- a/src/character.c   2012-08-02 07:31:34 +0000
+++ b/src/character.c   2012-08-03 23:36:11 +0000
@@ -920,12 +920,10 @@
   (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++)
     {

=== modified file 'src/charset.c'
--- a/src/charset.c     2012-08-02 07:31:34 +0000
+++ b/src/charset.c     2012-08-03 23:36:11 +0000
@@ -503,8 +503,7 @@
 
   /* 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 @@
 
       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 @@
 
   /* 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 @@
 
       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));
        }

=== modified file 'src/data.c'
--- a/src/data.c        2012-08-01 07:57:09 +0000
+++ b/src/data.c        2012-08-03 23:36:11 +0000
@@ -2179,10 +2179,9 @@
            {
              /* 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);

=== modified file 'src/dired.c'
--- a/src/dired.c       2012-07-17 11:52:00 +0000
+++ b/src/dired.c       2012-08-03 23:36:11 +0000
@@ -810,9 +810,8 @@
   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,

=== modified file 'src/doc.c'
--- a/src/doc.c 2012-08-01 07:57:09 +0000
+++ b/src/doc.c 2012-08-03 23:36:11 +0000
@@ -123,7 +123,7 @@
       /* 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));
     }

=== modified file 'src/doprnt.c'
--- a/src/doprnt.c      2012-07-05 06:32:41 +0000
+++ b/src/doprnt.c      2012-08-03 23:36:11 +0000
@@ -161,10 +161,9 @@
   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--;
 

=== modified file 'src/editfns.c'
--- a/src/editfns.c     2012-08-01 05:11:36 +0000
+++ b/src/editfns.c     2012-08-03 23:36:11 +0000
@@ -1793,7 +1793,7 @@
       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 @@
          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 @@
     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 @@
         {
          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 @@
         {
          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 @@
          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 @@
            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 @@
            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);

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2012-08-01 05:11:36 +0000
+++ b/src/fileio.c      2012-08-03 23:36:11 +0000
@@ -5200,7 +5200,7 @@
   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)

=== modified file 'src/filelock.c'
--- a/src/filelock.c    2012-07-16 04:47:31 +0000
+++ b/src/filelock.c    2012-08-03 23:36:11 +0000
@@ -337,31 +337,22 @@
 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 ();
+  printmax_t 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 ();
+  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 ? "address@hidden"pMd":%"pMd : 
"address@hidden"pMd,
            user_name, host_name, pid, boot);
@@ -593,7 +584,7 @@
   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, "address@hidden (pid %"pMd")",
            lock_info.user, lock_info.host, pid);

=== modified file 'src/fns.c'
--- a/src/fns.c 2012-08-01 20:51:44 +0000
+++ b/src/fns.c 2012-08-03 23:36:11 +0000
@@ -903,7 +903,7 @@
   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 @@
   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 @@
 
   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 @@
   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 @@
   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 @@
      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 @@
 
   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,

=== modified file 'src/font.c'
--- a/src/font.c        2012-08-01 20:51:44 +0000
+++ b/src/font.c        2012-08-03 23:36:11 +0000
@@ -2227,7 +2227,7 @@
       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;
 

=== modified file 'src/frame.c'
--- a/src/frame.c       2012-08-01 05:11:36 +0000
+++ b/src/frame.c       2012-08-03 23:36:11 +0000
@@ -3697,8 +3697,6 @@
 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 @@
 
   /* 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);

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2012-08-01 20:51:44 +0000
+++ b/src/keyboard.c    2012-08-03 23:36:11 +0000
@@ -6480,7 +6480,7 @@
          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 @@
     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);

=== modified file 'src/keymap.c'
--- a/src/keymap.c      2012-08-01 05:11:36 +0000
+++ b/src/keymap.c      2012-08-03 23:36:11 +0000
@@ -2304,11 +2304,10 @@
     {
       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 ();

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2012-08-03 20:55:27 +0000
+++ b/src/lisp.h        2012-08-03 23:36:11 +0000
@@ -3441,24 +3441,16 @@
 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 @@
 #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_;                                 \

=== modified file 'src/lread.c'
--- a/src/lread.c       2012-08-01 20:51:44 +0000
+++ b/src/lread.c       2012-08-03 23:36:11 +0000
@@ -4317,12 +4317,10 @@
   /* 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 ();
     }

=== modified file 'src/macros.c'
--- a/src/macros.c      2012-07-05 18:35:48 +0000
+++ b/src/macros.c      2012-08-03 23:36:11 +0000
@@ -72,8 +72,8 @@
       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;

=== modified file 'src/menu.c'
--- a/src/menu.c        2012-08-01 20:51:44 +0000
+++ b/src/menu.c        2012-08-03 23:36:11 +0000
@@ -976,8 +976,7 @@
 
   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)
     {

=== modified file 'src/minibuf.c'
--- a/src/minibuf.c     2012-08-01 05:11:36 +0000
+++ b/src/minibuf.c     2012-08-03 23:36:11 +0000
@@ -264,7 +264,7 @@
              if (STRING_BYTES_BOUND / 2 < size)
                memory_full (SIZE_MAX);
              size *= 2;
-             line = (char *) xrealloc (line, size);
+             line = xrealloc (line, size);
            }
          line[len++] = c;
        }

=== modified file 'src/print.c'
--- a/src/print.c       2012-08-01 06:23:24 +0000
+++ b/src/print.c       2012-08-03 23:36:11 +0000
@@ -392,16 +392,14 @@
        {
          /* 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 @@
   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 ();
     }

=== modified file 'src/sysdep.c'
--- a/src/sysdep.c      2012-08-02 07:31:34 +0000
+++ b/src/sysdep.c      2012-08-03 23:36:11 +0000
@@ -2031,7 +2031,7 @@
   int rtnval;
 
   rtnval = emacs_close (dirp->dd_fd);
-  xfree ((char *) dirp);
+  xfree (dirp);
 
   return rtnval;
 }

=== modified file 'src/w32menu.c'
--- a/src/w32menu.c     2012-08-01 20:51:44 +0000
+++ b/src/w32menu.c     2012-08-03 23:36:11 +0000
@@ -1243,7 +1243,7 @@
             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 @@
 
       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 @@
       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 @@
       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,

=== modified file 'src/xdisp.c'
--- a/src/xdisp.c       2012-08-01 15:39:21 +0000
+++ b/src/xdisp.c       2012-08-03 23:36:11 +0000
@@ -2660,9 +2660,9 @@
      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 @@
   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 @@
   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 @@
 #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 @@
          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 @@
          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)

=== modified file 'src/xfaces.c'
--- a/src/xfaces.c      2012-08-02 09:33:13 +0000
+++ b/src/xfaces.c      2012-08-03 23:36:11 +0000
@@ -1559,8 +1559,10 @@
 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++)

=== modified file 'src/xfns.c'
--- a/src/xfns.c        2012-08-01 05:11:36 +0000
+++ b/src/xfns.c        2012-08-03 23:36:11 +0000
@@ -460,7 +460,7 @@
       if (! success)
        break;
 
-      XFree ((char *) tmp_children);
+      XFree (tmp_children);
 
       if (wm_window == rootw || had_errors)
         break;
@@ -4001,7 +4001,7 @@
        fatal ("Can't get proper X visual info");
 
       dpyinfo->n_planes = vinfo->depth;
-      XFree ((char *) vinfo);
+      XFree (vinfo);
     }
 }
 

=== modified file 'src/xfont.c'
--- a/src/xfont.c       2012-08-01 20:51:44 +0000
+++ b/src/xfont.c       2012-08-03 23:36:11 +0000
@@ -1035,10 +1035,8 @@
 
   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;

=== modified file 'src/xselect.c'
--- a/src/xselect.c     2012-07-05 18:35:48 +0000
+++ b/src/xselect.c     2012-08-03 23:36:11 +0000
@@ -216,7 +216,7 @@
       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 @@
     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 @@
       offset += bytes_gotten;
 
       /* This was allocated by Xlib, so use XFree.  */
-      XFree ((char *) tmp_data);
+      XFree (tmp_data);
     }
 
   XFlush (display);
@@ -1568,7 +1568,7 @@
       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 @@
 
   /* Use xfree, not XFree, because x_get_window_property
      calls xmalloc itself.  */
-  xfree ((char *) data);
+  xfree (data);
   return val;
 }
 

=== modified file 'src/xterm.c'
--- a/src/xterm.c       2012-08-01 07:57:09 +0000
+++ b/src/xterm.c       2012-08-03 23:36:11 +0000
@@ -520,7 +520,7 @@
     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 @@
       dpyinfo->alt_mod_mask &= ~dpyinfo->meta_mod_mask;
     }
 
-  XFree ((char *) syms);
+  XFree (syms);
   XFreeModifiermap (mods);
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]