RFC: overriding mpconfig(port).h macros
Introduction of variants came along with wrapping a bunch of definitions in mpconfigport.h with #ifndef MICROPY_SOME_OPTION because otherwise these couldn't be defined in mpconfigvariant.h anymore. Likewise this also means that a variant cannot define anything which is already defined in mpconfigport.h and is not yet wrapped. Which is not ideal.
A simple solution is allowing to include another file after everything in mpconfigport.h (or even mpconfgh.h). In such file users can then #undef and #define again at will.
So how about adding
#ifdef MP_POSTCONFIGFILE
#include MP_POSTCONFIGFILE
#endif
at the end of mpconfig.h ? (name is chosen for consistency with MP_CONFIGFILE at the top though that doesn't follow naming conventions).
Alternatively this could go at the end of each mpconfigport.h but I'm not sure that is needed.
windows/mpconfigport.h: Allow overriding MICROPY_PORT_BUILTINS.
I'm trying to convert a custom MicroPython version, which is essentially a bunch of additional definitions in mpconfgport.h and extra source files, into a variant. I need a couple of extra Python exceptions available (ConnectionError and TimeoutError etc) so until now I did that by adding an extra source file with MP_DEFINE_EXCEPTION(ConnectionError, OSError) and then adding { MP_ROM_QSTR(MP_QSTR_ConnectionError), MP_ROM_PTR(&mp_type_ConnectionError) }, \ to MICROPY_PORT_BUILTINS.
- is there another way to achieve this?
- perhaps better to not force the variant to completely redefine, but instead introduce e.g.
#define MICROPY_PORT_BUILTINS \
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
MICROPY_PORT_BUILTINS_EXTRA
- should we immediately apply a similar change for MICROPY_PORT_BUILTIN_MODULES as well?
- and apply same changes to the unix port as well?