1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-19 05:13:34 -07:00

Use the nelems macro to compute the size of arrays.

Copied from Perforce
 Change: 187055
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Gareth Rees 2014-09-26 21:35:25 +01:00
parent 7f970f93ed
commit 716bb331b9
7 changed files with 14 additions and 16 deletions

View file

@ -222,7 +222,7 @@ static void test_pool(mps_pool_t pool, size_t roots_count, int mode)
cl.pool = pool;
cl.roots_count = roots_count;
for (i = 0; i < sizeof(kids)/sizeof(kids[0]); ++i)
for (i = 0; i < NELEMS(kids); ++i)
testthr_create(&kids[i], kid_thread, &cl);
die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate");
@ -306,7 +306,7 @@ static void test_pool(mps_pool_t pool, size_t roots_count, int mode)
mps_ap_destroy(busy_ap);
mps_ap_destroy(ap);
for (i = 0; i < sizeof(kids)/sizeof(kids[0]); ++i)
for (i = 0; i < NELEMS(kids); ++i)
testthr_join(&kids[i], NULL);
}

View file

@ -356,7 +356,7 @@ int main(int argc, char *argv[]) {
(void)fflush(stdout);
while (argc > 0) {
for (i = 0; i < sizeof(pools) / sizeof(pools[0]); ++i)
for (i = 0; i < NELEMS(pools); ++i)
if (strcmp(argv[0], pools[i].name) == 0)
goto found;
fprintf(stderr, "unknown pool test \"%s\"\n", argv[0]);

View file

@ -386,7 +386,7 @@ static void testTableExists(sqlite3 *db)
size_t i;
int defects = 0;
int tests = 0;
for (i=0; i < (sizeof(tableTests)/sizeof(tableTests[0])); ++i) {
for (i=0; i < NELEMS(tableTests); ++i) {
const char *name = tableTests[i].name;
int exists = tableExists(db, name);
if (exists)
@ -566,7 +566,7 @@ static void makeTables(sqlite3 *db)
size_t i;
evlog(LOG_SOMETIMES, "Creating tables.");
for (i=0; i < (sizeof(createStatements)/sizeof(createStatements[0])); ++i) {
for (i=0; i < NELEMS(createStatements); ++i) {
runStatement(db, createStatements[i], "Table creation");
}
}
@ -585,7 +585,7 @@ static void dropGlueTables(sqlite3 *db)
evlog(LOG_ALWAYS, "Dropping glue tables so they are rebuilt.");
for (i=0; i < (sizeof(glueTables)/sizeof(glueTables[0])); ++i) {
for (i=0; i < NELEMS(glueTables); ++i) {
evlog(LOG_SOMETIMES, "Dropping table %s", glueTables[i]);
sprintf(sql, "DROP TABLE %s", glueTables[i]);
res = sqlite3_exec(db,

View file

@ -449,7 +449,7 @@ int main(int argc, char *argv[]) {
(void)fflush(stdout);
while (argc > 0) {
for (i = 0; i < sizeof(pools) / sizeof(pools[0]); ++i)
for (i = 0; i < NELEMS(pools); ++i)
if (strcmp(argv[0], pools[i].name) == 0)
goto found;
fprintf(stderr, "unknown pool test \"%s\"\n", argv[0]);

View file

@ -102,8 +102,8 @@ typedef const struct SrcIdStruct {
* NELEMS(a) expands into an expression that is the number
* of elements in the array a.
*
* WARNING: expands a more than once (you'd have to write obviously
* perverse code for this to matter though).
* WARNING: expands a more than once (but only in the context of
* sizeof, so does not cause double evaluation).
*/
#define NELEMS(a) (sizeof(a)/sizeof((a)[0]))

View file

@ -56,8 +56,6 @@ static unsigned long step_frequencies[] = {
1000000000, /* one billion */
};
#define TESTS (sizeof(step_frequencies) / sizeof(step_frequencies[0]))
static unsigned test_number = 0;
@ -496,7 +494,7 @@ int main(int argc, char *argv[])
testlib_init(argc, argv);
while (test_number < TESTS) {
while (test_number < NELEMS(step_frequencies)) {
mps_arena_t arena;
mps_thr_t thread;
void *r;

View file

@ -325,9 +325,9 @@ void rnd_state_set_v2(unsigned long seed0_v2)
static struct {
const char *ident;
const char *doc;
} res_strings[] = {
#define RES_STRINGS_ROW(X, ident, doc) {#ident, #doc},
_mps_RES_ENUM(RES_STRINGS_ROW, X)
} const res_strings[] = {
#define RES_STRINGS_ROW(X, ident, doc) {#ident, doc},
_mps_RES_ENUM(RES_STRINGS_ROW, X)
};
@ -372,7 +372,7 @@ void error(const char *format, ...)
void die_expect(mps_res_t res, mps_res_t expected, const char *s)
{
if (res != expected) {
if (0 <= res && (unsigned)res < sizeof(res_strings) / sizeof(res_strings[0]))
if (0 <= res && (unsigned)res < NELEMS(res_strings))
error("\n%s: %s: %s\n", s, res_strings[res].ident, res_strings[res].doc);
else
error("\n%s: %d: unknown result code\n", s, res);