py: Declare constant data as properly constant.

Otherwise some compilers (eg without optimisation) will put this read-only
data in RAM instead of ROM.
This commit is contained in:
Damien George 2016-05-20 12:38:15 +01:00
parent a0a08b4be1
commit 3ff16ff52e
7 changed files with 8 additions and 8 deletions

View File

@ -2649,7 +2649,7 @@ STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns)
} }
typedef void (*compile_function_t)(compiler_t*, mp_parse_node_struct_t*); typedef void (*compile_function_t)(compiler_t*, mp_parse_node_struct_t*);
STATIC compile_function_t compile_function[] = { STATIC const compile_function_t compile_function[] = {
#define nc NULL #define nc NULL
#define c(f) compile_##f #define c(f) compile_##f
#define DEF_RULE(rule, comp, kind, ...) comp, #define DEF_RULE(rule, comp, kind, ...) comp,

View File

@ -190,7 +190,7 @@ STATIC void indent_pop(mp_lexer_t *lex) {
// c<op> = continue with <op>, if this opchar matches then continue matching // c<op> = continue with <op>, if this opchar matches then continue matching
// this means if the start of two ops are the same then they are equal til the last char // this means if the start of two ops are the same then they are equal til the last char
STATIC const char *tok_enc = STATIC const char *const tok_enc =
"()[]{},:;@~" // singles "()[]{},:;@~" // singles
"<e=c<e=" // < <= << <<= "<e=c<e=" // < <= << <<=
">e=c>e=" // > >= >> >>= ">e=c>e=" // > >= >> >>=
@ -227,7 +227,7 @@ STATIC const uint8_t tok_enc_kind[] = {
}; };
// must have the same order as enum in lexer.h // must have the same order as enum in lexer.h
STATIC const char *tok_kw[] = { STATIC const char *const tok_kw[] = {
"False", "False",
"None", "None",
"True", "True",

View File

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

View File

@ -414,7 +414,7 @@ typedef enum _mp_dict_view_kind_t {
MP_DICT_VIEW_VALUES, MP_DICT_VIEW_VALUES,
} mp_dict_view_kind_t; } mp_dict_view_kind_t;
STATIC char *mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"}; STATIC const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"};
typedef struct _mp_obj_dict_view_it_t { typedef struct _mp_obj_dict_view_it_t {
mp_obj_base_t base; mp_obj_base_t base;

View File

@ -104,7 +104,7 @@ enum {
#undef one_or_more #undef one_or_more
#undef DEF_RULE #undef DEF_RULE
STATIC const rule_t *rules[] = { STATIC const rule_t *const rules[] = {
#define DEF_RULE(rule, comp, kind, ...) &rule_##rule, #define DEF_RULE(rule, comp, kind, ...) &rule_##rule,
#include "py/grammar.h" #include "py/grammar.h"
#undef DEF_RULE #undef DEF_RULE

View File

@ -223,7 +223,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
// If there're no better alternatives, and if it's first word // If there're no better alternatives, and if it's first word
// in the line, try to complete "import". // in the line, try to complete "import".
if (s_start == org_str) { if (s_start == org_str) {
static char import_str[] = "import "; static const char import_str[] = "import ";
if (memcmp(s_start, import_str, s_len) == 0) { if (memcmp(s_start, import_str, s_len) == 0) {
*compl_str = import_str + s_len; *compl_str = import_str + s_len;
return sizeof(import_str) - 1 - s_len; return sizeof(import_str) - 1 - s_len;

View File

@ -29,7 +29,7 @@
#pragma clang diagnostic ignored "-Winitializer-overrides" #pragma clang diagnostic ignored "-Winitializer-overrides"
#endif // __clang__ #endif // __clang__
static void* entry_table[256] = { static const void *const entry_table[256] = {
[0 ... 255] = &&entry_default, [0 ... 255] = &&entry_default,
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE, [MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE, [MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,