diff options
author | Angus Gratton <angus@redyak.com.au> | 2024-02-27 15:32:29 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-03-07 14:20:42 +1100 |
commit | decf8e6a8bb940d5829ca3296790631fcece7b21 (patch) | |
tree | 55b7cd31de14b73e4b72d49344e9084f402767a9 /ports/esp32/esp32_nvs.c | |
parent | b3f2f18f927fa2fad10daf63d8c391331f5edf58 (diff) |
all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a433d6253a61cb0f987835fbc06b2de. 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>
Diffstat (limited to 'ports/esp32/esp32_nvs.c')
-rw-r--r-- | ports/esp32/esp32_nvs.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/ports/esp32/esp32_nvs.c b/ports/esp32/esp32_nvs.c index 0b3661918..daeec4c26 100644 --- a/ports/esp32/esp32_nvs.c +++ b/ports/esp32/esp32_nvs.c @@ -43,7 +43,7 @@ typedef struct _esp32_nvs_obj_t { } esp32_nvs_obj_t; // *esp32_nvs_new allocates a python NVS object given a handle to an esp-idf namespace C obj. -STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { +static esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { esp32_nvs_obj_t *self = mp_obj_malloc(esp32_nvs_obj_t, &esp32_nvs_type); self->namespace = namespace; return self; @@ -51,13 +51,13 @@ STATIC esp32_nvs_obj_t *esp32_nvs_new(nvs_handle_t namespace) { // esp32_nvs_print prints an NVS object, unfortunately it doesn't seem possible to extract the // namespace string or anything else from the opaque handle provided by esp-idf. -STATIC void esp32_nvs_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void esp32_nvs_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { // esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "<NVS namespace>"); } // esp32_nvs_make_new constructs a handle to an NVS namespace. -STATIC mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { // Check args mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -69,27 +69,27 @@ STATIC mp_obj_t esp32_nvs_make_new(const mp_obj_type_t *type, size_t n_args, siz } // esp32_nvs_set_i32 sets a 32-bit integer value -STATIC mp_obj_t esp32_nvs_set_i32(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_set_i32(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); int32_t value = mp_obj_get_int(value_in); check_esp_err(nvs_set_i32(self->namespace, key, value)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_i32_obj, esp32_nvs_set_i32); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_i32_obj, esp32_nvs_set_i32); // esp32_nvs_get_i32 reads a 32-bit integer value -STATIC mp_obj_t esp32_nvs_get_i32(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t esp32_nvs_get_i32(mp_obj_t self_in, mp_obj_t key_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); int32_t value; check_esp_err(nvs_get_i32(self->namespace, key, &value)); return mp_obj_new_int(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_get_i32_obj, esp32_nvs_get_i32); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_get_i32_obj, esp32_nvs_get_i32); // esp32_nvs_set_blob writes a buffer object into a binary blob value. -STATIC mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); mp_buffer_info_t value; @@ -97,10 +97,10 @@ STATIC mp_obj_t esp32_nvs_set_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t v check_esp_err(nvs_set_blob(self->namespace, key, value.buf, value.len)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_blob_obj, esp32_nvs_set_blob); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_set_blob_obj, esp32_nvs_set_blob); // esp32_nvs_get_blob reads a binary blob value into a bytearray. Returns actual length. -STATIC mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); // get buffer to be filled @@ -112,26 +112,26 @@ STATIC mp_obj_t esp32_nvs_get_blob(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t v check_esp_err(nvs_get_blob(self->namespace, key, value.buf, &length)); return MP_OBJ_NEW_SMALL_INT(length); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_get_blob_obj, esp32_nvs_get_blob); +static MP_DEFINE_CONST_FUN_OBJ_3(esp32_nvs_get_blob_obj, esp32_nvs_get_blob); // esp32_nvs_erase_key erases one key. -STATIC mp_obj_t esp32_nvs_erase_key(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t esp32_nvs_erase_key(mp_obj_t self_in, mp_obj_t key_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); const char *key = mp_obj_str_get_str(key_in); check_esp_err(nvs_erase_key(self->namespace, key)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_erase_key_obj, esp32_nvs_erase_key); +static MP_DEFINE_CONST_FUN_OBJ_2(esp32_nvs_erase_key_obj, esp32_nvs_erase_key); // esp32_nvs_commit commits any changes to flash. -STATIC mp_obj_t esp32_nvs_commit(mp_obj_t self_in) { +static mp_obj_t esp32_nvs_commit(mp_obj_t self_in) { esp32_nvs_obj_t *self = MP_OBJ_TO_PTR(self_in); check_esp_err(nvs_commit(self->namespace)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_nvs_commit_obj, esp32_nvs_commit); +static MP_DEFINE_CONST_FUN_OBJ_1(esp32_nvs_commit_obj, esp32_nvs_commit); -STATIC const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { +static const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get_i32), MP_ROM_PTR(&esp32_nvs_get_i32_obj) }, { MP_ROM_QSTR(MP_QSTR_set_i32), MP_ROM_PTR(&esp32_nvs_set_i32_obj) }, { MP_ROM_QSTR(MP_QSTR_get_blob), MP_ROM_PTR(&esp32_nvs_get_blob_obj) }, @@ -139,7 +139,7 @@ STATIC const mp_rom_map_elem_t esp32_nvs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_erase_key), MP_ROM_PTR(&esp32_nvs_erase_key_obj) }, { MP_ROM_QSTR(MP_QSTR_commit), MP_ROM_PTR(&esp32_nvs_commit_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(esp32_nvs_locals_dict, esp32_nvs_locals_dict_table); +static MP_DEFINE_CONST_DICT(esp32_nvs_locals_dict, esp32_nvs_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( esp32_nvs_type, |