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/modsys.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/modsys.c')
| -rw-r--r-- | py/modsys.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/py/modsys.c b/py/modsys.c index 2af81046f..e90ea2233 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -56,15 +56,15 @@ const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adap #endif // version - Python language version that this implementation conforms to, as a string -STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); +static const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); // version_info - Python language version that this implementation conforms to, as a tuple of ints // TODO: CPython is now at 5-element array (major, minor, micro, releaselevel, serial), but save 2 els so far... -STATIC const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; +static const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; // sys.implementation object // this holds the MicroPython version -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { {&mp_type_tuple}, 4, { @@ -78,7 +78,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { #endif } }; -STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); +static const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); #define SYS_IMPLEMENTATION_ELEMS_BASE \ MP_ROM_QSTR(MP_QSTR_micropython), \ MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \ @@ -99,7 +99,7 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER #define SYS_IMPLEMENTATION_ELEMS__V2 #endif -STATIC const qstr impl_fields[] = { +static const qstr impl_fields[] = { MP_QSTR_name, MP_QSTR_version, MP_QSTR__machine, @@ -110,7 +110,7 @@ STATIC const qstr impl_fields[] = { MP_QSTR__v2, #endif }; -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mp_sys_implementation_obj, impl_fields, 3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2, @@ -119,7 +119,7 @@ STATIC MP_DEFINE_ATTRTUPLE( SYS_IMPLEMENTATION_ELEMS__V2 ); #else -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_obj = { {&mp_type_tuple}, 3 + MICROPY_PERSISTENT_CODE_LOAD, // Do not include SYS_IMPLEMENTATION_ELEMS__V2 because @@ -138,7 +138,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { #ifdef MICROPY_PY_SYS_PLATFORM // platform - the platform that MicroPython is running on -STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); #endif #ifdef MICROPY_PY_SYS_EXECUTABLE @@ -152,7 +152,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_intern_obj, mp_obj_str_intern_checked); #endif // exit([retval]): raise SystemExit, with optional argument given to the exception -STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { mp_raise_type(&mp_type_SystemExit); } else { @@ -161,7 +161,7 @@ STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); -STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES void *stream_obj = &mp_sys_stdout_obj; if (n_args > 1) { @@ -181,7 +181,7 @@ STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_print_exception); #if MICROPY_PY_SYS_EXC_INFO -STATIC mp_obj_t mp_sys_exc_info(void) { +static mp_obj_t mp_sys_exc_info(void) { mp_obj_t cur_exc = MP_OBJ_FROM_PTR(MP_STATE_VM(cur_exception)); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); @@ -201,25 +201,25 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); #endif #if MICROPY_PY_SYS_GETSIZEOF -STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { +static mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { return mp_unary_op(MP_UNARY_OP_SIZEOF, obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); #endif #if MICROPY_PY_SYS_ATEXIT // atexit(callback): Callback is called when sys.exit is called. -STATIC mp_obj_t mp_sys_atexit(mp_obj_t obj) { +static mp_obj_t mp_sys_atexit(mp_obj_t obj) { mp_obj_t old = MP_STATE_VM(sys_exitfunc); MP_STATE_VM(sys_exitfunc) = obj; return old; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); #endif #if MICROPY_PY_SYS_SETTRACE // settrace(tracefunc): Set the system's trace function. -STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { +static mp_obj_t mp_sys_settrace(mp_obj_t obj) { return mp_prof_settrace(obj); } MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); @@ -243,7 +243,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #if MICROPY_PY_SYS_ATTR_DELEGATION // Must be kept in sync with the enum at the top of mpstate.h. -STATIC const uint16_t sys_mutable_keys[] = { +static const uint16_t sys_mutable_keys[] = { #if MICROPY_PY_SYS_PATH // Code should access this (as an mp_obj_t) for use with e.g. // mp_obj_list_append by using the `mp_sys_path` macro defined in runtime.h. @@ -266,7 +266,7 @@ void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { +static const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, #if MICROPY_PY_SYS_ARGV @@ -339,7 +339,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); const mp_obj_module_t mp_module_sys = { .base = { &mp_type_module }, |
