← index #8144PR #8140
Related · medium · value 2.154
QUERY · ISSUE

RFC: overriding mpconfig(port).h macros

openby stinosopened 2022-01-06updated 2024-09-09
needs-info

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.

CANDIDATE · PULL REQUEST

windows/mpconfigport.h: Allow overriding MICROPY_PORT_BUILTINS.

closedby stinosopened 2022-01-05updated 2022-01-10
py-core

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?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied