diff --git a/admin/coccinelle/arrayelts.cocci b/admin/coccinelle/arrayelts.cocci
index 5376a94bd85..9e1e0e64a9d 100644
--- a/admin/coccinelle/arrayelts.cocci
+++ b/admin/coccinelle/arrayelts.cocci
@@ -1,21 +1,21 @@
-// Use the ARRAYELTS macro where possible.
+// Use the countof macro where possible.
@@
type T;
T[] E;
@@
- (sizeof (E) / sizeof (E[...]))
-+ ARRAYELTS (E)
++ countof (E)
@@
type T;
T[] E;
@@
- (sizeof (E) / sizeof (T))
-+ ARRAYELTS (E)
++ countof (E)
@@
type T;
T[] E;
@@
- (sizeof (E) / sizeof (*E))
-+ ARRAYELTS (E)
++ countof (E)
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 20cea5b41e4..8c906d34cef 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -50,7 +50,7 @@ GNULIB_MODULES='
qcopy-acl readlink readlinkat realloc-posix regex
sig2str sigdescr_np socklen stat-time std-gnu23
stdc_bit_width stdc_count_ones stdc_trailing_zeros
- stdckdint-h stddef-h stdio-h stdio-windows
+ stdckdint-h stdcountof-h stddef-h stdio-h stdio-windows
stpcpy streq strnlen strtoimax symlink sys_stat-h sys_time-h
tempname time-h time_r time_rz timegm timer-time timespec-add timespec-sub
unlocked-io update-copyright utimensat
diff --git a/exec/trace.c b/exec/trace.c
index da9ac96c6ff..a194b87ca84 100644
--- a/exec/trace.c
+++ b/exec/trace.c
@@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */
#include
#include
#include
+#include
#include
#include
#include
@@ -1538,9 +1539,6 @@ static int interesting_syscalls[] =
READLINKAT_SYSCALL,
};
-/* Number of elements in an array. */
-#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
-
/* Install a secure computing filter that will notify attached tracers
when a system call of interest to this module is received. Value is
0 if successful, 1 otherwise. */
@@ -1548,7 +1546,7 @@ static int interesting_syscalls[] =
static int
establish_seccomp_filter (void)
{
- struct sock_filter statements[1 + ARRAYELTS (interesting_syscalls) + 2];
+ struct sock_filter statements[1 + countof (interesting_syscalls) + 2];
struct sock_fprog program;
int index, rc;
@@ -1567,27 +1565,27 @@ establish_seccomp_filter (void)
statements[index]
= ((struct sock_filter)
BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, EXEC_SYSCALL,
- ARRAYELTS (interesting_syscalls), 0)); index++;
+ countof (interesting_syscalls), 0)); index++;
#ifdef OPEN_SYSCALL
statements[index]
= ((struct sock_filter)
BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, OPEN_SYSCALL,
- ARRAYELTS (interesting_syscalls) - index + 1, 0)); index++;
+ countof (interesting_syscalls) - index + 1, 0)); index++;
#endif /* OPEN_SYSCALL */
statements[index]
= ((struct sock_filter)
BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, OPENAT_SYSCALL,
- ARRAYELTS (interesting_syscalls) - index + 1, 0)); index++;
+ countof (interesting_syscalls) - index + 1, 0)); index++;
#ifdef READLINK_SYSCALL
statements[index]
= ((struct sock_filter)
BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, READLINK_SYSCALL,
- ARRAYELTS (interesting_syscalls) - index + 1, 0)); index++;
+ countof (interesting_syscalls) - index + 1, 0)); index++;
#endif /* READLINK_SYSCALL */
statements[index]
= ((struct sock_filter)
BPF_JUMP (BPF_JMP + BPF_JEQ + BPF_K, READLINKAT_SYSCALL,
- ARRAYELTS (interesting_syscalls) - index + 1, 0)); index++;
+ countof (interesting_syscalls) - index + 1, 0)); index++;
/* If not intercepted above, permit this system call to execute as
normal. */
@@ -1600,7 +1598,7 @@ establish_seccomp_filter (void)
if (rc)
return 1;
- program.len = ARRAYELTS (statements);
+ program.len = countof (statements);
program.filter = statements;
rc = prctl (PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &program);
if (rc)
diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c
index 3bb6bd88d79..93c0b52b950 100644
--- a/lib-src/ebrowse.c
+++ b/lib-src/ebrowse.c
@@ -19,6 +19,8 @@ along with GNU Emacs. If not, see . */
#include
+
+#include
#include
#include
#include
@@ -3612,7 +3614,7 @@ static _Noreturn void
usage (int error)
{
int i;
- for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++)
+ for (i = 0; i < countof (usage_message); i++)
fputs (usage_message[i], stdout);
exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
}
diff --git a/lib-src/etags.c b/lib-src/etags.c
index 4114ba6b655..977484e4a67 100644
--- a/lib-src/etags.c
+++ b/lib-src/etags.c
@@ -110,6 +110,7 @@ University of California, as described above. */
#include
#include
#include
+#include
#include
#include
#include
@@ -6693,7 +6694,7 @@ mercury_decl (char *s, size_t pos)
}
else
{
- for (int j = 0; j < sizeof (Mercury_decl_tags) / sizeof (char*); ++j)
+ for (int j = 0; j < countof (Mercury_decl_tags); ++j)
{
if (memstreq (decl_type, decl_type_length, Mercury_decl_tags[j]))
{
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c
index f6e321d876a..f13ade84244 100644
--- a/lib-src/make-docfile.c
+++ b/lib-src/make-docfile.c
@@ -37,6 +37,7 @@ along with GNU Emacs. If not, see . */
#include
#include
+#include
#include
#include
#include
@@ -651,7 +652,7 @@ compare_globals (const void *a, const void *b)
/* Common symbols in decreasing popularity order. */
static char const commonsym[][8]
= { "nil", "t", "unbound", "error", "lambda" };
- int ncommonsym = sizeof commonsym / sizeof *commonsym;
+ int ncommonsym = countof (commonsym);
int ai = ncommonsym, bi = ncommonsym;
for (int i = 0; i < ncommonsym; i++)
{
diff --git a/lib-src/seccomp-filter.c b/lib-src/seccomp-filter.c
index a8cdc6e06f9..f58afbf272d 100644
--- a/lib-src/seccomp-filter.c
+++ b/lib-src/seccomp-filter.c
@@ -39,6 +39,7 @@ variants of those files that can be used to sandbox Emacs before
#include
#include
#include
+#include
#include
#include
#include
@@ -119,7 +120,7 @@ set_attribute (enum scmp_filter_attr attr, uint32_t value)
do \
{ \
const struct scmp_arg_cmp arg_array[] = {__VA_ARGS__}; \
- enum { arg_cnt = sizeof arg_array / sizeof *arg_array }; \
+ enum { arg_cnt = countof (arg_array) }; \
int status = seccomp_rule_add_array (ctx, action, syscall, \
arg_cnt, arg_array); \
if (status < 0) \
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 2a18a330fa1..0605164636d 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -167,6 +167,7 @@
# stdc_count_ones \
# stdc_trailing_zeros \
# stdckdint-h \
+# stdcountof-h \
# stddef-h \
# stdio-h \
# stdio-windows \
diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c
index 0699410cc82..72e7b23c654 100644
--- a/lwlib/lwlib-Xaw.c
+++ b/lwlib/lwlib-Xaw.c
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see . */
#include
+#include
#include
#include
@@ -527,11 +528,9 @@ make_dialog (char* name,
if (! actions_initted)
{
XtAppContext app = XtWidgetToApplicationContext (parent);
- XtAppAddActions (app, xaw_actions,
- sizeof (xaw_actions) / sizeof (xaw_actions[0]));
+ XtAppAddActions (app, xaw_actions, countof (xaw_actions));
#if defined USE_CAIRO || defined HAVE_XFT
- XtAppAddActions (app, button_actions,
- sizeof (button_actions) / sizeof (button_actions[0]));
+ XtAppAddActions (app, button_actions, countof (button_actions));
#endif
actions_initted = True;
}
diff --git a/src/alloc.c b/src/alloc.c
index 395cca304c6..5fc166dbc24 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4150,7 +4150,7 @@ memory_full (size_t nbytes)
consing_until_gc = min (consing_until_gc, memory_full_cons_threshold);
/* The first time we get here, free the spare memory. */
- for (int i = 0; i < ARRAYELTS (spare_memory); i++)
+ for (int i = 0; i < countof (spare_memory); i++)
if (spare_memory[i])
{
if (i == 0)
@@ -5679,7 +5679,7 @@ visit_static_gc_roots (struct gc_root_visitor visitor)
&buffer_local_symbols,
GC_ROOT_BUFFER_LOCAL_NAME);
- for (int i = 0; i < ARRAYELTS (lispsym); i++)
+ for (int i = 0; i < countof (lispsym); i++)
{
Lisp_Object sptr = builtin_lisp_symbol (i);
visitor.visit (&sptr, GC_ROOT_C_SYMBOL, visitor.data);
@@ -7035,11 +7035,11 @@ sweep_symbols (void)
struct symbol_block *sblk;
struct symbol_block **sprev = &symbol_block;
int lim = symbol_block_index;
- object_ct num_free = 0, num_used = ARRAYELTS (lispsym);
+ object_ct num_free = 0, num_used = countof (lispsym);
symbol_free_list = NULL;
- for (int i = 0; i < ARRAYELTS (lispsym); i++)
+ for (int i = 0; i < countof (lispsym); i++)
lispsym[i].u.s.gcmarkbit = 0;
for (sblk = symbol_block; sblk; sblk = *sprev)
@@ -7305,7 +7305,7 @@ which_symbols (Lisp_Object obj, EMACS_INT find_max)
if (! deadp (obj))
{
- for (int i = 0; i < ARRAYELTS (lispsym); i++)
+ for (int i = 0; i < countof (lispsym); i++)
{
Lisp_Object sym = builtin_lisp_symbol (i);
if (symbol_uses_obj (sym, obj))
@@ -7473,7 +7473,7 @@ If this portion is smaller than `gc-cons-threshold', this is ignored. */);
DEFVAR_INT ("symbols-consed", symbols_consed,
doc: /* Number of symbols that have been consed so far. */);
- symbols_consed += ARRAYELTS (lispsym);
+ symbols_consed += countof (lispsym);
DEFVAR_INT ("string-chars-consed", string_chars_consed,
doc: /* Number of string characters that have been consed so far. */);
diff --git a/src/androidvfs.c b/src/androidvfs.c
index 311ea31cda6..50a48acdd63 100644
--- a/src/androidvfs.c
+++ b/src/androidvfs.c
@@ -1068,7 +1068,7 @@ android_scan_directory_tree (const char *file, size_t *limit_return)
copy = NULL;
/* Make sure ntokens is within bounds. */
- if (ntokens == ARRAYELTS (tokens))
+ if (ntokens == countof (tokens))
goto fail;
len = strlen (token) + 1;
@@ -2609,7 +2609,7 @@ android_content_name (struct android_vnode *vnode, char *name,
else
i = 0;
- for (; i < ARRAYELTS (content_vnodes); ++i)
+ for (; i < countof (content_vnodes); ++i)
{
special = &content_vnodes[i];
@@ -2769,7 +2769,7 @@ android_content_readdir (struct android_vdir *vdir)
/* There are no more files to be read. */
if (dir->next_name == (content_directory_contents
- + ARRAYELTS (content_directory_contents)))
+ + countof (content_directory_contents)))
return NULL;
/* Get the next child. */
@@ -6688,7 +6688,7 @@ android_root_name (struct android_vnode *vnode, char *name,
/* Now, find out if the first component is a special vnode; if so,
call its root lookup function with the rest of NAME there. */
- for (i = 0; i < ARRAYELTS (special_vnodes); ++i)
+ for (i = 0; i < countof (special_vnodes); ++i)
{
special = &special_vnodes[i];
@@ -6774,7 +6774,7 @@ android_root_readdir (struct android_vdir *vdir)
dir = (struct android_root_vdir *) vdir;
p = dir->directory ? readdir (dir->directory) : NULL;
- if (p || dir->index >= ARRAYELTS (special_vnodes))
+ if (p || dir->index >= countof (special_vnodes))
return p;
dirent.d_ino = 0;
diff --git a/src/bignum.c b/src/bignum.c
index 89145f2a9c0..405f1796e93 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -64,7 +64,7 @@ init_bignum (void)
'longjmp'. */
mp_set_memory_functions (xmalloc, xrealloc_for_gmp, xfree_for_gmp);
- for (int i = 0; i < ARRAYELTS (mpz); i++)
+ for (int i = 0; i < countof (mpz); i++)
mpz_init (mpz[i]);
}
diff --git a/src/chartab.c b/src/chartab.c
index 7d2710f20a3..758aec36929 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -1163,7 +1163,7 @@ uniprop_decode_value_run_length (Lisp_Object table, Lisp_Object value)
static uniprop_decoder_t uniprop_decoder [] =
{ uniprop_decode_value_run_length };
-static const int uniprop_decoder_count = ARRAYELTS (uniprop_decoder);
+static const int uniprop_decoder_count = countof (uniprop_decoder);
/* Return the decoder of char-table TABLE or nil if none. */
@@ -1238,7 +1238,7 @@ static uniprop_encoder_t uniprop_encoder[] =
uniprop_encode_value_run_length,
uniprop_encode_value_numeric };
-static const int uniprop_encoder_count = ARRAYELTS (uniprop_encoder);
+static const int uniprop_encoder_count = countof (uniprop_encoder);
/* Return the encoder of char-table TABLE or nil if none. */
diff --git a/src/comp.c b/src/comp.c
index 545d13b6bfd..b2b4fb6f222 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -827,10 +827,10 @@ freloc_check_fill (void)
eassert (!NILP (Vcomp_subr_list));
- if (ARRAYELTS (helper_link_table) > F_RELOC_MAX_SIZE)
+ if (countof (helper_link_table) > F_RELOC_MAX_SIZE)
goto overflow;
memcpy (freloc.link_table, helper_link_table, sizeof (helper_link_table));
- freloc.size = ARRAYELTS (helper_link_table);
+ freloc.size = countof (helper_link_table);
Lisp_Object subr_l = Vcomp_subr_list;
FOR_EACH_TAIL (subr_l)
@@ -1510,7 +1510,7 @@ emit_slow_eq (gcc_jit_rvalue *x, gcc_jit_rvalue *y)
return emit_call (intern_c_string ("slow_eq"),
comp.bool_type,
- ARRAYELTS (args),
+ countof (args),
args,
false);
}
@@ -2154,7 +2154,7 @@ emit_setjmp (gcc_jit_rvalue *buf)
gcc_jit_context_new_function (comp.ctxt, NULL,
GCC_JIT_FUNCTION_IMPORTED,
comp.int_type, STR (SETJMP_NAME),
- ARRAYELTS (params), params,
+ countof (params), params,
false);
return gcc_jit_context_new_call (comp.ctxt, NULL, f, 1, args);
@@ -2182,7 +2182,7 @@ emit_setjmp (gcc_jit_rvalue *buf)
gcc_jit_context_new_function (comp.ctxt, NULL,
GCC_JIT_FUNCTION_IMPORTED,
comp.int_type, STR (SETJMP_NAME),
- ARRAYELTS (params), params,
+ countof (params), params,
false);
return gcc_jit_context_new_call (comp.ctxt, NULL, f, 2, args);
@@ -2231,7 +2231,7 @@ emit_limple_insn (Lisp_Object insn)
ptrdiff_t i = 0;
FOR_EACH_TAIL (p)
{
- if (i == ARRAYELTS (arg))
+ if (i == countof (arg))
break;
arg[i++] = XCAR (p);
}
@@ -2732,7 +2732,7 @@ emit_static_object (const char *name, Lisp_Object obj)
gcc_jit_context_new_struct_type (comp.ctxt,
NULL,
format_string ("%s_struct", name),
- ARRAYELTS (fields), fields));
+ countof (fields), fields));
gcc_jit_lvalue *data_struct =
gcc_jit_context_new_global (comp.ctxt,
@@ -2807,7 +2807,7 @@ emit_static_object (const char *name, Lisp_Object obj)
gcc_jit_block_add_eval (block, NULL,
gcc_jit_context_new_call (comp.ctxt, NULL,
comp.memcpy,
- ARRAYELTS (args),
+ countof (args),
args));
gcc_jit_block_add_assignment (block, NULL, ptrvar,
gcc_jit_lvalue_get_address (
@@ -2975,7 +2975,7 @@ emit_ctxt_code (void)
Fcons (Qnative_comp_debug, make_fixnum (comp.debug)),
Fcons (Qgccjit,
Fcomp_libgccjit_version ()) };
- emit_static_object (TEXT_OPTIM_QLY_SYM, Flist (ARRAYELTS (opt_qly), opt_qly));
+ emit_static_object (TEXT_OPTIM_QLY_SYM, Flist (countof (opt_qly), opt_qly));
emit_static_object (TEXT_FDOC_SYM,
CALLNI (comp-ctxt-function-docs, Vcomp_ctxt));
@@ -3113,7 +3113,7 @@ define_lisp_cons (void)
gcc_jit_context_new_union_type (comp.ctxt,
NULL,
"comp_cdr_u",
- ARRAYELTS (cdr_u_fields),
+ countof (cdr_u_fields),
cdr_u_fields);
comp.lisp_cons_u_s_car = gcc_jit_context_new_field (comp.ctxt,
@@ -3132,7 +3132,7 @@ define_lisp_cons (void)
gcc_jit_context_new_struct_type (comp.ctxt,
NULL,
"comp_cons_s",
- ARRAYELTS (cons_s_fields),
+ countof (cons_s_fields),
cons_s_fields);
comp.lisp_cons_u_s = gcc_jit_context_new_field (comp.ctxt,
@@ -3155,7 +3155,7 @@ define_lisp_cons (void)
gcc_jit_context_new_union_type (comp.ctxt,
NULL,
"comp_cons_u",
- ARRAYELTS (cons_u_fields),
+ countof (cons_u_fields),
cons_u_fields);
comp.lisp_cons_u =
@@ -3234,7 +3234,7 @@ define_memcpy (void)
comp.memcpy =
gcc_jit_context_new_function (comp.ctxt, NULL, GCC_JIT_FUNCTION_IMPORTED,
comp.void_ptr_type, "memcpy",
- ARRAYELTS (params), params, false);
+ countof (params), params, false);
}
/* struct handler definition */
@@ -3294,7 +3294,7 @@ define_handler_struct (void)
"pad2") };
gcc_jit_struct_set_fields (comp.handler_s,
NULL,
- ARRAYELTS (fields),
+ countof (fields),
fields);
}
@@ -3338,7 +3338,7 @@ define_thread_state_struct (void)
gcc_jit_context_new_struct_type (comp.ctxt,
NULL,
"comp_thread_state",
- ARRAYELTS (fields),
+ countof (fields),
fields);
comp.thread_state_ptr_type =
gcc_jit_type_get_pointer (gcc_jit_struct_as_type (comp.thread_state_s));
@@ -4141,7 +4141,7 @@ declare_lex_function (Lisp_Object func)
GCC_JIT_FUNCTION_EXPORTED,
comp.lisp_obj_type,
SSDATA (c_name),
- ARRAYELTS (params), params, 0);
+ countof (params), params, 0);
}
SAFE_FREE ();
return res;
@@ -4471,7 +4471,7 @@ DEFUN ("comp--install-trampoline", Fcomp__install_trampoline,
subr_name);
Lisp_Object subr_l = Vcomp_subr_list;
- ptrdiff_t i = ARRAYELTS (helper_link_table);
+ ptrdiff_t i = countof (helper_link_table);
FOR_EACH_TAIL (subr_l)
{
Lisp_Object subr = XCAR (subr_l);
diff --git a/src/data.c b/src/data.c
index 92926eca89a..bbc4b34c6b8 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1943,7 +1943,7 @@ notify_variable_watchers (Lisp_Object symbol,
if (SUBRP (watcher))
{
Lisp_Object args[] = { symbol, newval, operation, where };
- funcall_subr (XSUBR (watcher), ARRAYELTS (args), args);
+ funcall_subr (XSUBR (watcher), countof (args), args);
}
else
calln (watcher, symbol, newval, operation, where);
diff --git a/src/doc.c b/src/doc.c
index 069c0294914..99d1ab292f0 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -546,7 +546,7 @@ the same file name is found in the `doc-directory'. */)
{
#include "buildobj.h"
};
- int i = ARRAYELTS (buildobj);
+ int i = countof (buildobj);
while (0 <= --i)
Vbuild_files = Fcons (build_string (buildobj[i]), Vbuild_files);
}
diff --git a/src/dosfns.c b/src/dosfns.c
index 07d553b0d78..189eaec408b 100644
--- a/src/dosfns.c
+++ b/src/dosfns.c
@@ -395,7 +395,7 @@ msdos_stdcolor_idx (const char *name)
{
int i;
- for (i = 0; i < ARRAYELTS (vga_colors); i++)
+ for (i = 0; i < countof (vga_colors); i++)
if (xstrcasecmp (name, vga_colors[i]) == 0)
return i;
@@ -413,7 +413,7 @@ msdos_stdcolor_name (int idx)
return build_string (unspecified_fg);
else if (idx == FACE_TTY_DEFAULT_BG_COLOR)
return build_string (unspecified_bg);
- else if (idx >= 0 && idx < ARRAYELTS (vga_colors))
+ else if (idx >= 0 && idx < countof (vga_colors))
return build_string (vga_colors[idx]);
else
return Qunspecified; /* meaning the default */
diff --git a/src/editfns.c b/src/editfns.c
index 4089edb1074..84f1e5cef03 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2450,7 +2450,7 @@ check_translation (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t end,
{
int initial_buf[16];
int *buf = initial_buf;
- ptrdiff_t buf_size = ARRAYELTS (initial_buf);
+ ptrdiff_t buf_size = countof (initial_buf);
int *bufalloc = 0;
ptrdiff_t buf_used = 0;
Lisp_Object result = Qnil;
diff --git a/src/emacs.c b/src/emacs.c
index 0827101da2f..3a9c7458e49 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1718,7 +1718,7 @@ android_emacs_init (int argc, char **argv, char *dump_file)
{
int i;
printf ("Usage: %s [OPTION-OR-FILENAME]...\n", argv[0]);
- for (i = 0; i < ARRAYELTS (usage_message); i++)
+ for (i = 0; i < countof (usage_message); i++)
fputs (usage_message[i], stdout);
exit (0);
}
@@ -2836,7 +2836,7 @@ sort_args (int argc, char **argv)
}
/* Look for a match with a known old-fashioned option. */
- for (i = 0; i < ARRAYELTS (standard_args); i++)
+ for (i = 0; i < countof (standard_args); i++)
if (!strcmp (argv[from], standard_args[i].name))
{
options[from] = standard_args[i].nargs;
@@ -2858,7 +2858,7 @@ sort_args (int argc, char **argv)
match = -1;
- for (i = 0; i < ARRAYELTS (standard_args); i++)
+ for (i = 0; i < countof (standard_args); i++)
if (standard_args[i].longname
&& !strncmp (argv[from], standard_args[i].longname,
thislen))
diff --git a/src/eval.c b/src/eval.c
index 1fdc6653cfc..699dcde2e0b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3245,7 +3245,7 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args)
Lisp_Object *a;
if (numargs < maxargs)
{
- eassume (maxargs <= ARRAYELTS (argbuf));
+ eassume (maxargs <= countof (argbuf));
a = argbuf;
memcpy (a, args, numargs * word_size);
memclear (a + numargs, (maxargs - numargs) * word_size);
diff --git a/src/fileio.c b/src/fileio.c
index 28adb6dd5f9..0b11b7bdf65 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1962,7 +1962,7 @@ get_homedir (void)
{
static char const *userenv[] = {"LOGNAME", "USER"};
struct passwd *pw = NULL;
- for (int i = 0; i < ARRAYELTS (userenv); i++)
+ for (int i = 0; i < countof (userenv); i++)
{
char *user = egetenv (userenv[i]);
if (user)
diff --git a/src/fns.c b/src/fns.c
index 687f0303aae..d692a92580a 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -4759,7 +4759,7 @@ cmpfn_user_defined (Lisp_Object key1, Lisp_Object key2,
struct Lisp_Hash_Table *h)
{
Lisp_Object args[] = { h->test->user_cmp_function, key1, key2 };
- return hash_table_user_defined_call (ARRAYELTS (args), args, h);
+ return hash_table_user_defined_call (countof (args), args, h);
}
static EMACS_INT
@@ -4805,7 +4805,7 @@ static hash_hash_t
hashfn_user_defined (Lisp_Object key, struct Lisp_Hash_Table *h)
{
Lisp_Object args[] = { h->test->user_hash_function, key };
- Lisp_Object hash = hash_table_user_defined_call (ARRAYELTS (args), args, h);
+ Lisp_Object hash = hash_table_user_defined_call (countof (args), args, h);
return reduce_emacs_uint_to_hash_hash (FIXNUMP (hash)
? XUFIXNUM(hash) : sxhash (hash));
}
diff --git a/src/font.c b/src/font.c
index fed90084219..ad46fb1904d 100644
--- a/src/font.c
+++ b/src/font.c
@@ -734,7 +734,7 @@ get_font_prop_index (Lisp_Object key)
{
int i;
- for (i = 0; i < ARRAYELTS (font_property_table); i++)
+ for (i = 0; i < countof (font_property_table); i++)
if (EQ (key, builtin_lisp_symbol (font_property_table[i].key)))
return i;
return -1;
@@ -5700,7 +5700,7 @@ If the named font cannot be opened and loaded, return nil. */)
#endif
-#define BUILD_STYLE_TABLE(TBL) build_style_table (TBL, ARRAYELTS (TBL))
+#define BUILD_STYLE_TABLE(TBL) build_style_table (TBL, countof (TBL))
static Lisp_Object
build_style_table (const struct table_entry *entry, int nelement)
diff --git a/src/frame.c b/src/frame.c
index 489ecbc7187..d17af6198be 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -5081,7 +5081,7 @@ handle_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val,
Lisp_Object old_value)
{
Lisp_Object param_index = Fget (prop, Qx_frame_parameter);
- if (FIXNATP (param_index) && XFIXNAT (param_index) < ARRAYELTS (frame_parms))
+ if (FIXNATP (param_index) && XFIXNAT (param_index) < countof (frame_parms))
{
if (FRAME_RIF (f))
{
@@ -7384,10 +7384,10 @@ syms_of_frame (void)
DEFSYM (Qcloned_from, "cloned-from");
DEFSYM (Qundeleted, "undeleted");
- for (int i = 0; i < ARRAYELTS (frame_parms); i++)
+ for (int i = 0; i < countof (frame_parms); i++)
{
int sym = frame_parms[i].sym;
- eassert (sym >= 0 && sym < ARRAYELTS (lispsym));
+ eassert (sym >= 0 && sym < countof (lispsym));
Lisp_Object v = builtin_lisp_symbol (sym);
Fput (v, Qx_frame_parameter, make_fixnum (i));
}
diff --git a/src/fringe.c b/src/fringe.c
index 5187325f281..b390246576b 100644
--- a/src/fringe.c
+++ b/src/fringe.c
@@ -488,7 +488,7 @@ static struct fringe_bitmap standard_bitmaps[] =
#define NO_FRINGE_BITMAP 0
#define UNDEF_FRINGE_BITMAP 1
-#define MAX_STANDARD_FRINGE_BITMAPS ARRAYELTS (standard_bitmaps)
+#define MAX_STANDARD_FRINGE_BITMAPS countof (standard_bitmaps)
static struct fringe_bitmap **fringe_bitmaps;
static Lisp_Object *fringe_faces;
diff --git a/src/haiku.c b/src/haiku.c
index 68a1d238add..d8615562c93 100644
--- a/src/haiku.c
+++ b/src/haiku.c
@@ -133,7 +133,7 @@ struct load_sample
/* We maintain 1-sec samples for the last 16 minutes in a circular buffer. */
static struct load_sample samples[16*60];
static int first_idx = -1, last_idx = -1;
-static int max_idx = ARRAYELTS (samples);
+static int max_idx = countof (samples);
static unsigned num_of_processors = 0;
static int
diff --git a/src/haikufns.c b/src/haikufns.c
index 3568c1bc0bc..32813833874 100644
--- a/src/haikufns.c
+++ b/src/haikufns.c
@@ -85,7 +85,7 @@ get_geometry_from_preferences (struct haiku_display_info *dpyinfo,
};
int i;
- for (i = 0; i < ARRAYELTS (r); ++i)
+ for (i = 0; i < countof (r); ++i)
{
if (NILP (Fassq (r[i].tem, parms)))
{
@@ -2065,7 +2065,7 @@ haiku_free_custom_cursors (struct frame *f)
output = FRAME_OUTPUT_DATA (f);
dpyinfo = FRAME_DISPLAY_INFO (f);
- for (i = 0; i < ARRAYELTS (custom_cursors); ++i)
+ for (i = 0; i < countof (custom_cursors); ++i)
{
cursor = &custom_cursors[i];
frame_cursor = (Emacs_Cursor *) ((char *) output
@@ -2111,7 +2111,7 @@ haiku_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
values. */
haiku_free_custom_cursors (f);
- for (i = 0; i < ARRAYELTS (custom_cursors); ++i)
+ for (i = 0; i < countof (custom_cursors); ++i)
{
frame_cursor = (Emacs_Cursor *) ((char *) output
+ custom_cursors[i].output_offset);
diff --git a/src/image.c b/src/image.c
index 723443193c0..640e3736b08 100644
--- a/src/image.c
+++ b/src/image.c
@@ -4971,7 +4971,7 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
{
#ifdef USE_CAIRO
Emacs_Color fgbg[] = {{.pixel = fg}, {.pixel = bg}};
- FRAME_TERMINAL (f)->query_colors (f, fgbg, ARRAYELTS (fgbg));
+ FRAME_TERMINAL (f)->query_colors (f, fgbg, countof (fgbg));
fg = lookup_rgb_color (f, fgbg[0].red, fgbg[0].green, fgbg[0].blue);
bg = lookup_rgb_color (f, fgbg[1].red, fgbg[1].green, fgbg[1].blue);
img->pixmap
@@ -6298,7 +6298,7 @@ static const char xpm_color_key_strings[][4] = {"s", "m", "g4", "g", "c"};
static int
xpm_str_to_color_key (const char *s)
{
- for (int i = 0; i < ARRAYELTS (xpm_color_key_strings); i++)
+ for (int i = 0; i < countof (xpm_color_key_strings); i++)
if (strcmp (xpm_color_key_strings[i], s) == 0)
return i;
return -1;
@@ -7731,7 +7731,7 @@ pbm_load (struct frame *f, struct image *img)
#ifdef USE_CAIRO
{
Emacs_Color fgbg[] = {{.pixel = fg}, {.pixel = bg}};
- FRAME_TERMINAL (f)->query_colors (f, fgbg, ARRAYELTS (fgbg));
+ FRAME_TERMINAL (f)->query_colors (f, fgbg, countof (fgbg));
fg = lookup_rgb_color (f, fgbg[0].red, fgbg[0].green, fgbg[0].blue);
bg = lookup_rgb_color (f, fgbg[1].red, fgbg[1].green, fgbg[1].blue);
}
@@ -12992,7 +12992,7 @@ lookup_image_type (Lisp_Object type)
return &native_image_type;
#endif
- for (int i = 0; i < ARRAYELTS (image_types); i++)
+ for (int i = 0; i < countof (image_types); i++)
{
struct image_type const *r = &image_types[i];
if (EQ (type, builtin_lisp_symbol (r->type)))
diff --git a/src/keyboard.c b/src/keyboard.c
index 6f0b5fbb2ec..4cfb2de07f2 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6360,13 +6360,13 @@ make_lispy_event (struct input_event *event)
case NON_ASCII_KEYSTROKE_EVENT:
button_down_time = 0;
- for (i = 0; i < ARRAYELTS (lispy_accent_codes); i++)
+ for (i = 0; i < countof (lispy_accent_codes); i++)
if (event->code == lispy_accent_codes[i])
return modify_event_symbol (i,
event->modifiers,
Qfunction_key, Qnil,
lispy_accent_keys, &accent_key_syms,
- ARRAYELTS (lispy_accent_keys));
+ countof (lispy_accent_keys));
#if 0
#ifdef XK_kana_A
@@ -6375,7 +6375,7 @@ make_lispy_event (struct input_event *event)
event->modifiers & ~shift_modifier,
Qfunction_key, Qnil,
lispy_kana_keys, &func_key_syms,
- ARRAYELTS (lispy_kana_keys));
+ countof (lispy_kana_keys));
#endif /* XK_kana_A */
#endif /* 0 */
@@ -6386,18 +6386,18 @@ make_lispy_event (struct input_event *event)
event->modifiers,
Qfunction_key, Qnil,
iso_lispy_function_keys, &func_key_syms,
- ARRAYELTS (iso_lispy_function_keys));
+ countof (iso_lispy_function_keys));
#endif
if ((FUNCTION_KEY_OFFSET <= event->code
&& (event->code
- < FUNCTION_KEY_OFFSET + ARRAYELTS (lispy_function_keys)))
+ < FUNCTION_KEY_OFFSET + countof (lispy_function_keys)))
&& lispy_function_keys[event->code - FUNCTION_KEY_OFFSET])
return modify_event_symbol (event->code - FUNCTION_KEY_OFFSET,
event->modifiers,
Qfunction_key, Qnil,
lispy_function_keys, &func_key_syms,
- ARRAYELTS (lispy_function_keys));
+ countof (lispy_function_keys));
/* Handle system-specific or unknown keysyms.
We need to use an alist rather than a vector as the cache
@@ -6424,13 +6424,13 @@ make_lispy_event (struct input_event *event)
make_fixnum (event->modifiers));
case MULTIMEDIA_KEY_EVENT:
- if (event->code < ARRAYELTS (lispy_multimedia_keys)
+ if (event->code < countof (lispy_multimedia_keys)
&& event->code > 0 && lispy_multimedia_keys[event->code])
{
return modify_event_symbol (event->code, event->modifiers,
Qfunction_key, Qnil,
lispy_multimedia_keys, &func_key_syms,
- ARRAYELTS (lispy_multimedia_keys));
+ countof (lispy_multimedia_keys));
}
return Qnil;
#endif
@@ -7529,7 +7529,7 @@ static const char *const modifier_names[] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, "alt", "super", "hyper", "shift", "control", "meta"
};
-#define NUM_MOD_NAMES ARRAYELTS (modifier_names)
+#define NUM_MOD_NAMES countof (modifier_names)
static Lisp_Object modifier_symbols;
@@ -13607,7 +13607,7 @@ This is effective only in `noninteractive' sessions. */);
{
int i;
- for (i = 0; i < ARRAYELTS (head_table); i++)
+ for (i = 0; i < countof (head_table); i++)
{
const struct event_head *p = &head_table[i];
Lisp_Object var = builtin_lisp_symbol (p->var);
@@ -13626,12 +13626,12 @@ This is effective only in `noninteractive' sessions. */);
staticpro (&frame_relative_event_pos);
mouse_syms = make_nil_vector (5);
staticpro (&mouse_syms);
- wheel_syms = make_nil_vector (ARRAYELTS (lispy_wheel_names));
+ wheel_syms = make_nil_vector (countof (lispy_wheel_names));
staticpro (&wheel_syms);
{
int i;
- int len = ARRAYELTS (modifier_names);
+ int len = countof (modifier_names);
modifier_symbols = make_nil_vector (len);
for (i = 0; i < len; i++)
diff --git a/src/keymap.c b/src/keymap.c
index dc40d68089a..a42cec854dd 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2118,7 +2118,7 @@ For an approximate inverse of this, see `kbd'. */)
Lisp_Object lists[2] = { prefix, keys };
ptrdiff_t listlens[2] = { nprefix, nkeys };
- for (int li = 0; li < ARRAYELTS (lists); li++)
+ for (int li = 0; li < countof (lists); li++)
{
Lisp_Object list = lists[li];
ptrdiff_t listlen = listlens[li], i_byte = 0;
diff --git a/src/lisp.h b/src/lisp.h
index dd780e90c1d..764205dcf90 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -25,6 +25,7 @@ along with GNU Emacs. If not, see . */
#include
#include
#include
+#include
#include
#include
#include
@@ -70,9 +71,6 @@ INLINE_HEADER_BEGIN
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
-/* Number of elements in an array. */
-#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
-
/* Number of bits in a Lisp_Object tag. */
DEFINE_GDB_SYMBOL_BEGIN (int, GCTYPEBITS)
#define GCTYPEBITS 3
@@ -3452,7 +3450,7 @@ enum maxargs
};
/* Call a function F that accepts many args, passing it ARRAY's elements. */
-#define CALLMANY(f, array) (f) (ARRAYELTS (array), array)
+#define CALLMANY(f, array) (f) (countof (array), array)
/* Call a function F that accepts many args, passing it the remaining args,
E.g., 'return CALLN (Fformat, fmt, text);' is less error-prone than
@@ -4493,7 +4491,7 @@ extern Lisp_Object list5 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object,
Lisp_Object);
extern Lisp_Object listn (ptrdiff_t, Lisp_Object, ...);
#define list(...) \
- listn (ARRAYELTS (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
+ listn (countof (((Lisp_Object []) {__VA_ARGS__})), __VA_ARGS__)
enum gc_root_type
{
diff --git a/src/lread.c b/src/lread.c
index 00f85114ac7..b079e83dd06 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1539,7 +1539,7 @@ Return t if the file exists and loads successfully. */)
if (!NILP (Ffboundp (Qdo_after_load_evaluation)))
calln (Qdo_after_load_evaluation, hist_file_name);
- for (int i = 0; i < ARRAYELTS (saved_strings); i++)
+ for (int i = 0; i < countof (saved_strings); i++)
{
xfree (saved_strings[i].string);
saved_strings[i].string = NULL;
@@ -3449,7 +3449,7 @@ skip_lazy_string (source_t *source)
and record where in the file it comes from. */
/* First exchange the two saved_strings. */
- static_assert (ARRAYELTS (saved_strings) == 2);
+ static_assert (countof (saved_strings) == 2);
struct saved_string t = saved_strings[0];
saved_strings[0] = saved_strings[1];
saved_strings[1] = t;
@@ -3507,7 +3507,7 @@ get_lazy_string (Lisp_Object val)
compatibility. */
EMACS_INT pos = eabs (XFIXNUM (XCDR (val)));
struct saved_string *ss = &saved_strings[0];
- struct saved_string *ssend = ss + ARRAYELTS (saved_strings);
+ struct saved_string *ssend = ss + countof (saved_strings);
while (ss < ssend
&& !(pos >= ss->position && pos < ss->position + ss->length))
ss++;
@@ -5199,7 +5199,7 @@ init_obarray_once (void)
initial_obarray = Vobarray;
staticpro (&initial_obarray);
- for (int i = 0; i < ARRAYELTS (lispsym); i++)
+ for (int i = 0; i < countof (lispsym); i++)
define_symbol (builtin_lisp_symbol (i), defsym_name[i]);
DEFSYM (Qunbound, "unbound");
diff --git a/src/macfont.m b/src/macfont.m
index 1916e5c0287..3cd3b79a346 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -224,7 +224,7 @@ static void mac_font_get_glyphs_for_variants (CFDataRef, UTF32Char,
unichar characters[] = {0xfffd};
NSString *string =
[NSString stringWithCharacters:characters
- length:ARRAYELTS (characters)];
+ length:countof (characters)];
NSGlyphInfo *glyphInfo =
[NSGlyphInfo glyphInfoWithCharacterIdentifier:cid
collection:collection
@@ -893,7 +893,7 @@ static void mac_font_get_glyphs_for_variants (CFDataRef, UTF32Char,
};
int i;
- for (i = 0; i < ARRAYELTS (numeric_traits); i++)
+ for (i = 0; i < countof (numeric_traits); i++)
{
num = CFDictionaryGetValue (dict, numeric_traits[i].trait);
if (num && CFNumberGetValue (num, kCFNumberCGFloatType, &floatval))
@@ -2119,7 +2119,7 @@ static int macfont_variation_glyphs (struct font *, int c,
if (! traits)
goto err;
- for (i = 0; i < ARRAYELTS (numeric_traits); i++)
+ for (i = 0; i < countof (numeric_traits); i++)
{
tmp = AREF (spec, numeric_traits[i].index);
if (FIXNUMP (tmp))
@@ -3788,7 +3788,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
{
attributes = CFDictionaryCreate (NULL, (const void **) keys,
(const void **) values,
- ARRAYELTS (keys),
+ countof (keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease (values[1]);
@@ -4002,7 +4002,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CTLineRef ctline = NULL;
string = CFStringCreateWithCharacters (NULL, characters,
- ARRAYELTS (characters));
+ countof (characters));
if (string)
{
@@ -4018,7 +4018,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
attributes = CFDictionaryCreate (NULL, (const void **) keys,
(const void **) values,
- ARRAYELTS (keys),
+ countof (keys),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFRelease (glyph_info);
diff --git a/src/msdos.c b/src/msdos.c
index 4d111b30969..ddfb0451395 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -581,7 +581,7 @@ dos_set_window_size (int *rows, int *cols)
};
int i = 0;
- while (i < ARRAYELTS (std_dimension))
+ while (i < countof (std_dimension))
{
if (std_dimension[i].need_vga <= have_vga
&& std_dimension[i].rows >= *rows)
@@ -2068,7 +2068,7 @@ dos_set_keyboard (int code, int always)
keyboard_map_all = always;
dos_keyboard_layout = 1;
- for (i = 0; i < ARRAYELTS (keyboard_layout_list); i++)
+ for (i = 0; i < countof (keyboard_layout_list); i++)
if (code == keyboard_layout_list[i].country_code)
{
keyboard = keyboard_layout_list[i].keyboard_map;
@@ -2511,7 +2511,7 @@ dos_rawgetc (void)
one. */
if (code == -1)
{
- if (sc >= ARRAYELTS (ibmpc_translate_map))
+ if (sc >= countof (ibmpc_translate_map))
continue;
if ((code = ibmpc_translate_map[sc]) == Ignore)
continue;
@@ -3479,7 +3479,7 @@ init_environment (int argc, char **argv, int skip_args)
static const char * const tempdirs[] = {
"$TMPDIR", "$TEMP", "$TMP", "c:/"
};
- const int imax = ARRAYELTS (tempdirs);
+ const int imax = countof (tempdirs);
/* Make sure they have a usable $TMPDIR. Many Emacs functions use
temporary files and assume "/tmp" if $TMPDIR is unset, which
diff --git a/src/nsfns.m b/src/nsfns.m
index 045d167e6b4..3ee6315d963 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -1168,7 +1168,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
};
int i;
- for (i = 0; i < ARRAYELTS (r); ++i)
+ for (i = 0; i < countof (r); ++i)
{
if (NILP (Fassq (r[i].tem, parms)))
{
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 2b785a8dab8..ab6e7d7140d 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -630,7 +630,7 @@ -(void)removeAllItems
int len = strlen (key);
char *buf = xmalloc (len + 1);
memcpy (buf, key, len + 1);
- for (int i = 0; i < ARRAYELTS (key_symbols); i++)
+ for (int i = 0; i < countof (key_symbols); i++)
{
ptrdiff_t fromlen = strlen (key_symbols[i].from);
char *p = buf;
diff --git a/src/nsterm.m b/src/nsterm.m
index 2507053f3a1..20097454444 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2645,7 +2645,7 @@ Hide the window (X11 semantics)
Internal call used by NSView-keyDown.
-------------------------------------------------------------------------- */
{
- const unsigned last_keysym = ARRAYELTS (convert_ns_to_X_keysym);
+ const unsigned last_keysym = countof (convert_ns_to_X_keysym);
unsigned keysym;
/* An array would be faster, but less easy to read. */
for (keysym = 0; keysym < last_keysym; keysym += 2)
diff --git a/src/pdumper.c b/src/pdumper.c
index 066058d2078..039768b022b 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -4387,7 +4387,7 @@ DEFUN ("dump-emacs-portable--sort-predicate-copied",
void
pdumper_do_now_and_after_load_impl (pdumper_hook hook)
{
- if (nr_dump_hooks == ARRAYELTS (dump_hooks))
+ if (nr_dump_hooks == countof (dump_hooks))
fatal ("out of dump hooks: make dump_hooks[] bigger");
dump_hooks[nr_dump_hooks++] = hook;
hook ();
@@ -4396,7 +4396,7 @@ pdumper_do_now_and_after_load_impl (pdumper_hook hook)
void
pdumper_do_now_and_after_late_load_impl (pdumper_hook hook)
{
- if (nr_dump_late_hooks == ARRAYELTS (dump_late_hooks))
+ if (nr_dump_late_hooks == countof (dump_late_hooks))
fatal ("out of dump hooks: make dump_late_hooks[] bigger");
dump_late_hooks[nr_dump_late_hooks++] = hook;
hook ();
@@ -4405,7 +4405,7 @@ pdumper_do_now_and_after_late_load_impl (pdumper_hook hook)
static void
pdumper_remember_user_data_1 (void *mem, int nbytes)
{
- if (nr_remembered_data == ARRAYELTS (remembered_data))
+ if (nr_remembered_data == countof (remembered_data))
fatal ("out of remembered data slots: make remembered_data[] bigger");
remembered_data[nr_remembered_data].mem = mem;
remembered_data[nr_remembered_data].sz = nbytes;
@@ -5731,7 +5731,7 @@ pdumper_load (const char *dump_filename, char *argv0)
.protection = DUMP_MEMORY_ACCESS_READWRITE,
};
- if (!dump_mmap_contiguous (sections, ARRAYELTS (sections)))
+ if (!dump_mmap_contiguous (sections, countof (sections)))
goto out;
err = PDUMPER_LOAD_ERROR;
@@ -5768,7 +5768,7 @@ pdumper_load (const char *dump_filename, char *argv0)
dump_do_all_emacs_relocations (header, dump_base);
dump_mmap_discard_contents (§ions[DS_DISCARDABLE]);
- for (int i = 0; i < ARRAYELTS (sections); ++i)
+ for (int i = 0; i < countof (sections); ++i)
dump_mmap_reset (§ions[i]);
Lisp_Object hashes = zero_vector;
@@ -5807,7 +5807,7 @@ pdumper_load (const char *dump_filename, char *argv0)
dump_private.dump_filename = dump_filename_copy;
out:
- for (int i = 0; i < ARRAYELTS (sections); ++i)
+ for (int i = 0; i < countof (sections); ++i)
dump_mmap_release (§ions[i]);
if (dump_fd >= 0)
emacs_close (dump_fd);
diff --git a/src/profiler.c b/src/profiler.c
index c9cc3f118ad..fefc717d270 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -429,7 +429,7 @@ setup_cpu_timer (Lisp_Object sampling_interval)
sigev.sigev_signo = SIGPROF;
sigev.sigev_notify = SIGEV_SIGNAL;
- for (int i = 0; i < ARRAYELTS (system_clock); i++)
+ for (int i = 0; i < countof (system_clock); i++)
if (timer_create (system_clock[i], &sigev, &profiler_timer) == 0)
{
profiler_timer_ok = true;
diff --git a/src/sfnt.c b/src/sfnt.c
index 956b89d3efb..d436421c79b 100644
--- a/src/sfnt.c
+++ b/src/sfnt.c
@@ -28,6 +28,7 @@ along with GNU Emacs. If not, see . */
#include
#include
#include
+#include
#include
#include
#include
@@ -127,8 +128,6 @@ xfree (void *ptr)
#define TEST_STATIC static
/* Needed for tests. */
-#define ARRAYELTS(arr) (sizeof (arr) / sizeof (arr)[0])
-
#define eassert(expr) assert (expr)
/* Also necessary. */
@@ -18062,9 +18061,9 @@ static uint32_t sfnt_sround_values[] =
static struct sfnt_generic_test_args sround_test_args =
{
sfnt_sround_values,
- ARRAYELTS (sfnt_sround_values),
+ countof (sfnt_sround_values),
false,
- ARRAYELTS (sfnt_sround_instructions),
+ countof (sfnt_sround_instructions),
};
static unsigned char sfnt_s45round_instructions[] =
@@ -18084,9 +18083,9 @@ static uint32_t sfnt_s45round_values[] =
static struct sfnt_generic_test_args s45round_test_args =
{
sfnt_s45round_values,
- ARRAYELTS (sfnt_s45round_values),
+ countof (sfnt_s45round_values),
false,
- ARRAYELTS (sfnt_s45round_instructions),
+ countof (sfnt_s45round_instructions),
};
static struct sfnt_generic_test_args rutg_test_args =
@@ -19468,14 +19467,14 @@ static struct sfnt_interpreter_test all_tests[] =
{
"SROUND",
sfnt_sround_instructions,
- ARRAYELTS (sfnt_sround_instructions),
+ countof (sfnt_sround_instructions),
&sround_test_args,
sfnt_generic_check,
},
{
"S45ROUND",
sfnt_s45round_instructions,
- ARRAYELTS (sfnt_s45round_instructions),
+ countof (sfnt_s45round_instructions),
&s45round_test_args,
sfnt_generic_check,
},
@@ -20369,7 +20368,7 @@ main (int argc, char **argv)
interpreter->pop_hook = sfnt_pop_hook;
}
- for (i = 0; i < ARRAYELTS (all_tests); ++i)
+ for (i = 0; i < countof (all_tests); ++i)
sfnt_run_interpreter_test (&all_tests[i], interpreter);
exit (0);
diff --git a/src/sfntfont-android.c b/src/sfntfont-android.c
index 55f9c9e9078..7a2e4cb3f8f 100644
--- a/src/sfntfont-android.c
+++ b/src/sfntfont-android.c
@@ -701,7 +701,7 @@ loaded before character sets are made available. */)
/* Scan through each of the system font directories. Enumerate each
font that looks like a TrueType font. */
- for (i = 0; i < ARRAYELTS (system_font_directories); ++i)
+ for (i = 0; i < countof (system_font_directories); ++i)
{
dir = opendir (system_font_directories[i]);
diff --git a/src/sfntfont.c b/src/sfntfont.c
index 858c5449ac7..39a3afadfb0 100644
--- a/src/sfntfont.c
+++ b/src/sfntfont.c
@@ -486,7 +486,7 @@ sfnt_parse_style (Lisp_Object style_name, struct sfnt_font_desc *desc)
{
/* Weight hasn't been found yet. Scan through the weight
table. */
- for (i = 0; i < ARRAYELTS (sfnt_weight_descriptions); ++i)
+ for (i = 0; i < countof (sfnt_weight_descriptions); ++i)
{
if (!strcmp (sfnt_weight_descriptions[i].c_string,
single))
@@ -503,7 +503,7 @@ sfnt_parse_style (Lisp_Object style_name, struct sfnt_font_desc *desc)
{
/* Slant hasn't been found yet. Scan through the slant
table. */
- for (i = 0; i < ARRAYELTS (sfnt_slant_descriptions); ++i)
+ for (i = 0; i < countof (sfnt_slant_descriptions); ++i)
{
if (!strcmp (sfnt_slant_descriptions[i].c_string,
single))
@@ -520,7 +520,7 @@ sfnt_parse_style (Lisp_Object style_name, struct sfnt_font_desc *desc)
{
/* Width hasn't been found yet. Scan through the width
table. */
- for (i = 0; i < ARRAYELTS (sfnt_width_descriptions); ++i)
+ for (i = 0; i < countof (sfnt_width_descriptions); ++i)
{
if (!strcmp (sfnt_width_descriptions[i].c_string,
single))
@@ -1998,7 +1998,7 @@ sfntfont_list (struct frame *f, Lisp_Object font_spec)
for (desc = system_fonts; desc; desc = desc->next)
{
rc = sfntfont_list_1 (desc, font_spec, instances,
- ARRAYELTS (instances));
+ countof (instances));
if (rc < 0)
matching = Fcons (sfntfont_desc_to_entity (desc, 0),
diff --git a/src/sound.c b/src/sound.c
index 5c2dfa08e21..fc68f98457e 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -1312,7 +1312,7 @@ do_play_sound (const char *psz_file_or_data, unsigned long ui_volume, bool in_me
wcscat (sz_cmd_buf_w, fname_w);
wcscat (sz_cmd_buf_w, L"\" alias GNUEmacs_PlaySound_Device wait");
mci_error = mciSendStringW (sz_cmd_buf_w,
- sz_ret_buf_w, ARRAYELTS (sz_ret_buf_w) , NULL);
+ sz_ret_buf_w, countof (sz_ret_buf_w) , NULL);
}
if (mci_error != 0)
{
diff --git a/src/sysdep.c b/src/sysdep.c
index 2f48b7c6681..069e052d3ab 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -430,7 +430,7 @@ init_baud_rate (int fd)
#endif /* not DOS_NT */
}
- baud_rate = (emacs_ospeed < ARRAYELTS (baud_convert)
+ baud_rate = (emacs_ospeed < countof (baud_convert)
? baud_convert[emacs_ospeed] : 9600);
if (baud_rate == 0)
baud_rate = 1200;
@@ -3136,7 +3136,7 @@ static const struct speed_struct speeds[] =
static speed_t
convert_speed (speed_t speed)
{
- for (ptrdiff_t i = 0; i < ARRAYELTS (speeds); i++)
+ for (ptrdiff_t i = 0; i < countof (speeds); i++)
{
if (speed == speeds[i].internal)
return speed;
@@ -3356,7 +3356,7 @@ list_system_processes (void)
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PROC};
#endif
size_t len;
- size_t mibsize = ARRAYELTS (mib);
+ size_t mibsize = countof (mib);
struct kinfo_proc *procs;
size_t i;
diff --git a/src/term.c b/src/term.c
index cd8c9717640..2261293a60b 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1427,7 +1427,7 @@ term_get_fkeys_1 (void)
if (!KEYMAPP (KVAR (kboard, Vinput_decode_map)))
kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil));
- for (i = 0; i < ARRAYELTS (keys); i++)
+ for (i = 0; i < countof (keys); i++)
{
char *sequence = tgetstr (keys[i].cap, address);
if (sequence)
diff --git a/src/w32.c b/src/w32.c
index 409d4238bc9..4be30fc5ec4 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1957,7 +1957,7 @@ static unsigned num_of_processors;
/* We maintain 1-sec samples for the last 16 minutes in a circular buffer. */
static struct load_sample samples[16*60];
static int first_idx = -1, last_idx = -1;
-static int max_idx = ARRAYELTS (samples);
+static int max_idx = countof (samples);
static int
buf_next (int from)
@@ -2870,7 +2870,7 @@ init_environment (char ** argv)
int i;
- const int imax = ARRAYELTS (tempdirs);
+ const int imax = countof (tempdirs);
/* Implementation note: This function explicitly works with ANSI
file names, not with UTF-8 encoded file names. This is because
@@ -2943,7 +2943,7 @@ init_environment (char ** argv)
{"LANG", NULL},
};
-#define N_ENV_VARS ARRAYELTS (dflt_envvars)
+#define N_ENV_VARS countof (dflt_envvars)
/* We need to copy dflt_envvars[] and work on the copy because we
don't want the dumped Emacs to inherit the values of
diff --git a/src/w32console.c b/src/w32console.c
index ea62d59a787..30a1f65f43f 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -215,7 +215,7 @@ w32con_clear_frame (struct frame *f)
static struct glyph glyph_base[80];
static struct glyph *glyphs = glyph_base;
-static size_t glyphs_len = ARRAYELTS (glyph_base);
+static size_t glyphs_len = countof (glyph_base);
static BOOL ceol_initialized = FALSE;
/* Clear from Cursor to end (what's "standout marker"?). */
diff --git a/src/w32fns.c b/src/w32fns.c
index 1749f2ba390..726fe52affc 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -838,7 +838,7 @@ w32_default_color_map (void)
cmap = Qnil;
- for (i = 0; i < ARRAYELTS (w32_color_map); pc++, i++)
+ for (i = 0; i < countof (w32_color_map); pc++, i++)
cmap = Fcons (Fcons (build_string (pc->name),
make_fixnum (pc->colorref)),
cmap);
@@ -2834,7 +2834,7 @@ w32_createwindow (struct frame *f, int *coords)
}
/* Reset F's touch point array. */
- for (i = 0; i < ARRAYELTS (f->output_data.w32->touch_ids); ++i)
+ for (i = 0; i < countof (f->output_data.w32->touch_ids); ++i)
f->output_data.w32->touch_ids[i] = -1;
/* Assign an offset for touch points reported to F. */
@@ -4173,7 +4173,7 @@ deliver_wm_chars (int do_translate, HWND hwnd, UINT msg, UINT wParam,
windows_msg.time = GetMessageTime ();
TranslateMessage (&windows_msg);
}
- count = get_wm_chars (hwnd, buf, ARRAYELTS (buf), 1,
+ count = get_wm_chars (hwnd, buf, countof (buf), 1,
/* The message may have been synthesized by
who knows what; be conservative. */
modifier_set (VK_LCONTROL)
@@ -8413,7 +8413,7 @@ DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
file_details_w->lStructSize = sizeof (*file_details_w);
/* Set up the inout parameter for the selected file name. */
file_details_w->lpstrFile = filename_buf_w;
- file_details_w->nMaxFile = ARRAYELTS (filename_buf_w);
+ file_details_w->nMaxFile = countof (filename_buf_w);
file_details_w->hwndOwner = FRAME_W32_WINDOW (f);
/* Undocumented Bug in Common File Dialog:
If a filter is not specified, shell links are not resolved. */
@@ -8446,7 +8446,7 @@ DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
else
file_details_a->lStructSize = sizeof (*file_details_a);
file_details_a->lpstrFile = filename_buf_a;
- file_details_a->nMaxFile = ARRAYELTS (filename_buf_a);
+ file_details_a->nMaxFile = countof (filename_buf_a);
file_details_a->hwndOwner = FRAME_W32_WINDOW (f);
file_details_a->lpstrFilter = filter_a;
file_details_a->lpstrInitialDir = dir_a;
diff --git a/src/w32proc.c b/src/w32proc.c
index b89979c7314..52d7ef9b5a7 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -4220,7 +4220,7 @@ nl_langinfo (nl_item item)
{ 210, 297 }
};
int idx = atoi (nl_langinfo_buf);
- if (0 <= idx && idx < ARRAYELTS (paper_size))
+ if (0 <= idx && idx < countof (paper_size))
retval = (char *)(intptr_t) (item == _NL_PAPER_WIDTH
? paper_size[idx][0]
: paper_size[idx][1]);
diff --git a/src/w32term.c b/src/w32term.c
index ccf5d14cb10..728f6ce856d 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -276,7 +276,7 @@ int event_record_index;
record_event (char *locus, int type)
{
- if (event_record_index == ARRAYELTS (event_record))
+ if (event_record_index == countof (event_record))
event_record_index = 0;
event_record[event_record_index].locus = locus;
@@ -5259,7 +5259,7 @@ w32_read_socket (struct terminal *terminal,
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == ARRAYELTS (temp_buffer))
+ if (temp_index == countof (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
inev.kind = NON_ASCII_KEYSTROKE_EVENT;
@@ -5285,7 +5285,7 @@ w32_read_socket (struct terminal *terminal,
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == ARRAYELTS (temp_buffer))
+ if (temp_index == countof (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
@@ -5400,7 +5400,7 @@ w32_read_socket (struct terminal *terminal,
hlinfo->mouse_face_hidden = true;
}
- if (temp_index == ARRAYELTS (temp_buffer))
+ if (temp_index == countof (temp_buffer))
temp_index = 0;
temp_buffer[temp_index++] = msg.msg.wParam;
inev.kind = MULTIMEDIA_KEY_EVENT;
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c
index 2266dadcac5..6f468423bb2 100644
--- a/src/w32uniscribe.c
+++ b/src/w32uniscribe.c
@@ -882,7 +882,7 @@ uniscribe_check_otf_1 (HDC context, Lisp_Object script, Lisp_Object lang,
{
SCRIPT_CACHE cache = NULL;
OPENTYPE_TAG tags[128], script_tag, lang_tag;
- int max_tags = ARRAYELTS (tags);
+ int max_tags = countof (tags);
int ntags, i, ret = 0;
HRESULT rslt;
diff --git a/src/xdisp.c b/src/xdisp.c
index 2b4af7d877e..1691bd0d80e 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3145,7 +3145,7 @@ funcall_with_backtraces (ptrdiff_t nargs, Lisp_Object *args)
}
#define SAFE_CALLMANY(inhibit_quit, f, array) \
- dsafe__call (inhibit_quit, f, ARRAYELTS (array), array)
+ dsafe__call (inhibit_quit, f, countof (array), array)
#define dsafe_calln(inhibit_quit, ...) \
SAFE_CALLMANY (inhibit_quit, \
backtrace_on_redisplay_error \
@@ -7093,7 +7093,7 @@ load_overlay_strings (struct it *it, ptrdiff_t charpos)
{
ptrdiff_t n = 0;
struct overlay_entry entriesbuf[20];
- ptrdiff_t size = ARRAYELTS (entriesbuf);
+ ptrdiff_t size = countof (entriesbuf);
struct overlay_entry *entries = entriesbuf;
struct itree_node *node;
@@ -12248,7 +12248,7 @@ vadd_to_log (char const *format, va_list ap)
ptrdiff_t form_nargs = format_nargs (format);
ptrdiff_t nargs = 1 + form_nargs;
Lisp_Object args[10];
- eassert (nargs <= ARRAYELTS (args));
+ eassert (nargs <= countof (args));
AUTO_STRING (args0, format);
args[0] = args0;
for (ptrdiff_t i = 1; i < nargs; i++)
diff --git a/src/xfaces.c b/src/xfaces.c
index 010b0e1847e..73d475c757f 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -458,7 +458,7 @@ DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0,
putc ('\n', stderr);
- for (i = n = 0; i < ARRAYELTS (color_count); ++i)
+ for (i = n = 0; i < countof (color_count); ++i)
if (color_count[i])
{
fprintf (stderr, "%3d: %5d", i, color_count[i]);
@@ -5807,14 +5807,14 @@ Value is ORDER. */)
{
Lisp_Object list;
int i;
- int indices[ARRAYELTS (font_sort_order)];
+ int indices[countof (font_sort_order)];
CHECK_LIST (order);
memset (indices, 0, sizeof indices);
i = 0;
for (list = order;
- CONSP (list) && i < ARRAYELTS (indices);
+ CONSP (list) && i < countof (indices);
list = XCDR (list), ++i)
{
Lisp_Object attr = XCAR (list);
@@ -5836,9 +5836,9 @@ Value is ORDER. */)
indices[i] = xlfd;
}
- if (!NILP (list) || i != ARRAYELTS (indices))
+ if (!NILP (list) || i != countof (indices))
signal_error ("Invalid font sort order", order);
- for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
+ for (i = 0; i < countof (font_sort_order); ++i)
if (indices[i] == 0)
signal_error ("Invalid font sort order", order);
@@ -7340,7 +7340,7 @@ DEFUN ("dump-face", Fdump_face, Sdump_face, 0, 1, 0, doc: /* */)
int i;
fputs ("font selection order: ", stderr);
- for (i = 0; i < ARRAYELTS (font_sort_order); ++i)
+ for (i = 0; i < countof (font_sort_order); ++i)
fprintf (stderr, "%d ", font_sort_order[i]);
putc ('\n', stderr);
diff --git a/src/xfns.c b/src/xfns.c
index 2a1d3f5860e..0750a444e81 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3070,7 +3070,7 @@ best_xim_style (struct x_display_info *dpyinfo,
XIMStyles *xim)
{
int i, j;
- int nr_supported = ARRAYELTS (supported_xim_styles);
+ int nr_supported = countof (supported_xim_styles);
if (dpyinfo->preferred_xim_style)
return dpyinfo->preferred_xim_style;
diff --git a/src/xgselect.c b/src/xgselect.c
index 97f2c3391d9..0d2de12654f 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -112,7 +112,7 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
bool have_wfds = wfds != NULL;
GPollFD gfds_buf[128];
GPollFD *gfds = gfds_buf;
- int gfds_size = ARRAYELTS (gfds_buf);
+ int gfds_size = countof (gfds_buf);
int n_gfds, retval = 0, our_fds = 0, max_fds = fds_lim - 1;
int i, nfds, tmo_in_millisec, must_free = 0;
bool need_to_dispatch;
diff --git a/src/xterm.c b/src/xterm.c
index 358e01c776a..ddbf8e06664 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -5142,7 +5142,7 @@ int event_record_index;
void
record_event (char *locus, int type)
{
- if (event_record_index == ARRAYELTS (event_record))
+ if (event_record_index == countof (event_record))
event_record_index = 0;
event_record[event_record_index].locus = locus;
@@ -17807,7 +17807,7 @@ static int temp_index;
static short temp_buffer[100];
#define STORE_KEYSYM_FOR_DEBUG(keysym) \
- if (temp_index == ARRAYELTS (temp_buffer)) \
+ if (temp_index == countof (temp_buffer)) \
temp_index = 0; \
temp_buffer[temp_index++] = (keysym)
@@ -29921,7 +29921,7 @@ x_intern_cached_atom (struct x_display_info *dpyinfo,
&& !strcmp (name, dpyinfo->motif_drag_atom_name))
return dpyinfo->motif_drag_atom;
- for (i = 0; i < ARRAYELTS (x_atom_refs); ++i)
+ for (i = 0; i < countof (x_atom_refs); ++i)
{
ptr = (char *) dpyinfo;
@@ -30009,7 +30009,7 @@ x_get_atom_name (struct x_display_info *dpyinfo, Atom atom,
return xstrdup (buffer);
}
- for (i = 0; i < ARRAYELTS (x_atom_refs); ++i)
+ for (i = 0; i < countof (x_atom_refs); ++i)
{
ref_atom = *(Atom *) (dpyinfo_pointer
+ x_atom_refs[i].offset);
@@ -31515,7 +31515,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
XScreenNumberOfScreen (dpyinfo->screen));
{
- enum { atom_count = ARRAYELTS (x_atom_refs) };
+ enum { atom_count = countof (x_atom_refs) };
/* 1 for _XSETTINGS_SN. */
enum { total_atom_count = 2 + atom_count };
Atom atoms_return[total_atom_count];