bpo-45953: Statically allocate the main interpreter (and initial thread state). (gh-29883)

Previously, the main interpreter was allocated on the heap during runtime initialization.  Here we instead embed it into _PyRuntimeState, which means it is statically allocated as part of the _PyRuntime global.  The same goes for the initial thread state (of each interpreter, including the main one).  Consequently there are fewer allocations during runtime/interpreter init, fewer possible failures, and better memory locality.

FYI, this also helps efforts to consolidate globals, which in turns helps work on subinterpreter isolation.

https://bugs.python.org/issue45953
This commit is contained in:
Eric Snow 2022-01-12 16:28:46 -07:00 committed by GitHub
parent 0bbf30e2b9
commit ed57b36c32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 34 deletions

View file

@ -292,7 +292,7 @@ trip_signal(int sig_num)
_Py_atomic_store(&is_tripped, 1);
/* Signals are always handled by the main interpreter */
PyInterpreterState *interp = _PyRuntime.interpreters.main;
PyInterpreterState *interp = _PyInterpreterState_Main();
/* Notify ceval.c */
_PyEval_SignalReceived(interp);