misc: rename ARRAY_SIZE to ARRAY_LENGTH and guard it

This commit is contained in:
Mikaela Szekely 2022-08-23 08:24:38 -06:00 committed by Rachel Mant
parent 6217da4eab
commit 9576d13cf7
3 changed files with 9 additions and 7 deletions

View File

@ -42,7 +42,9 @@
#include "platform.h" #include "platform.h"
#include "platform_support.h" #include "platform_support.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(arr) (sizeof(arr) / sizeof(arr[0]))
#endif
extern uint32_t delay_cnt; extern uint32_t delay_cnt;

View File

@ -174,7 +174,7 @@ static const gdb_reg_type_e cortex_a_spr_types[] = {
GDB_TYPE_UNSPECIFIED // cpsr GDB_TYPE_UNSPECIFIED // cpsr
}; };
static_assert(ARRAY_SIZE(cortex_a_spr_types) == ARRAY_SIZE(cortex_a_spr_names), "SPR array length mixmatch! SPR type " static_assert(ARRAY_LENGTH(cortex_a_spr_types) == ARRAY_LENGTH(cortex_a_spr_names), "SPR array length mixmatch! SPR type "
"array should have the same length as " "array should have the same length as "
"SPR name array."); "SPR name array.");
@ -270,7 +270,7 @@ static size_t create_tdesc_cortex_a(char *buffer, size_t max_len)
// all of the Cortex-A target description SPRs have the same bitsize, and none of them // all of the Cortex-A target description SPRs have the same bitsize, and none of them
// have a specified save-restore value. So we only need one "associative array" here. // have a specified save-restore value. So we only need one "associative array" here.
// NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays. // NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays.
for (size_t i = 0; i < ARRAY_SIZE(cortex_a_spr_names); ++i) { for (size_t i = 0; i < ARRAY_LENGTH(cortex_a_spr_names); ++i) {
gdb_reg_type_e type = cortex_a_spr_types[i]; gdb_reg_type_e type = cortex_a_spr_types[i];
if (max_len != 0) if (max_len != 0)

View File

@ -176,7 +176,7 @@ static const gdb_reg_type_e cortex_m_spr_types[] = {
GDB_TYPE_UNSPECIFIED, // control GDB_TYPE_UNSPECIFIED, // control
}; };
static_assert(ARRAY_SIZE(cortex_m_spr_types) == ARRAY_SIZE(cortex_m_spr_names), "SPR array length mismatch! SPR type " static_assert(ARRAY_LENGTH(cortex_m_spr_types) == ARRAY_LENGTH(cortex_m_spr_names), "SPR array length mismatch! SPR type "
"array should have the same length as " "array should have the same length as "
"SPR name array."); "SPR name array.");
@ -194,7 +194,7 @@ static const gdb_reg_save_restore_e cortex_m_spr_save_restores[] = {
GDB_SAVE_RESTORE_NO, // control GDB_SAVE_RESTORE_NO, // control
}; };
static_assert(ARRAY_SIZE(cortex_m_spr_save_restores) == ARRAY_SIZE(cortex_m_spr_names), "SPR array length mismatch! " static_assert(ARRAY_LENGTH(cortex_m_spr_save_restores) == ARRAY_LENGTH(cortex_m_spr_names), "SPR array length mismatch! "
"SPR save-restore array should " "SPR save-restore array should "
"have the same length as SPR " "have the same length as SPR "
"name array."); "name array.");
@ -213,7 +213,7 @@ static const uint8_t cortex_m_spr_bitsizes[] = {
8, // control 8, // control
}; };
static_assert(ARRAY_SIZE(cortex_m_spr_bitsizes) == ARRAY_SIZE(cortex_m_spr_names), "SPR array length mismatch! SPR " static_assert(ARRAY_LENGTH(cortex_m_spr_bitsizes) == ARRAY_LENGTH(cortex_m_spr_names), "SPR array length mismatch! SPR "
"bitsize array should have the same " "bitsize array should have the same "
"length as SPR name array."); "length as SPR name array.");
@ -295,7 +295,7 @@ static size_t create_tdesc_cortex_m(char *buffer, size_t max_len)
// Some of them have different bitsizes, specified types, or specified save-restore values. // Some of them have different bitsizes, specified types, or specified save-restore values.
// We'll use the 'associative arrays' defined for those values. // We'll use the 'associative arrays' defined for those values.
// NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays. // NOTE: unlike the other loops, this loop uses a size_t for its counter, as it's used to index into arrays.
for (size_t i = 0; i < ARRAY_SIZE(cortex_m_spr_names); ++i) { for (size_t i = 0; i < ARRAY_LENGTH(cortex_m_spr_names); ++i) {
if (max_len != 0) if (max_len != 0)
printsz = max_len - (size_t)total; printsz = max_len - (size_t)total;