mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 12:10:13 +01:00
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:
committed by
Damien George
parent
b3f2f18f92
commit
decf8e6a8b
18
py/modgc.c
18
py/modgc.c
@@ -31,7 +31,7 @@
|
||||
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
|
||||
|
||||
// collect(): run a garbage collection
|
||||
STATIC mp_obj_t py_gc_collect(void) {
|
||||
static mp_obj_t py_gc_collect(void) {
|
||||
gc_collect();
|
||||
#if MICROPY_PY_GC_COLLECT_RETVAL
|
||||
return MP_OBJ_NEW_SMALL_INT(MP_STATE_MEM(gc_collected));
|
||||
@@ -42,26 +42,26 @@ STATIC mp_obj_t py_gc_collect(void) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect);
|
||||
|
||||
// disable(): disable the garbage collector
|
||||
STATIC mp_obj_t gc_disable(void) {
|
||||
static mp_obj_t gc_disable(void) {
|
||||
MP_STATE_MEM(gc_auto_collect_enabled) = 0;
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable);
|
||||
|
||||
// enable(): enable the garbage collector
|
||||
STATIC mp_obj_t gc_enable(void) {
|
||||
static mp_obj_t gc_enable(void) {
|
||||
MP_STATE_MEM(gc_auto_collect_enabled) = 1;
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
|
||||
|
||||
STATIC mp_obj_t gc_isenabled(void) {
|
||||
static mp_obj_t gc_isenabled(void) {
|
||||
return mp_obj_new_bool(MP_STATE_MEM(gc_auto_collect_enabled));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
|
||||
|
||||
// mem_free(): return the number of bytes of available heap RAM
|
||||
STATIC mp_obj_t gc_mem_free(void) {
|
||||
static mp_obj_t gc_mem_free(void) {
|
||||
gc_info_t info;
|
||||
gc_info(&info);
|
||||
#if MICROPY_GC_SPLIT_HEAP_AUTO
|
||||
@@ -74,7 +74,7 @@ STATIC mp_obj_t gc_mem_free(void) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
|
||||
|
||||
// mem_alloc(): return the number of bytes of heap RAM that are allocated
|
||||
STATIC mp_obj_t gc_mem_alloc(void) {
|
||||
static mp_obj_t gc_mem_alloc(void) {
|
||||
gc_info_t info;
|
||||
gc_info(&info);
|
||||
return MP_OBJ_NEW_SMALL_INT(info.used);
|
||||
@@ -82,7 +82,7 @@ STATIC mp_obj_t gc_mem_alloc(void) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc);
|
||||
|
||||
#if MICROPY_GC_ALLOC_THRESHOLD
|
||||
STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
if (MP_STATE_MEM(gc_alloc_threshold) == (size_t)-1) {
|
||||
return MP_OBJ_NEW_SMALL_INT(-1);
|
||||
@@ -100,7 +100,7 @@ STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gc_threshold_obj, 0, 1, gc_threshold);
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = {
|
||||
static const mp_rom_map_elem_t mp_module_gc_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gc) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_collect), MP_ROM_PTR(&gc_collect_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&gc_disable_obj) },
|
||||
@@ -113,7 +113,7 @@ STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table);
|
||||
static MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_gc = {
|
||||
.base = { &mp_type_module },
|
||||
|
||||
Reference in New Issue
Block a user