summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-02-27 15:32:29 +1100
committerDamien George <damien@micropython.org>2024-03-07 14:20:42 +1100
commitdecf8e6a8bb940d5829ca3296790631fcece7b21 (patch)
tree55b7cd31de14b73e4b72d49344e9084f402767a9 /shared
parentb3f2f18f927fa2fad10daf63d8c391331f5edf58 (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 'shared')
-rw-r--r--shared/libc/printf.c2
-rw-r--r--shared/readline/readline.c12
-rw-r--r--shared/runtime/gchelper_generic.c10
-rw-r--r--shared/runtime/mpirq.c14
-rw-r--r--shared/runtime/pyexec.c20
-rw-r--r--shared/runtime/softtimer.c4
-rw-r--r--shared/runtime/sys_stdio_mphal.c26
-rw-r--r--shared/timeutils/timeutils.c4
-rw-r--r--shared/tinyusb/mp_cdc_common.c2
9 files changed, 47 insertions, 47 deletions
diff --git a/shared/libc/printf.c b/shared/libc/printf.c
index 715181229..50b04ce9b 100644
--- a/shared/libc/printf.c
+++ b/shared/libc/printf.c
@@ -87,7 +87,7 @@ typedef struct _strn_print_env_t {
size_t remain;
} strn_print_env_t;
-STATIC void strn_print_strn(void *data, const char *str, size_t len) {
+static void strn_print_strn(void *data, const char *str, size_t len) {
strn_print_env_t *strn_print_env = data;
if (len > strn_print_env->remain) {
len = strn_print_env->remain;
diff --git a/shared/readline/readline.c b/shared/readline/readline.c
index b85bbd5be..c9386f16b 100644
--- a/shared/readline/readline.c
+++ b/shared/readline/readline.c
@@ -55,7 +55,7 @@ void readline_init0(void) {
memset(MP_STATE_PORT(readline_hist), 0, MICROPY_READLINE_HISTORY_SIZE * sizeof(const char*));
}
-STATIC char *str_dup_maybe(const char *str) {
+static char *str_dup_maybe(const char *str) {
uint32_t len = strlen(str);
char *s2 = m_new_maybe(char, len + 1);
if (s2 == NULL) {
@@ -72,7 +72,7 @@ STATIC char *str_dup_maybe(const char *str) {
// ...and provide the implementation using them
#if MICROPY_HAL_HAS_VT100
-STATIC void mp_hal_move_cursor_back(uint pos) {
+static void mp_hal_move_cursor_back(uint pos) {
if (pos <= 4) {
// fast path for most common case of 1 step back
mp_hal_stdout_tx_strn("\b\b\b\b", pos);
@@ -88,7 +88,7 @@ STATIC void mp_hal_move_cursor_back(uint pos) {
}
}
-STATIC void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) {
+static void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) {
(void)n_chars_to_erase;
mp_hal_stdout_tx_strn("\x1b[K", 3);
}
@@ -107,10 +107,10 @@ typedef struct _readline_t {
const char *prompt;
} readline_t;
-STATIC readline_t rl;
+static readline_t rl;
#if MICROPY_REPL_EMACS_WORDS_MOVE
-STATIC size_t cursor_count_word(int forward) {
+static size_t cursor_count_word(int forward) {
const char *line_buf = vstr_str(rl.line);
size_t pos = rl.cursor_pos;
bool in_word = false;
@@ -481,7 +481,7 @@ redraw:
}
#if MICROPY_REPL_AUTO_INDENT
-STATIC void readline_auto_indent(void) {
+static void readline_auto_indent(void) {
if (!(rl.auto_indent_state & AUTO_INDENT_ENABLED)) {
return;
}
diff --git a/shared/runtime/gchelper_generic.c b/shared/runtime/gchelper_generic.c
index 272e37056..4ef2e73f7 100644
--- a/shared/runtime/gchelper_generic.c
+++ b/shared/runtime/gchelper_generic.c
@@ -42,7 +42,7 @@
// stack already by the caller.
#if defined(__x86_64__)
-STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
+static void gc_helper_get_regs(gc_helper_regs_t arr) {
register long rbx asm ("rbx");
register long rbp asm ("rbp");
register long r12 asm ("r12");
@@ -73,7 +73,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
#elif defined(__i386__)
-STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
+static void gc_helper_get_regs(gc_helper_regs_t arr) {
register long ebx asm ("ebx");
register long esi asm ("esi");
register long edi asm ("edi");
@@ -100,7 +100,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
// Fallback implementation, prefer gchelper_thumb1.s or gchelper_thumb2.s
-STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
+static void gc_helper_get_regs(gc_helper_regs_t arr) {
register long r4 asm ("r4");
register long r5 asm ("r5");
register long r6 asm ("r6");
@@ -125,7 +125,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
#elif defined(__aarch64__)
-STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
+static void gc_helper_get_regs(gc_helper_regs_t arr) {
const register long x19 asm ("x19");
const register long x20 asm ("x20");
const register long x21 asm ("x21");
@@ -161,7 +161,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
// Even if we have specific support for an architecture, it is
// possible to force use of setjmp-based implementation.
-STATIC void gc_helper_get_regs(gc_helper_regs_t arr) {
+static void gc_helper_get_regs(gc_helper_regs_t arr) {
setjmp(arr);
}
diff --git a/shared/runtime/mpirq.c b/shared/runtime/mpirq.c
index acd727403..6111b9b10 100644
--- a/shared/runtime/mpirq.c
+++ b/shared/runtime/mpirq.c
@@ -96,13 +96,13 @@ void mp_irq_handler(mp_irq_obj_t *self) {
/******************************************************************************/
// MicroPython bindings
-STATIC mp_obj_t mp_irq_flags(mp_obj_t self_in) {
+static mp_obj_t mp_irq_flags(mp_obj_t self_in) {
mp_irq_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_FLAGS));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags);
+static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags);
-STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) {
+static mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) {
mp_irq_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_t ret_obj = mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_TRIGGERS));
if (n_args == 2) {
@@ -111,19 +111,19 @@ STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) {
}
return ret_obj;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger);
+static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger);
-STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
+static mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
mp_irq_handler(MP_OBJ_TO_PTR(self_in));
return mp_const_none;
}
-STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
+static const mp_rom_map_elem_t mp_irq_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) },
{ MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&mp_irq_trigger_obj) },
};
-STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table);
+static MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table);
MP_DEFINE_CONST_OBJ_TYPE(
mp_irq_type,
diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c
index cc2aa5350..a305e6a5d 100644
--- a/shared/runtime/pyexec.c
+++ b/shared/runtime/pyexec.c
@@ -47,7 +47,7 @@ pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
int pyexec_system_exit = 0;
#if MICROPY_REPL_INFO
-STATIC bool repl_display_debugging_info = 0;
+static bool repl_display_debugging_info = 0;
#endif
#define EXEC_FLAG_PRINT_EOF (1 << 0)
@@ -64,7 +64,7 @@ STATIC bool repl_display_debugging_info = 0;
// EXEC_FLAG_PRINT_EOF prints 2 EOF chars: 1 after normal output, 1 after exception output
// EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code
// EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile)
-STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags) {
+static int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags) {
int ret = 0;
#if MICROPY_REPL_INFO
uint32_t start = 0;
@@ -201,7 +201,7 @@ typedef struct _mp_reader_stdin_t {
uint16_t window_remain;
} mp_reader_stdin_t;
-STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) {
+static mp_uint_t mp_reader_stdin_readbyte(void *data) {
mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data;
if (reader->eof) {
@@ -233,7 +233,7 @@ STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) {
return c;
}
-STATIC void mp_reader_stdin_close(void *data) {
+static void mp_reader_stdin_close(void *data) {
mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data;
if (!reader->eof) {
reader->eof = true;
@@ -247,7 +247,7 @@ STATIC void mp_reader_stdin_close(void *data) {
}
}
-STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) {
+static void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) {
// Make flow-control window half the buffer size, and indicate to the host that 2x windows are
// free (sending the window size implicitly indicates that a window is free, and then the 0x01
// indicates that another window is free).
@@ -263,7 +263,7 @@ STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_s
reader->close = mp_reader_stdin_close;
}
-STATIC int do_reader_stdin(int c) {
+static int do_reader_stdin(int c) {
if (c != 'A') {
// Unsupported command.
mp_hal_stdout_tx_strn("R\x00", 2);
@@ -294,8 +294,8 @@ typedef struct _repl_t {
repl_t repl;
-STATIC int pyexec_raw_repl_process_char(int c);
-STATIC int pyexec_friendly_repl_process_char(int c);
+static int pyexec_raw_repl_process_char(int c);
+static int pyexec_friendly_repl_process_char(int c);
void pyexec_event_repl_init(void) {
MP_STATE_VM(repl_line) = vstr_new(32);
@@ -310,7 +310,7 @@ void pyexec_event_repl_init(void) {
}
}
-STATIC int pyexec_raw_repl_process_char(int c) {
+static int pyexec_raw_repl_process_char(int c) {
if (c == CHAR_CTRL_A) {
// reset raw REPL
if (vstr_len(MP_STATE_VM(repl_line)) == 2 && vstr_str(MP_STATE_VM(repl_line))[0] == CHAR_CTRL_E) {
@@ -364,7 +364,7 @@ reset:
return 0;
}
-STATIC int pyexec_friendly_repl_process_char(int c) {
+static int pyexec_friendly_repl_process_char(int c) {
if (repl.paste_mode) {
if (c == CHAR_CTRL_C) {
// cancel everything
diff --git a/shared/runtime/softtimer.c b/shared/runtime/softtimer.c
index 468fa95b7..13a6e7877 100644
--- a/shared/runtime/softtimer.c
+++ b/shared/runtime/softtimer.c
@@ -56,9 +56,9 @@ static void soft_timer_schedule_at_ms(uint32_t ticks_ms) {
// Pointer to the pairheap of soft timer objects.
// This may contain bss/data pointers as well as GC-heap pointers,
// and is explicitly GC traced by soft_timer_gc_mark_all().
-STATIC soft_timer_entry_t *soft_timer_heap;
+static soft_timer_entry_t *soft_timer_heap;
-STATIC int soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
+static int soft_timer_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
soft_timer_entry_t *e1 = (soft_timer_entry_t *)n1;
soft_timer_entry_t *e2 = (soft_timer_entry_t *)n2;
return soft_timer_ticks_diff(e1->expiry_ms, e2->expiry_ms) < 0;
diff --git a/shared/runtime/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c
index b7a35a5cb..ad045fb3a 100644
--- a/shared/runtime/sys_stdio_mphal.c
+++ b/shared/runtime/sys_stdio_mphal.c
@@ -49,15 +49,15 @@ typedef struct _sys_stdio_obj_t {
} sys_stdio_obj_t;
#if MICROPY_PY_SYS_STDIO_BUFFER
-STATIC const sys_stdio_obj_t stdio_buffer_obj;
+static const sys_stdio_obj_t stdio_buffer_obj;
#endif
-STATIC void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
+static void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<io.FileIO %d>", self->fd);
}
-STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
+static mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->fd == STDIO_FD_IN) {
for (uint i = 0; i < size; i++) {
@@ -74,7 +74,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er
}
}
-STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
+static mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) {
mp_hal_stdout_tx_strn_cooked(buf, size);
@@ -85,7 +85,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size,
}
}
-STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
+static mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
(void)self_in;
if (request == MP_STREAM_POLL) {
return mp_hal_stdio_poll(arg);
@@ -97,7 +97,7 @@ STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg,
}
}
-STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
+static const mp_rom_map_elem_t stdio_locals_dict_table[] = {
#if MICROPY_PY_SYS_STDIO_BUFFER
{ MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) },
#endif
@@ -111,9 +111,9 @@ STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) },
};
-STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
+static MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table);
-STATIC const mp_stream_p_t stdio_obj_stream_p = {
+static const mp_stream_p_t stdio_obj_stream_p = {
.read = stdio_read,
.write = stdio_write,
.ioctl = stdio_ioctl,
@@ -134,25 +134,25 @@ const sys_stdio_obj_t mp_sys_stdout_obj = {{&stdio_obj_type}, .fd = STDIO_FD_OUT
const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR};
#if MICROPY_PY_SYS_STDIO_BUFFER
-STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
+static mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
for (uint i = 0; i < size; i++) {
((byte *)buf)[i] = mp_hal_stdin_rx_chr();
}
return size;
}
-STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
+static mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
return mp_hal_stdout_tx_strn(buf, size);
}
-STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
+static const mp_stream_p_t stdio_buffer_obj_stream_p = {
.read = stdio_buffer_read,
.write = stdio_buffer_write,
.ioctl = stdio_ioctl,
.is_text = false,
};
-STATIC MP_DEFINE_CONST_OBJ_TYPE(
+static MP_DEFINE_CONST_OBJ_TYPE(
stdio_buffer_obj_type,
MP_QSTR_FileIO,
MP_TYPE_FLAG_ITER_IS_STREAM,
@@ -161,5 +161,5 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE(
locals_dict, &stdio_locals_dict
);
-STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused
+static const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused
#endif
diff --git a/shared/timeutils/timeutils.c b/shared/timeutils/timeutils.c
index 6bf3eca84..4282a0178 100644
--- a/shared/timeutils/timeutils.c
+++ b/shared/timeutils/timeutils.c
@@ -40,7 +40,7 @@
#define DAYS_PER_100Y (365 * 100 + 24)
#define DAYS_PER_4Y (365 * 4 + 1)
-STATIC const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
+static const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
bool timeutils_is_leap_year(mp_uint_t year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
@@ -125,7 +125,7 @@ void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_t
tm->tm_year = 2000 + years + 4 * q_cycles + 100 * c_cycles + 400 * qc_cycles;
// Note: days_in_month[0] corresponds to March
- STATIC const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29};
+ static const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29};
mp_int_t month;
for (month = 0; days_in_month[month] <= days; month++) {
diff --git a/shared/tinyusb/mp_cdc_common.c b/shared/tinyusb/mp_cdc_common.c
index 827868526..e790646f4 100644
--- a/shared/tinyusb/mp_cdc_common.c
+++ b/shared/tinyusb/mp_cdc_common.c
@@ -34,7 +34,7 @@
static mp_sched_node_t mp_bootloader_sched_node;
-STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
+static void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
mp_hal_delay_ms(250);
machine_bootloader(0, NULL);
}