Commit 6d3c5e43 authored by Damien George's avatar Damien George
Browse files

Add ARRAY_SIZE macro, and use it where possible.

parent d139c489
......@@ -105,8 +105,8 @@ STATIC const mp_obj_dict_t stm_module_globals = {
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(stm_module_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(stm_module_globals_table) / sizeof(mp_map_elem_t),
.used = ARRAY_SIZE(stm_module_globals_table),
.alloc = ARRAY_SIZE(stm_module_globals_table),
.table = (mp_map_elem_t*)stm_module_globals_table,
},
};
......
......@@ -33,8 +33,8 @@ STATIC const mp_obj_dict_t time_module_globals = {
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(time_module_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(time_module_globals_table) / sizeof(mp_map_elem_t),
.used = ARRAY_SIZE(time_module_globals_table),
.alloc = ARRAY_SIZE(time_module_globals_table),
.table = (mp_map_elem_t*)time_module_globals_table,
},
};
......
......@@ -158,7 +158,7 @@ STATIC const pyb_spi_obj_t pyb_spi_obj[] = {
{{&pyb_spi_type}, NULL},
#endif
};
#define PYB_NUM_SPI (sizeof(pyb_spi_obj) / sizeof(pyb_spi_obj[0]))
#define PYB_NUM_SPI ARRAY_SIZE(pyb_spi_obj)
STATIC void pyb_spi_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
pyb_spi_obj_t *self = self_in;
......@@ -206,7 +206,7 @@ STATIC const mp_arg_parse_t pyb_spi_init_accepted_args[] = {
{ MP_QSTR_ti, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_BOOL, {.u_bool = false} },
{ MP_QSTR_crc, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_OBJ, {.u_obj = mp_const_none} },
};
#define PYB_SPI_INIT_NUM_ARGS (sizeof(pyb_spi_init_accepted_args) / sizeof(pyb_spi_init_accepted_args[0]))
#define PYB_SPI_INIT_NUM_ARGS ARRAY_SIZE(pyb_spi_init_accepted_args)
STATIC mp_obj_t pyb_spi_init_helper(const pyb_spi_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
......@@ -299,7 +299,7 @@ STATIC const mp_arg_parse_t pyb_spi_send_accepted_args[] = {
{ MP_QSTR_send, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
#define PYB_SPI_SEND_NUM_ARGS (sizeof(pyb_spi_send_accepted_args) / sizeof(pyb_spi_send_accepted_args[0]))
#define PYB_SPI_SEND_NUM_ARGS ARRAY_SIZE(pyb_spi_send_accepted_args)
STATIC mp_obj_t pyb_spi_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
......@@ -331,7 +331,7 @@ STATIC const mp_arg_parse_t pyb_spi_recv_accepted_args[] = {
{ MP_QSTR_recv, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
#define PYB_SPI_RECV_NUM_ARGS (sizeof(pyb_spi_recv_accepted_args) / sizeof(pyb_spi_recv_accepted_args[0]))
#define PYB_SPI_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_recv_accepted_args)
STATIC mp_obj_t pyb_spi_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
......@@ -368,7 +368,7 @@ STATIC const mp_arg_parse_t pyb_spi_send_recv_accepted_args[] = {
{ MP_QSTR_recv, MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
#define PYB_SPI_SEND_RECV_NUM_ARGS (sizeof(pyb_spi_send_recv_accepted_args) / sizeof(pyb_spi_send_recv_accepted_args[0]))
#define PYB_SPI_SEND_RECV_NUM_ARGS ARRAY_SIZE(pyb_spi_send_recv_accepted_args)
STATIC mp_obj_t pyb_spi_send_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
......
......@@ -57,7 +57,7 @@ static uint32_t tim3_counter = 0;
// Used to do callbacks to Python code on interrupt
STATIC pyb_timer_obj_t *pyb_timer_obj_all[14];
#define PYB_TIMER_OBJ_ALL_NUM (sizeof(pyb_timer_obj_all) / sizeof(pyb_timer_obj_all[0]))
#define PYB_TIMER_OBJ_ALL_NUM ARRAY_SIZE(pyb_timer_obj_all)
void timer_init0(void) {
tim3_counter = 0;
......@@ -180,7 +180,7 @@ STATIC const mp_arg_parse_t pyb_timer_init_accepted_args[] = {
{ MP_QSTR_mode, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = TIM_COUNTERMODE_UP} },
{ MP_QSTR_div, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = TIM_CLOCKDIVISION_DIV1} },
};
#define PYB_TIMER_INIT_NUM_ARGS (sizeof(pyb_timer_init_accepted_args) / sizeof(pyb_timer_init_accepted_args[0]))
#define PYB_TIMER_INIT_NUM_ARGS ARRAY_SIZE(pyb_timer_init_accepted_args)
STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
......
......@@ -231,7 +231,7 @@ STATIC const mp_arg_parse_t pyb_uart_init_accepted_args[] = {
{ MP_QSTR_stop, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 1} },
{ MP_QSTR_parity, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_OBJ, {.u_obj = mp_const_none} },
};
#define PYB_UART_INIT_NUM_ARGS (sizeof(pyb_uart_init_accepted_args) / sizeof(pyb_uart_init_accepted_args[0]))
#define PYB_UART_INIT_NUM_ARGS ARRAY_SIZE(pyb_uart_init_accepted_args)
STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// parse args
......@@ -331,7 +331,7 @@ STATIC const mp_arg_parse_t pyb_uart_send_accepted_args[] = {
{ MP_QSTR_send, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
#define PYB_UART_SEND_NUM_ARGS (sizeof(pyb_uart_send_accepted_args) / sizeof(pyb_uart_send_accepted_args[0]))
#define PYB_UART_SEND_NUM_ARGS ARRAY_SIZE(pyb_uart_send_accepted_args)
STATIC mp_obj_t pyb_uart_send(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
......@@ -363,7 +363,7 @@ STATIC const mp_arg_parse_t pyb_uart_recv_accepted_args[] = {
{ MP_QSTR_recv, MP_ARG_PARSE_REQUIRED | MP_ARG_PARSE_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_timeout, MP_ARG_PARSE_KW_ONLY | MP_ARG_PARSE_INT, {.u_int = 5000} },
};
#define PYB_UART_RECV_NUM_ARGS (sizeof(pyb_uart_recv_accepted_args) / sizeof(pyb_uart_recv_accepted_args[0]))
#define PYB_UART_RECV_NUM_ARGS ARRAY_SIZE(pyb_uart_recv_accepted_args)
STATIC mp_obj_t pyb_uart_recv(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
// TODO assumes transmission size is 8-bits wide
......
......@@ -394,8 +394,8 @@ STATIC const mp_obj_dict_t mp_module_ffi_globals = {
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(mp_module_ffi_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(mp_module_ffi_globals_table) / sizeof(mp_map_elem_t),
.used = ARRAY_SIZE(mp_module_ffi_globals_table),
.alloc = ARRAY_SIZE(mp_module_ffi_globals_table),
.table = (mp_map_elem_t*)mp_module_ffi_globals_table,
},
};
......
......@@ -378,8 +378,8 @@ STATIC const mp_obj_dict_t mp_module_socket_globals = {
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(mp_module_socket_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(mp_module_socket_globals_table) / sizeof(mp_map_elem_t),
.used = ARRAY_SIZE(mp_module_socket_globals_table),
.alloc = ARRAY_SIZE(mp_module_socket_globals_table),
.table = (mp_map_elem_t*)mp_module_socket_globals_table,
},
};
......
......@@ -63,8 +63,8 @@ STATIC const mp_obj_dict_t mp_module_time_globals = {
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(mp_module_time_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(mp_module_time_globals_table) / sizeof(mp_map_elem_t),
.used = ARRAY_SIZE(mp_module_time_globals_table),
.alloc = ARRAY_SIZE(mp_module_time_globals_table),
.table = (mp_map_elem_t*)mp_module_time_globals_table,
},
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment