Page 1 of 1

mpconfigport.h module definitions

Posted: Tue Sep 21, 2021 3:11 pm
by hippy

Code: Select all

#define MICROPY_PORT_BUILTIN_MODULES \
    { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&mp_module_machine }, \
    { MP_OBJ_NEW_QSTR(MP_QSTR__onewire), (mp_obj_t)&mp_module_onewire }, \
    { MP_OBJ_NEW_QSTR(MP_QSTR__rp2), (mp_obj_t)&mp_module_rp2 }, \
    { MP_ROM_QSTR(MP_QSTR_uos), MP_ROM_PTR(&mp_module_uos) }, \
    { MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&mp_module_utime) }, \
Can anyone explain why there are two different styles for defining built-in modules or point me to the explanatory documentation ?

Re: mpconfigport.h module definitions

Posted: Wed Sep 22, 2021 7:38 am
by stijn
Should probably be MP_ROM_QSTR everywhere. I think MP_ROM_QSTR is the same as MP_OBJ_NEW_QSTR everywhere, but it exists for consistency with MP_ROM_PTR and MP_ROM_INT. See https://github.com/micropython/micropython/pull/1655

Re: mpconfigport.h module definitions

Posted: Wed Sep 22, 2021 9:58 am
by hippy
Thanks I discovered that in adding new modules to my own build I had used a mix of both depending on which I had copied and pasted. It seemed to work regardless but I wasn't sure if I had created some hidden problem which would come back and bite me.