← index #12228PR #12436
Duplicate · high · value 7.887
QUERY · ISSUE

Consider renaming `MP_STATE_PORT`

openby jimmoopened 2023-08-15updated 2023-09-13
enhancement

Before MP_REGISTER_ROOT_POINTER was added, a port could define additional root pointers in its mpconfigport.h. It made sense to refer to them via a distinct macro, hence MP_STATE_PORT, even though all ports alias that to MP_STATE_VM.

Now the MP_REGISTER_ROOT_POINTER feature can be used to implement root pointers for modules that mpstate.h does not know about, such as modules in extmod, or user c module. We could also consider moving some config-optional stuff that's currently in mpstate.h to use MP_REGISTER_ROOT_POINTER. But things defined with MP_REGISTER_ROOT_POINTER are no longer "port". So for example, in modbluetooth_nimble.c we use MP_STATE_PORT(bluetooth_nimble_root_pointers), but the only thing that's "port" about them is that bluetooth can be enabled by the port/board.

So I see three options:

  1. Remove MP_STATE_PORT and just change everything to use MP_STATE_MEM.
  2. Replace MP_STATE_PORT with MP_STATE_ROOT_POINTER and have that aliased to MP_STATE_VM in a common location (i.e. not ports' mpconfigport.h).
  3. Same as (2) but move the generated root pointers into their own struct, and add a fourth field (between thread and vm) on mp_state_ctx_t, and have MP_STATE_ROOT_POINTER access that specifically.

(My vote is for (3), these variables are no more "vm" than they are "port", and should find a new home )

FWIW, This came up as a question on Discord because the embed port does not define MP_STATE_PORT.

CANDIDATE · PULL REQUEST

all: Replace MP_STATE_PORT with MP_STATE_ROOT.

openby jimmoopened 2023-09-13updated 2024-01-16
py-core

Implements option (3) from #12228. cc @robert-hh @dlech


Before MP_REGISTER_ROOT_POINTER was added, a port could define additional
root pointers in its mpconfigport.h. It made sense to refer to them via a
distinct macro, hence MP_STATE_PORT, even though all ports alias that to
MP_STATE_VM.

Now the MP_REGISTER_ROOT_POINTER feature can be used to implement root
pointers for modules that mpstate.h does not know about, such as modules in
extmod, or user c module. We could also consider moving some
config-optional stuff that's currently in mpstate.h to use
MP_REGISTER_ROOT_POINTER. But things defined with MP_REGISTER_ROOT_POINTER
are no longer "port". So for example, in modbluetooth_nimble.c we use
MP_STATE_PORT(bluetooth_nimble_root_pointers), but the only thing that's
"port" about them is that bluetooth can be enabled by the port/board.

This renames all previous uses of MP_STATE_PORT to the new MP_STATE_ROOT.

Furthermore, it moves the generated entries out of the mp_state_vm_t
structure and into an new mp_state_root_t structure that sits between
thread and vm (so it's still part of root pointer searching).

Also fixes several cases where MP_STATE_VM was incorrectly used for what
should be now MP_STATE_ROOT.

Other than the logical improvement, it also means that ports no longer
have to define MP_STATE_PORT (one less thing to duplicate in
mpconfigport.h).

This work was funded through GitHub Sponsors.

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