+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):
#ifdef SUSPICIOUS_OBJECT_CHECKING
struct suspicious_free_record {
- void* suspicious_object;
+ void *suspicious_object;
#ifdef HAVE_EXECINFO_H
- void* backtrace[128];
+ void *backtrace[128];
#endif
};
-static void* suspicious_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 (void* ptr);
+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)
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;
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)
Vmemory_full = Qnil;
#endif
}
-
\f
/************************************************************************
C Stack Marking
#ifdef SUSPICIOUS_OBJECT_CHECKING
static void*
-find_suspicious_object_in_range (void* begin, void* end)
+find_suspicious_object_in_range (void *begin, void *end)
{
- char* begin_a = begin;
- char* end_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 (void* ptr)
+detect_suspicious_free (void *ptr)
{
int i;
struct suspicious_free_record* rec;
{
#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;
}
}
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);
}
Lisp_Object
-from_unicode_buffer (const wchar_t* wstr)
+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)));
}
extern Lisp_Object from_unicode (Lisp_Object str);
/* Convert WSTR to an Emacs string. */
-extern Lisp_Object from_unicode_buffer (const wchar_t* wstr);
+extern Lisp_Object from_unicode_buffer (const wchar_t *wstr);
#endif /* WINDOWSNT || CYGWIN */
{
#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);
/* 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;
{
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);
}
{ &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. */
{
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;
#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)
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
#ifdef HAVE_GNUTLS3
/* Function to log a simple audit message. */
static void
-gnutls_audit_log_function (gnutls_session_t session, const char* string)
+gnutls_audit_log_function (gnutls_session_t session, const char *string)
{
if (global_gnutls_log_level >= 1)
{
/* Function to log a simple message. */
static void
-gnutls_log_function (int level, const char* string)
+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 char* string, int extra)
+gnutls_log_function2i (int level, const char *string, int extra)
{
message ("gnutls.c: [%d] %s %d", level, string, extra);
}
Lisp_Object global_init;
char const *priority_string_ptr = "NORMAL"; /* default priority string. */
unsigned int peer_verification;
- char* c_hostname;
+ char *c_hostname;
/* Placeholders for the property list elements. */
Lisp_Object priority_string;
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,
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
}
\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
static int menu_bar_items_index;
-static const char* separator_names[] = {
+static const char *separator_names[] = {
"space",
"no-line",
"single-line",
/* 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);
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;
extern void keys_of_keymap (void);
typedef void (*map_keymap_function_t)
- (Lisp_Object key, Lisp_Object val, Lisp_Object args, void* data);
+ (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,
#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
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);
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;
/* 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;
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"
return decode_mode_spec_buf;
no_value:
{
- char* p = decode_mode_spec_buf;
+ char *p = decode_mode_spec_buf;
int pad = width - 2;
while (pad-- > 0)
*p++ = ' ';
#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). */
{
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);
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);
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");
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;
{
#define SM_ERRORSTRING_LEN 512
char errorstring[SM_ERRORSTRING_LEN];
- char* previous_id = NULL;
+ char *previous_id = NULL;
SmcCallbacks callbacks;
ptrdiff_t name_len = 0;
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;
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)
#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);