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>
78 lines
3.1 KiB
C
78 lines
3.1 KiB
C
#define MICROPY_STACK_CHECK (1)
|
|
#define MICROPY_PY_RE (1)
|
|
#define MICROPY_PY_RE_MATCH_GROUPS (1)
|
|
#define MICROPY_PY_RE_MATCH_SPAN_START_END (1)
|
|
#define MICROPY_PY_RE_SUB (0) // requires vstr interface
|
|
|
|
#include <alloca.h>
|
|
#include "py/dynruntime.h"
|
|
|
|
#define STACK_LIMIT (2048)
|
|
|
|
const char *stack_top;
|
|
|
|
void mp_stack_check(void) {
|
|
// Assumes descending stack on target
|
|
volatile char dummy;
|
|
if (stack_top - &dummy >= STACK_LIMIT) {
|
|
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("maximum recursion depth exceeded"));
|
|
}
|
|
}
|
|
|
|
#if !defined(__linux__)
|
|
void *memcpy(void *dst, const void *src, size_t n) {
|
|
return mp_fun_table.memmove_(dst, src, n);
|
|
}
|
|
void *memset(void *s, int c, size_t n) {
|
|
return mp_fun_table.memset_(s, c, n);
|
|
}
|
|
#endif
|
|
|
|
void *memmove(void *dest, const void *src, size_t n) {
|
|
return mp_fun_table.memmove_(dest, src, n);
|
|
}
|
|
|
|
mp_obj_full_type_t match_type;
|
|
mp_obj_full_type_t re_type;
|
|
|
|
#include "extmod/modre.c"
|
|
|
|
mp_map_elem_t match_locals_dict_table[5];
|
|
static MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table);
|
|
|
|
mp_map_elem_t re_locals_dict_table[3];
|
|
static MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table);
|
|
|
|
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
|
|
MP_DYNRUNTIME_INIT_ENTRY
|
|
|
|
char dummy;
|
|
stack_top = &dummy;
|
|
|
|
// Because MP_QSTR_start/end/split are static, xtensa and xtensawin will make a small data section
|
|
// to copy in this key/value pair if they are specified as a struct, so assign them separately.
|
|
|
|
match_type.base.type = (void*)&mp_fun_table.type_type;
|
|
match_type.name = MP_QSTR_match;
|
|
MP_OBJ_TYPE_SET_SLOT(&match_type, print, match_print, 0);
|
|
match_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_group), MP_OBJ_FROM_PTR(&match_group_obj) };
|
|
match_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_groups), MP_OBJ_FROM_PTR(&match_groups_obj) };
|
|
match_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_span), MP_OBJ_FROM_PTR(&match_span_obj) };
|
|
match_locals_dict_table[3] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_start), MP_OBJ_FROM_PTR(&match_start_obj) };
|
|
match_locals_dict_table[4] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_end), MP_OBJ_FROM_PTR(&match_end_obj) };
|
|
MP_OBJ_TYPE_SET_SLOT(&match_type, locals_dict, (void*)&match_locals_dict, 1);
|
|
|
|
re_type.base.type = (void*)&mp_fun_table.type_type;
|
|
re_type.name = MP_QSTR_re;
|
|
MP_OBJ_TYPE_SET_SLOT(&re_type, print, re_print, 0);
|
|
re_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_match), MP_OBJ_FROM_PTR(&re_match_obj) };
|
|
re_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_search), MP_OBJ_FROM_PTR(&re_search_obj) };
|
|
re_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_split), MP_OBJ_FROM_PTR(&re_split_obj) };
|
|
MP_OBJ_TYPE_SET_SLOT(&re_type, locals_dict, (void*)&re_locals_dict, 1);
|
|
|
|
mp_store_global(MP_QSTR_compile, MP_OBJ_FROM_PTR(&mod_re_compile_obj));
|
|
mp_store_global(MP_QSTR_match, MP_OBJ_FROM_PTR(&re_match_obj));
|
|
mp_store_global(MP_QSTR_search, MP_OBJ_FROM_PTR(&re_search_obj));
|
|
|
|
MP_DYNRUNTIME_INIT_EXIT
|
|
}
|