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 /extmod/modasyncio.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 'extmod/modasyncio.c')
-rw-r--r-- | extmod/modasyncio.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/extmod/modasyncio.c b/extmod/modasyncio.c index a6a54eba8..61dd70722 100644 --- a/extmod/modasyncio.c +++ b/extmod/modasyncio.c @@ -55,19 +55,19 @@ typedef struct _mp_obj_task_queue_t { mp_obj_task_t *heap; } mp_obj_task_queue_t; -STATIC const mp_obj_type_t task_queue_type; -STATIC const mp_obj_type_t task_type; +static const mp_obj_type_t task_queue_type; +static const mp_obj_type_t task_type; -STATIC mp_obj_t task_queue_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 task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // Ticks for task ordering in pairing heap -STATIC mp_obj_t ticks(void) { +static mp_obj_t ticks(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } -STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { +static mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in); mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in); mp_int_t diff = ((t1 - t0 + MICROPY_PY_TIME_TICKS_PERIOD / 2) & (MICROPY_PY_TIME_TICKS_PERIOD - 1)) @@ -75,7 +75,7 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { return diff; } -STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { +static int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { mp_obj_task_t *t1 = (mp_obj_task_t *)n1; mp_obj_task_t *t2 = (mp_obj_task_t *)n2; return MP_OBJ_SMALL_INT_VALUE(ticks_diff(t1->ph_key, t2->ph_key)) < 0; @@ -84,7 +84,7 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { /******************************************************************************/ // TaskQueue class -STATIC mp_obj_t task_queue_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 task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_task_queue_t *self = mp_obj_malloc(mp_obj_task_queue_t, type); @@ -92,7 +92,7 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { +static mp_obj_t task_queue_peek(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); if (self->heap == NULL) { return mp_const_none; @@ -100,9 +100,9 @@ STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(self->heap); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); -STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { +static mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_task_t *task = MP_OBJ_TO_PTR(args[1]); task->data = mp_const_none; @@ -115,9 +115,9 @@ STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, TASK_PAIRHEAP(self->heap), TASK_PAIRHEAP(task)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_obj, 2, 3, task_queue_push); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_obj, 2, 3, task_queue_push); -STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { +static mp_obj_t task_queue_pop(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *head = (mp_obj_task_t *)mp_pairheap_peek(task_lt, &self->heap->pairheap); if (head == NULL) { @@ -126,25 +126,25 @@ STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { self->heap = (mp_obj_task_t *)mp_pairheap_pop(task_lt, &self->heap->pairheap); return MP_OBJ_FROM_PTR(head); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); -STATIC mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { +static mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *task = MP_OBJ_TO_PTR(task_in); self->heap = (mp_obj_task_t *)mp_pairheap_delete(task_lt, &self->heap->pairheap, &task->pairheap); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); -STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = { +static const mp_rom_map_elem_t task_queue_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_peek), MP_ROM_PTR(&task_queue_peek_obj) }, { MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&task_queue_push_obj) }, { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&task_queue_pop_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&task_queue_remove_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); +static MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_queue_type, MP_QSTR_TaskQueue, MP_TYPE_FLAG_NONE, @@ -156,9 +156,9 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // Task class // This is the core asyncio context with cur_task, _task_queue and CancelledError. -STATIC mp_obj_t asyncio_context = MP_OBJ_NULL; +static mp_obj_t asyncio_context = MP_OBJ_NULL; -STATIC mp_obj_t task_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 task_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, 2, false); mp_obj_task_t *self = m_new_obj(mp_obj_task_t); self->pairheap.base.type = type; @@ -173,13 +173,13 @@ STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_done(mp_obj_t self_in) { +static mp_obj_t task_done(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(TASK_IS_DONE(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); +static MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); -STATIC mp_obj_t task_cancel(mp_obj_t self_in) { +static mp_obj_t task_cancel(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); // Check if task is already finished. if (TASK_IS_DONE(self)) { @@ -222,9 +222,9 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); +static MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); -STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // Load @@ -255,7 +255,7 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { @@ -271,7 +271,7 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { return self_in; } -STATIC mp_obj_t task_iternext(mp_obj_t self_in) { +static mp_obj_t task_iternext(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { // Task finished, raise return value to caller so it can continue. @@ -287,12 +287,12 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { return mp_const_none; } -STATIC const mp_getiter_iternext_custom_t task_getiter_iternext = { +static const mp_getiter_iternext_custom_t task_getiter_iternext = { .getiter = task_getiter, .iternext = task_iternext, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_type, MP_QSTR_Task, MP_TYPE_FLAG_ITER_IS_CUSTOM, @@ -304,12 +304,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // C-level asyncio module -STATIC const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { +static const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) }, { MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) }, { MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); const mp_obj_module_t mp_module_asyncio = { .base = { &mp_type_module }, |