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/modjson.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/modjson.c')
-rw-r--r-- | extmod/modjson.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/extmod/modjson.c b/extmod/modjson.c index 1772b7299..e655a02bc 100644 --- a/extmod/modjson.c +++ b/extmod/modjson.c @@ -41,7 +41,7 @@ enum { DUMP_MODE_TO_STREAM = 2, }; -STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { +static mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { enum { ARG_separators }; static const mp_arg_t allowed_args[] = { { MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -78,34 +78,34 @@ STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp } } -STATIC mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); #else -STATIC mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { +static mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_WRITE); mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor}; mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(mp_obj_t obj) { +static mp_obj_t mod_json_dumps(mp_obj_t obj) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 8, &print); mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_obj_new_str_from_utf8_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); #endif @@ -134,7 +134,7 @@ typedef struct _json_stream_t { #define S_CUR(s) ((s).cur) #define S_NEXT(s) (json_stream_next(&(s))) -STATIC byte json_stream_next(json_stream_t *s) { +static byte json_stream_next(json_stream_t *s) { mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode); if (s->errcode != 0) { mp_raise_OSError(s->errcode); @@ -145,7 +145,7 @@ STATIC byte json_stream_next(json_stream_t *s) { return s->cur; } -STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) { +static mp_obj_t mod_json_load(mp_obj_t stream_obj) { const mp_stream_p_t *stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ); json_stream_t s = {stream_obj, stream_p->read, 0, 0}; vstr_t vstr; @@ -355,18 +355,18 @@ success: fail: mp_raise_ValueError(MP_ERROR_TEXT("syntax error in JSON")); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); -STATIC mp_obj_t mod_json_loads(mp_obj_t obj) { +static mp_obj_t mod_json_loads(mp_obj_t obj) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ); vstr_t vstr = {bufinfo.len, bufinfo.len, (char *)bufinfo.buf, true}; mp_obj_stringio_t sio = {{&mp_type_stringio}, &vstr, 0, MP_OBJ_NULL}; return mod_json_load(MP_OBJ_FROM_PTR(&sio)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); -STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { +static const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_json_dump_obj) }, { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_json_dumps_obj) }, @@ -374,7 +374,7 @@ STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_json_loads_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); const mp_obj_module_t mp_module_json = { .base = { &mp_type_module }, |