all: Remove the "STATIC" macro and just use "static" instead.

The STATIC macro was introduced a very long time ago in commit
d5df6cd44a.  The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.

This STATIC feature is rarely (if ever) used.  And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.

So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing.  For example, newcomers don't have
to learn what the STATIC macro is and why it exists.  Reading the code is
also less "loud" with a lowercase static.

One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.

Methodology for this commit was:

1) git ls-files | egrep '\.[ch]$' | \
   xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"

2) Do some manual cleanup in the diff by searching for the word STATIC in
   comments and changing those back.

3) "git-grep STATIC docs/", manually fixed those cases.

4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
Angus Gratton
2024-02-27 15:32:29 +11:00
committed by Damien George
parent b3f2f18f92
commit decf8e6a8b
482 changed files with 6287 additions and 6293 deletions

View File

@@ -30,28 +30,28 @@
#include "py/mphal.h"
#include "modpyb.h"
STATIC mp_obj_t pyb_millis(void) {
static mp_obj_t pyb_millis(void) {
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
static MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
STATIC mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
static mp_obj_t pyb_elapsed_millis(mp_obj_t start) {
uint32_t startMillis = mp_obj_get_int(start);
uint32_t currMillis = mp_hal_ticks_ms();
return MP_OBJ_NEW_SMALL_INT((currMillis - startMillis) & 0x1fff);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_elapsed_millis_obj, pyb_elapsed_millis);
STATIC mp_obj_t pyb_delay(mp_obj_t ms_in) {
static mp_obj_t pyb_delay(mp_obj_t ms_in) {
mp_int_t ms = mp_obj_get_int(ms_in);
if (ms >= 0) {
mp_hal_delay_ms(ms);
}
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
static const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pyb) },
{ MP_ROM_QSTR(MP_QSTR_millis), MP_ROM_PTR(&pyb_millis_obj) },
@@ -62,7 +62,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_Switch), MP_ROM_PTR(&pyb_switch_type) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
static MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
const mp_obj_module_t pyb_module = {
.base = { &mp_type_module },

View File

@@ -32,7 +32,7 @@ typedef struct _pyb_led_obj_t {
mp_obj_base_t base;
} pyb_led_obj_t;
STATIC const pyb_led_obj_t pyb_led_obj[] = {
static const pyb_led_obj_t pyb_led_obj[] = {
{{&pyb_led_type}},
{{&pyb_led_type}},
{{&pyb_led_type}},
@@ -46,7 +46,7 @@ void pyb_led_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
mp_printf(print, "LED(%u)", LED_ID(self));
}
STATIC mp_obj_t pyb_led_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
static mp_obj_t pyb_led_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
mp_int_t led_id = mp_obj_get_int(args[0]);
if (!(1 <= led_id && led_id <= NUM_LED)) {
@@ -60,29 +60,29 @@ mp_obj_t pyb_led_on(mp_obj_t self_in) {
led_state(LED_ID(self), 1);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_on_obj, pyb_led_on);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_on_obj, pyb_led_on);
mp_obj_t pyb_led_off(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
led_state(LED_ID(self), 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_off_obj, pyb_led_off);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_off_obj, pyb_led_off);
mp_obj_t pyb_led_toggle(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
led_toggle(LED_ID(self));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_toggle_obj, pyb_led_toggle);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_led_toggle_obj, pyb_led_toggle);
STATIC const mp_rom_map_elem_t pyb_led_locals_dict_table[] = {
static const mp_rom_map_elem_t pyb_led_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&pyb_led_on_obj) },
{ MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&pyb_led_off_obj) },
{ MP_ROM_QSTR(MP_QSTR_toggle), MP_ROM_PTR(&pyb_led_toggle_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table);
static MP_DEFINE_CONST_DICT(pyb_led_locals_dict, pyb_led_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
pyb_led_type,

View File

@@ -32,7 +32,7 @@ typedef struct _pyb_switch_obj_t {
mp_obj_base_t base;
} pyb_switch_obj_t;
STATIC const pyb_switch_obj_t pyb_switch_obj[] = {
static const pyb_switch_obj_t pyb_switch_obj[] = {
{{&pyb_switch_type}},
{{&pyb_switch_type}},
};
@@ -45,7 +45,7 @@ void pyb_switch_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
mp_printf(print, "Switch(%u)", SWITCH_ID(self));
}
STATIC mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
static mp_obj_t pyb_switch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
mp_int_t sw_id = mp_obj_get_int(args[0]);
if (!(1 <= sw_id && sw_id <= NUM_SWITCH)) {
@@ -58,18 +58,18 @@ mp_obj_t pyb_switch_value(mp_obj_t self_in) {
pyb_switch_obj_t *self = self_in;
return switch_get(SWITCH_ID(self)) ? mp_const_true : mp_const_false;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value);
static MP_DEFINE_CONST_FUN_OBJ_1(pyb_switch_value_obj, pyb_switch_value);
mp_obj_t pyb_switch_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
return pyb_switch_value(self_in);
}
STATIC const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = {
static const mp_rom_map_elem_t pyb_switch_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&pyb_switch_value_obj) },
};
STATIC MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table);
static MP_DEFINE_CONST_DICT(pyb_switch_locals_dict, pyb_switch_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
pyb_switch_type,