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 /py/builtinimport.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 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index 002a5cb85..0611926fd 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -57,7 +57,7 @@ // uses mp_vfs_import_stat) to also search frozen modules. Given an exact // path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"), // will return whether the path is a file, directory, or doesn't exist. -STATIC mp_import_stat_t stat_path(vstr_t *path) { +static mp_import_stat_t stat_path(vstr_t *path) { const char *str = vstr_null_terminated_str(path); #if MICROPY_MODULE_FROZEN // Only try and load as a frozen module if it starts with .frozen/. @@ -75,7 +75,7 @@ STATIC mp_import_stat_t stat_path(vstr_t *path) { // argument. This is the logic that makes .py files take precedent over .mpy // files. This uses stat_path above, rather than mp_import_stat directly, so // that the .frozen path prefix is handled. -STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { +static mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { mp_import_stat_t stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; @@ -99,7 +99,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // or "foo/bar.(m)py" in either the filesystem or frozen modules. If the // result is a file, the path argument will be updated to include the file // extension. -STATIC mp_import_stat_t stat_module(vstr_t *path) { +static mp_import_stat_t stat_module(vstr_t *path) { mp_import_stat_t stat = stat_path(path); DEBUG_printf("stat %s: %d\n", vstr_str(path), stat); if (stat == MP_IMPORT_STAT_DIR) { @@ -114,7 +114,7 @@ STATIC mp_import_stat_t stat_module(vstr_t *path) { // Given a top-level module name, try and find it in each of the sys.path // entries. Note: On success, the dest argument will be updated to the matching // path (i.e. "<entry>/mod_name(.py)"). -STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { +static mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { DEBUG_printf("stat_top_level: '%s'\n", qstr_str(mod_name)); #if MICROPY_PY_SYS size_t path_num; @@ -152,7 +152,7 @@ STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { } #if MICROPY_MODULE_FROZEN_STR || MICROPY_ENABLE_COMPILER -STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { +static void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #if MICROPY_PY___FILE__ qstr source_name = lex->source_name; mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); @@ -165,7 +165,7 @@ STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #endif #if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_MODULE_FROZEN_MPY -STATIC void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { +static void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { #if MICROPY_PY___FILE__ mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); #else @@ -196,7 +196,7 @@ STATIC void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fu } #endif -STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { +static void do_load(mp_module_context_t *module_obj, vstr_t *file) { #if MICROPY_MODULE_FROZEN || MICROPY_ENABLE_COMPILER || (MICROPY_PERSISTENT_CODE_LOAD && MICROPY_HAS_FILE_READER) const char *file_str = vstr_null_terminated_str(file); #endif @@ -267,7 +267,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { // Convert a relative (to the current module) import, going up "level" levels, // into an absolute import. -STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { +static void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { // What we want to do here is to take the name of the current module, // remove <level> trailing components, and concatenate the passed-in // module name. @@ -350,7 +350,7 @@ typedef struct _nlr_jump_callback_node_unregister_module_t { qstr name; } nlr_jump_callback_node_unregister_module_t; -STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { +static void unregister_module_from_nlr_jump_callback(void *ctx_in) { nlr_jump_callback_node_unregister_module_t *ctx = ctx_in; mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; mp_map_lookup(mp_loaded_modules_map, MP_OBJ_NEW_QSTR(ctx->name), MP_MAP_LOOKUP_REMOVE_IF_FOUND); @@ -363,7 +363,7 @@ STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { // attribute on it) (or MP_OBJ_NULL for top-level). // override_main: Whether to set the __name__ to "__main__" (and use __main__ // for the actual path). -STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { +static mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { // Immediately return if the module at this level is already loaded. mp_map_elem_t *elem; |