Skip to content

Commit 3ff16ff

Browse files
committed
py: Declare constant data as properly constant.
Otherwise some compilers (eg without optimisation) will put this read-only data in RAM instead of ROM.
1 parent a0a08b4 commit 3ff16ff

7 files changed

Lines changed: 8 additions & 8 deletions

File tree

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns)
26492649
}
26502650

26512651
typedef void (*compile_function_t)(compiler_t*, mp_parse_node_struct_t*);
2652-
STATIC compile_function_t compile_function[] = {
2652+
STATIC const compile_function_t compile_function[] = {
26532653
#define nc NULL
26542654
#define c(f) compile_##f
26552655
#define DEF_RULE(rule, comp, kind, ...) comp,

py/lexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ STATIC void indent_pop(mp_lexer_t *lex) {
190190
// c<op> = continue with <op>, if this opchar matches then continue matching
191191
// this means if the start of two ops are the same then they are equal til the last char
192192

193-
STATIC const char *tok_enc =
193+
STATIC const char *const tok_enc =
194194
"()[]{},:;@~" // singles
195195
"<e=c<e=" // < <= << <<=
196196
">e=c>e=" // > >= >> >>=
@@ -227,7 +227,7 @@ STATIC const uint8_t tok_enc_kind[] = {
227227
};
228228

229229
// must have the same order as enum in lexer.h
230-
STATIC const char *tok_kw[] = {
230+
STATIC const char *const tok_kw[] = {
231231
"False",
232232
"None",
233233
"True",

py/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const mp_map_t mp_const_empty_map = {
4949
// The first set of sizes are chosen so the allocation fits exactly in a
5050
// 4-word GC block, and it's not so important for these small values to be
5151
// prime. The latter sizes are prime and increase at an increasing rate.
52-
STATIC uint16_t hash_allocation_sizes[] = {
52+
STATIC const uint16_t hash_allocation_sizes[] = {
5353
0, 2, 4, 6, 8, 10, 12, // +2
5454
17, 23, 29, 37, 47, 59, 73, // *1.25
5555
97, 127, 167, 223, 293, 389, 521, 691, 919, 1223, 1627, 2161, // *1.33

py/objdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ typedef enum _mp_dict_view_kind_t {
414414
MP_DICT_VIEW_VALUES,
415415
} mp_dict_view_kind_t;
416416

417-
STATIC char *mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"};
417+
STATIC const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"};
418418

419419
typedef struct _mp_obj_dict_view_it_t {
420420
mp_obj_base_t base;

py/parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ enum {
104104
#undef one_or_more
105105
#undef DEF_RULE
106106

107-
STATIC const rule_t *rules[] = {
107+
STATIC const rule_t *const rules[] = {
108108
#define DEF_RULE(rule, comp, kind, ...) &rule_##rule,
109109
#include "py/grammar.h"
110110
#undef DEF_RULE

py/repl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
223223
// If there're no better alternatives, and if it's first word
224224
// in the line, try to complete "import".
225225
if (s_start == org_str) {
226-
static char import_str[] = "import ";
226+
static const char import_str[] = "import ";
227227
if (memcmp(s_start, import_str, s_len) == 0) {
228228
*compl_str = import_str + s_len;
229229
return sizeof(import_str) - 1 - s_len;

py/vmentrytable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#pragma clang diagnostic ignored "-Winitializer-overrides"
3030
#endif // __clang__
3131

32-
static void* entry_table[256] = {
32+
static const void *const entry_table[256] = {
3333
[0 ... 255] = &&entry_default,
3434
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
3535
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,

0 commit comments

Comments
 (0)