Page 1 of 1

C module globals table: mp_map_elem_t vs mp_rom_map_elem_t [EDIT]

Posted: Sun Nov 11, 2018 2:03 am
by zinahe
Greetings all,

A complete noob here. So be gentle please.

I have seen two variations of the global table in c modules implemented as:

Code: Select all

STATIC const mp_rom_map_elem_t esp_module_globals_table[] = {
    { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_mymodule) },
};

or

Code: Select all

STATIC const mp_map_elem_t global_table[] = {
    { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_mymodule) },
};

I have tried to search in code-base; and both seem to be equally used. I am guessing one would be used to freeze the table in flash and the other in RAM; but I haven't seen anything to confirm that assumption. What are the circumstances where I choose one over the other ? Is this documented somewhere ?

Re: C module globals table: mp_map_elem_t vs mp_rom_map_elem_t

Posted: Sun Nov 11, 2018 4:30 pm
by dhylands
Originally, there was only mp_map_elem_t. The mp_rom_xxx types were introduced to indicate that the particular struct was stored in flash and thus can't be modified.

Many, but not all, of the places have been updated (where appropriate). Personally, I would use mp_rom_map_elem_t for anything new, since the intent is that the local dict tables will be stored in flash.

Re: C module globals table: mp_map_elem_t vs mp_rom_map_elem_t

Posted: Sun Nov 11, 2018 4:50 pm
by zinahe
@dhylands: Thanks a lot.

When one is familiar with the historical context of things, it is pretty straight forward. But you can imagine how confusing it could quickly get for someone who's just getting started with upy.

Cheers,