Prefer 'ARRAYELTS (x)' to 'sizeof x / sizeof *x'.
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Apr 2014 19:30:36 +0000 (12:30 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Apr 2014 19:30:36 +0000 (12:30 -0700)
* alloc.c (memory_full):
* charset.c (syms_of_charset):
* doc.c (Fsnarf_documentation):
* emacs.c (main):
* font.c (BUILD_STYLE_TABLE):
* keyboard.c (make_lispy_event):
* profiler.c (setup_cpu_timer):
* xgselect.c (xg_select):
* xterm.c (record_event, STORE_KEYSYM_FOR_DEBUG):
Use ARRAYELTS.
* font.c (FONT_PROPERTY_TABLE_SIZE): Remove.
Replace the only use with ARRAYELTS (font_property_table).
* xfaces.c (DIM): Remove.  All uses replaced by ARRAYELTS.

23 files changed:
src/ChangeLog
src/alloc.c
src/charset.c
src/coding.c
src/coding.h
src/doc.c
src/emacs.c
src/font.c
src/gnutls.c
src/keyboard.c
src/keymap.c
src/keymap.h
src/lisp.h
src/process.c
src/profiler.c
src/sysdep.c
src/unexcoff.c
src/xdisp.c
src/xfaces.c
src/xgselect.c
src/xsmfns.c
src/xterm.c
src/xterm.h

index 7152890..a474c26 100644 (file)
@@ -1,3 +1,20 @@
+2014-04-05  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Prefer 'ARRAYELTS (x)' to 'sizeof x / sizeof *x'.
+       * alloc.c (memory_full):
+       * charset.c (syms_of_charset):
+       * doc.c (Fsnarf_documentation):
+       * emacs.c (main):
+       * font.c (BUILD_STYLE_TABLE):
+       * keyboard.c (make_lispy_event):
+       * profiler.c (setup_cpu_timer):
+       * xgselect.c (xg_select):
+       * xterm.c (record_event, STORE_KEYSYM_FOR_DEBUG):
+       Use ARRAYELTS.
+       * font.c (FONT_PROPERTY_TABLE_SIZE): Remove.
+       Replace the only use with ARRAYELTS (font_property_table).
+       * xfaces.c (DIM): Remove.  All uses replaced by ARRAYELTS.
+
 2014-04-03  Daniel Colascione  <dancol@dancol.org>
 
        * xterm.c (x_term_init):
index 9740afe..2919c21 100644 (file)
@@ -208,19 +208,19 @@ const char *pending_malloc_warning;
 
 #ifdef SUSPICIOUS_OBJECT_CHECKING
 struct suspicious_free_record {
-  voidsuspicious_object;
+  void *suspicious_object;
 #ifdef HAVE_EXECINFO_H
-  voidbacktrace[128];
+  void *backtrace[128];
 #endif
 };
-static voidsuspicious_objects[32];
+static void *suspicious_objects[32];
 static int suspicious_object_index;
 struct suspicious_free_record suspicious_free_history[64];
 static int suspicious_free_history_index;
 /* Find the first currently-monitored suspicious pointer in range
    [begin,end) or NULL if no such pointer exists.  */
-static void* find_suspicious_object_in_range (void* begin, void* end);
-static void detect_suspicious_free (voidptr);
+static void *find_suspicious_object_in_range (void *begin, void *end);
+static void detect_suspicious_free (void *ptr);
 #else
 #define find_suspicious_object_in_range(begin, end) NULL
 #define detect_suspicious_free(ptr) (void)
@@ -3116,7 +3116,7 @@ allocate_vectorlike (ptrdiff_t len)
         mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
 #endif
 
-      if (find_suspicious_object_in_range (p, (char*)p + nbytes))
+      if (find_suspicious_object_in_range (p, (char *) p + nbytes))
         emacs_abort ();
 
       consing_since_gc += nbytes;
@@ -3765,7 +3765,7 @@ memory_full (size_t nbytes)
       memory_full_cons_threshold = sizeof (struct cons_block);
 
       /* The first time we get here, free the spare memory.  */
-      for (i = 0; i < sizeof (spare_memory) / sizeof (char *); i++)
+      for (i = 0; i < ARRAYELTS (spare_memory); i++)
        if (spare_memory[i])
          {
            if (i == 0)
@@ -3818,7 +3818,6 @@ refill_memory_reserve (void)
     Vmemory_full = Qnil;
 #endif
 }
-
 \f
 /************************************************************************
                           C Stack Marking
@@ -6829,23 +6828,24 @@ which_symbols (Lisp_Object obj, EMACS_INT find_max)
 #ifdef SUSPICIOUS_OBJECT_CHECKING
 
 static void*
-find_suspicious_object_in_range (void* begin, void* end)
+find_suspicious_object_in_range (void *begin, void *end)
 {
-  charbegin_a = begin;
-  charend_a = end;
+  char *begin_a = begin;
+  char *end_a = end;
   int i;
 
-  for (i = 0; i < ARRAYELTS (suspicious_objects); ++i) {
-    char* suspicious_object = suspicious_objects[i];
-    if (begin_a <= suspicious_object && suspicious_object < end_a)
-      return suspicious_object;
-  }
+  for (i = 0; i < ARRAYELTS (suspicious_objects); ++i)
+    {
+      char *suspicious_object = suspicious_objects[i];
+      if (begin_a <= suspicious_object && suspicious_object < end_a)
+       return suspicious_object;
+    }
 
   return NULL;
 }
 
 static void
-detect_suspicious_free (voidptr)
+detect_suspicious_free (void *ptr)
 {
   int i;
   struct suspicious_free_record* rec;
@@ -6882,11 +6882,12 @@ garbage collection bugs.  Otherwise, do nothing and return OBJ.   */)
 {
 #ifdef SUSPICIOUS_OBJECT_CHECKING
   /* Right now, we care only about vectors.  */
-  if (VECTORLIKEP (obj)) {
-    suspicious_objects[suspicious_object_index++] = XVECTOR (obj);
-    if (suspicious_object_index == ARRAYELTS (suspicious_objects))
-      suspicious_object_index = 0;
-  }
+  if (VECTORLIKEP (obj))
+    {
+      suspicious_objects[suspicious_object_index++] = XVECTOR (obj);
+      if (suspicious_object_index == ARRAYELTS (suspicious_objects))
+       suspicious_object_index = 0;
+    }
 #endif
   return obj;
 }
index 3566b15..baa6922 100644 (file)
@@ -2386,7 +2386,7 @@ syms_of_charset (void)
   }
 
   charset_table = charset_table_init;
-  charset_table_size = sizeof charset_table_init / sizeof *charset_table_init;
+  charset_table_size = ARRAYELTS (charset_table_init);
   charset_table_used = 0;
 
   defsubr (&Scharsetp);
index 654e39c..fbe14f1 100644 (file)
@@ -8443,11 +8443,11 @@ from_unicode (Lisp_Object str)
 }
 
 Lisp_Object
-from_unicode_buffer (const wchar_twstr)
+from_unicode_buffer (const wchar_t *wstr)
 {
     return from_unicode (
         make_unibyte_string (
-            (char*) wstr,
+            (char *) wstr,
             /* we get one of the two final 0 bytes for free. */
             1 + sizeof (wchar_t) * wcslen (wstr)));
 }
index 4e8b105..f3efcca 100644 (file)
@@ -743,7 +743,7 @@ extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
 extern Lisp_Object from_unicode (Lisp_Object str);
 
 /* Convert WSTR to an Emacs string.  */
-extern Lisp_Object from_unicode_buffer (const wchar_twstr);
+extern Lisp_Object from_unicode_buffer (const wchar_t *wstr);
 
 #endif /* WINDOWSNT || CYGWIN */
 
index b6a4cd0..df8cfba 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -595,7 +595,7 @@ the same file name is found in the `doc-directory'.  */)
        {
          #include "buildobj.h"
        };
-      int i = sizeof buildobj / sizeof *buildobj;
+      int i = ARRAYELTS (buildobj);
       while (0 <= --i)
        Vbuild_files = Fcons (build_string (buildobj[i]), Vbuild_files);
       Vbuild_files = Fpurecopy (Vbuild_files);
index 75498dc..deebb22 100644 (file)
@@ -136,7 +136,7 @@ static void *malloc_state_ptr;
 /* From glibc, a routine that returns a copy of the malloc internal state.  */
 extern void *malloc_get_state (void);
 /* From glibc, a routine that overwrites the malloc internal state.  */
-extern int malloc_set_state (void*);
+extern int malloc_set_state (void *);
 /* True if the MALLOC_CHECK_ environment variable was set while
    dumping.  Used to work around a bug in glibc's malloc.  */
 static bool malloc_using_checking;
@@ -1008,7 +1008,7 @@ main (int argc, char **argv)
     {
       int i;
       printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]);
-      for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++)
+      for (i = 0; i < ARRAYELTS (usage_message); i++)
        fputs (usage_message[i], stdout);
       exit (0);
     }
index e99141b..5faf477 100644 (file)
@@ -662,10 +662,6 @@ static const struct
     { &QCotf, font_prop_validate_otf }
   };
 
-/* Size (number of elements) of the above table.  */
-#define FONT_PROPERTY_TABLE_SIZE \
-  ((sizeof font_property_table) / (sizeof *font_property_table))
-
 /* Return an index number of font property KEY or -1 if KEY is not an
    already known property.  */
 
@@ -674,7 +670,7 @@ get_font_prop_index (Lisp_Object key)
 {
   int i;
 
-  for (i = 0; i < FONT_PROPERTY_TABLE_SIZE; i++)
+  for (i = 0; i < ARRAYELTS (font_property_table); i++)
     if (EQ (key, *font_property_table[i].key))
       return i;
   return -1;
@@ -4935,8 +4931,7 @@ If the named font is not yet loaded, return nil.  */)
 #endif
 
 \f
-#define BUILD_STYLE_TABLE(TBL) \
-  build_style_table ((TBL), sizeof TBL / sizeof (struct table_entry))
+#define BUILD_STYLE_TABLE(TBL) build_style_table (TBL, ARRAYELTS (TBL))
 
 static Lisp_Object
 build_style_table (const struct table_entry *entry, int nelement)
index 03c29d0..d9b417b 100644 (file)
@@ -56,7 +56,7 @@ static Lisp_Object QCgnutls_bootprop_verify_error;
 static Lisp_Object QCgnutls_bootprop_callbacks_verify;
 
 static void gnutls_log_function (int, const char *);
-static void gnutls_log_function2 (int, const char*, const char*);
+static void gnutls_log_function2 (int, const char *, const char *);
 #ifdef HAVE_GNUTLS3
 static void gnutls_audit_log_function (gnutls_session_t, const char *);
 #endif
@@ -267,7 +267,7 @@ init_gnutls_functions (void)
 #ifdef HAVE_GNUTLS3
 /* Function to log a simple audit message.  */
 static void
-gnutls_audit_log_function (gnutls_session_t session, const charstring)
+gnutls_audit_log_function (gnutls_session_t session, const char *string)
 {
   if (global_gnutls_log_level >= 1)
     {
@@ -278,21 +278,21 @@ gnutls_audit_log_function (gnutls_session_t session, const char* string)
 
 /* Function to log a simple message.  */
 static void
-gnutls_log_function (int level, const charstring)
+gnutls_log_function (int level, const char *string)
 {
   message ("gnutls.c: [%d] %s", level, string);
 }
 
 /* Function to log a message and a string.  */
 static void
-gnutls_log_function2 (int level, const char* string, const char* extra)
+gnutls_log_function2 (int level, const char *string, const char *extra)
 {
   message ("gnutls.c: [%d] %s %s", level, string, extra);
 }
 
 /* Function to log a message and an integer.  */
 static void
-gnutls_log_function2i (int level, const charstring, int extra)
+gnutls_log_function2i (int level, const char *string, int extra)
 {
   message ("gnutls.c: [%d] %s %d", level, string, extra);
 }
@@ -794,7 +794,7 @@ one trustfile (usually a CA bundle).  */)
   Lisp_Object global_init;
   char const *priority_string_ptr = "NORMAL"; /* default priority string.  */
   unsigned int peer_verification;
-  charc_hostname;
+  char *c_hostname;
 
   /* Placeholders for the property list elements.  */
   Lisp_Object priority_string;
index 6de5370..277d4f1 100644 (file)
@@ -5478,7 +5478,7 @@ make_lispy_event (struct input_event *event)
     case NON_ASCII_KEYSTROKE_EVENT:
       button_down_time = 0;
 
-      for (i = 0; i < sizeof (lispy_accent_codes) / sizeof (int); i++)
+      for (i = 0; i < ARRAYELTS (lispy_accent_codes); i++)
        if (event->code == lispy_accent_codes[i])
          return modify_event_symbol (i,
                                      event->modifiers,
@@ -5511,7 +5511,7 @@ make_lispy_event (struct input_event *event)
       if (event->code & (1 << 28)
          || event->code - FUNCTION_KEY_OFFSET < 0
          || (event->code - FUNCTION_KEY_OFFSET
-             >= sizeof lispy_function_keys / sizeof *lispy_function_keys)
+             >= ARRAYELTS (lispy_function_keys))
          || !lispy_function_keys[event->code - FUNCTION_KEY_OFFSET])
        {
          /* We need to use an alist rather than a vector as the cache
@@ -7282,7 +7282,7 @@ store_user_signal_events (void)
 }
 
 \f
-static void menu_bar_item (Lisp_Object, Lisp_Object, Lisp_Object, void*);
+static void menu_bar_item (Lisp_Object, Lisp_Object, Lisp_Object, void *);
 static Lisp_Object menu_bar_one_keymap_changed_items;
 
 /* These variables hold the vector under construction within
@@ -7292,7 +7292,7 @@ static Lisp_Object menu_bar_items_vector;
 static int menu_bar_items_index;
 
 
-static const charseparator_names[] = {
+static const char *separator_names[] = {
   "space",
   "no-line",
   "single-line",
@@ -7900,7 +7900,8 @@ static Lisp_Object QCrtl;
 /* Function prototypes.  */
 
 static void init_tool_bar_items (Lisp_Object);
-static void process_tool_bar_item (Lisp_Object, Lisp_Object, Lisp_Object, void*);
+static void process_tool_bar_item (Lisp_Object, Lisp_Object, Lisp_Object,
+                                  void *);
 static bool parse_tool_bar_item (Lisp_Object, Lisp_Object);
 static void append_tool_bar_item (void);
 
index c1416f8..663c466 100644 (file)
@@ -1894,7 +1894,7 @@ struct accessible_keymaps_data {
 
 static void
 accessible_keymaps_1 (Lisp_Object key, Lisp_Object cmd, Lisp_Object args, void *data)
-/* Use void* data to be compatible with map_keymap_function_t.  */
+/* Use void * data to be compatible with map_keymap_function_t.  */
 {
   struct accessible_keymaps_data *d = data; /* Cast! */
   Lisp_Object maps = d->maps;
index 4a408c6..b01886d 100644 (file)
@@ -46,7 +46,7 @@ extern void syms_of_keymap (void);
 extern void keys_of_keymap (void);
 
 typedef void (*map_keymap_function_t)
-     (Lisp_Object key, Lisp_Object val, Lisp_Object args, voiddata);
+     (Lisp_Object key, Lisp_Object val, Lisp_Object args, void *data);
 extern void map_keymap (Lisp_Object, map_keymap_function_t, Lisp_Object,
                        void *, bool);
 extern void map_keymap_canonical (Lisp_Object map,
index a697e39..03c0d99 100644 (file)
@@ -58,8 +58,8 @@ INLINE_HEADER_BEGIN
 #define max(a, b) ((a) > (b) ? (a) : (b))
 #define min(a, b) ((a) < (b) ? (a) : (b))
 
-/* Find number of elements in array */
-#define ARRAYELTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
+/* Number of elements in an array.  */
+#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
 
 /* EMACS_INT - signed integer wide enough to hold an Emacs value
    EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
index fe365a1..5a5ce0c 100644 (file)
@@ -2022,11 +2022,11 @@ conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
            terminator, however.  */
         if (name_length > 0 && sockun->sun_path[0] != '\0')
           {
-            const char* terminator =
-              memchr (sockun->sun_path, '\0', name_length);
+            const char *terminator
+             = memchr (sockun->sun_path, '\0', name_length);
 
             if (terminator)
-              name_length = terminator - (const char*) sockun->sun_path;
+              name_length = terminator - (const char *) sockun->sun_path;
           }
 
        return make_unibyte_string (sockun->sun_path, name_length);
index 8b092dc..ff97fe8 100644 (file)
@@ -294,7 +294,7 @@ setup_cpu_timer (Lisp_Object sampling_interval)
       sigev.sigev_signo = SIGPROF;
       sigev.sigev_notify = SIGEV_SIGNAL;
 
-      for (i = 0; i < sizeof system_clock / sizeof *system_clock; i++)
+      for (i = 0; i < ARRAYELTS (system_clock); i++)
        if (timer_create (system_clock[i], &sigev, &profiler_timer) == 0)
          {
            profiler_timer_ok = 1;
index 964dc41..7a88883 100644 (file)
@@ -128,7 +128,7 @@ static const int baud_convert[] =
 /* Return the current working directory.  Returns NULL on errors.
    Any other returned value must be freed with free. This is used
    only when get_current_dir_name is not defined on the system.  */
-char*
+char *
 get_current_dir_name (void)
 {
   char *buf;
index 5710ac0..cb0b6f2 100644 (file)
@@ -120,7 +120,7 @@ static int pagemask;
    into an int which is the number of a byte.
    This is a no-op on ordinary machines, but not on all.  */
 
-#define ADDR_CORRECT(x) ((char *)(x) - (char*)0)
+#define ADDR_CORRECT(x) ((char *) (x) - (char *) 0)
 
 #include "lisp.h"
 
index 53bd463..3431a7b 100644 (file)
@@ -22639,7 +22639,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
        return decode_mode_spec_buf;
     no_value:
         {
-         charp = decode_mode_spec_buf;
+         char *p = decode_mode_spec_buf;
          int pad = width - 2;
          while (pad-- > 0)
            *p++ = ' ';
index 7a63070..4e599d0 100644 (file)
@@ -273,10 +273,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define IGNORE_DEFFACE_P(ATTR) EQ ((ATTR), QCignore_defface)
 
-/* Value is the number of elements of VECTOR.  */
-
-#define DIM(VECTOR) (sizeof (VECTOR) / sizeof *(VECTOR))
-
 /* Size of hash table of realized faces in face caches (should be a
    prime number).  */
 
@@ -5093,14 +5089,14 @@ Value is ORDER.  */)
 {
   Lisp_Object list;
   int i;
-  int indices[DIM (font_sort_order)];
+  int indices[ARRAYELTS (font_sort_order)];
 
   CHECK_LIST (order);
   memset (indices, 0, sizeof indices);
   i = 0;
 
   for (list = order;
-       CONSP (list) && i < DIM (indices);
+       CONSP (list) && i < ARRAYELTS (indices);
        list = XCDR (list), ++i)
     {
       Lisp_Object attr = XCAR (list);
@@ -5122,9 +5118,9 @@ Value is ORDER.  */)
       indices[i] = xlfd;
     }
 
-  if (!NILP (list) || i != DIM (indices))
+  if (!NILP (list) || i != ARRAYELTS (indices))
     signal_error ("Invalid font sort order", order);
-  for (i = 0; i < DIM (font_sort_order); ++i)
+  for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
     if (indices[i] == 0)
       signal_error ("Invalid font sort order", order);
 
@@ -6348,7 +6344,7 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
       int i;
 
       fprintf (stderr, "font selection order: ");
-      for (i = 0; i < DIM (font_sort_order); ++i)
+      for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
        fprintf (stderr, "%d ", font_sort_order[i]);
       fprintf (stderr, "\n");
 
index 1d3f916..5f71ff8 100644 (file)
@@ -41,7 +41,7 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
   int have_wfds = wfds != NULL;
   GPollFD gfds_buf[128];
   GPollFD *gfds = gfds_buf;
-  int gfds_size = sizeof gfds_buf / sizeof *gfds_buf;
+  int gfds_size = ARRAYELTS (gfds_buf);
   int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
   int i, nfds, tmo_in_millisec;
   bool need_to_dispatch;
index 9a31f51..81b0126 100644 (file)
@@ -395,7 +395,7 @@ x_session_initialize (struct x_display_info *dpyinfo)
 {
 #define SM_ERRORSTRING_LEN 512
   char errorstring[SM_ERRORSTRING_LEN];
-  charprevious_id = NULL;
+  char *previous_id = NULL;
   SmcCallbacks callbacks;
   ptrdiff_t name_len = 0;
 
index a04f2fe..dd71a8a 100644 (file)
@@ -308,7 +308,7 @@ int event_record_index;
 void
 record_event (char *locus, int type)
 {
-  if (event_record_index == sizeof (event_record) / sizeof (struct record))
+  if (event_record_index == ARRAYELTS (event_record))
     event_record_index = 0;
 
   event_record[event_record_index].locus = locus;
@@ -5624,7 +5624,7 @@ static int temp_index;
 static short temp_buffer[100];
 
 #define STORE_KEYSYM_FOR_DEBUG(keysym)                         \
-  if (temp_index == sizeof temp_buffer / sizeof (short))       \
+  if (temp_index == ARRAYELTS (temp_buffer))                   \
     temp_index = 0;                                            \
   temp_buffer[temp_index++] = (keysym)
 
index 50df88c..90d2e13 100644 (file)
@@ -996,7 +996,7 @@ extern Lisp_Object x_get_focus_frame (struct frame *);
 
 #ifdef USE_GTK
 extern int xg_set_icon (struct frame *, Lisp_Object);
-extern int xg_set_icon_from_xpm_data (struct frame *, const char**);
+extern int xg_set_icon_from_xpm_data (struct frame *, const char **);
 #endif /* USE_GTK */
 
 extern void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);