python / cpython

The Python programming language
https://www.python.org
Other
63.65k stars 30.49k forks source link

The Last Fields of PyInterpreterState and of _PyRuntimeState Should Not Change #127117

Closed ericsnowcurrently closed 3 days ago

ericsnowcurrently commented 4 days ago

The last field of PyInterpreterState should be _initial_thread and the last field of _PyRuntimeState should be _main_interpreter. Respectively, they are the preallocated struct values that are used for the "main" thread and main interpreter.

Having them at the end simplifies some backporting scenarios. It also gives better locality to all the state in the respective interpreter/runtime; otherwise any fields after _initial_thread or _main_interpreter will be separated from the rest by those structs.

I'll make sure there's a note on each struct and that any out-of-place fields are moved up.

Linked PRs