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

@ -617,7 +617,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
}
else {
/* Last resort: use the main interpreter */
interp = _PyRuntime.interpreters.main;
interp = _PyInterpreterState_Main();
}
return _PyEval_AddPendingCall(interp, func, arg);
}