mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-30860: Consolidate stateful runtime globals. (#3397)
* group the (stateful) runtime globals into various topical structs * consolidate the topical structs under a single top-level _PyRuntimeState struct * add a check-c-globals.py script that helps identify runtime globals Other globals are excluded (see globals.txt and check-c-globals.py).
This commit is contained in:
parent
bab21faded
commit
2ebc5ce42a
72 changed files with 2746 additions and 1312 deletions
|
@ -3,11 +3,11 @@
|
|||
/* Interface to Sjoerd's portable C thread library */
|
||||
|
||||
#include "Python.h"
|
||||
#include "internal/pystate.h"
|
||||
#include "structmember.h" /* offsetof */
|
||||
#include "pythread.h"
|
||||
|
||||
static PyObject *ThreadError;
|
||||
static long nb_threads = 0;
|
||||
static PyObject *str_dict;
|
||||
|
||||
_Py_IDENTIFIER(stderr);
|
||||
|
@ -986,7 +986,7 @@ t_bootstrap(void *boot_raw)
|
|||
tstate->thread_id = PyThread_get_thread_ident();
|
||||
_PyThreadState_Init(tstate);
|
||||
PyEval_AcquireThread(tstate);
|
||||
nb_threads++;
|
||||
tstate->interp->num_threads++;
|
||||
res = PyObject_Call(boot->func, boot->args, boot->keyw);
|
||||
if (res == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_SystemExit))
|
||||
|
@ -1013,7 +1013,7 @@ t_bootstrap(void *boot_raw)
|
|||
Py_DECREF(boot->args);
|
||||
Py_XDECREF(boot->keyw);
|
||||
PyMem_DEL(boot_raw);
|
||||
nb_threads--;
|
||||
tstate->interp->num_threads--;
|
||||
PyThreadState_Clear(tstate);
|
||||
PyThreadState_DeleteCurrent();
|
||||
PyThread_exit_thread();
|
||||
|
@ -1152,7 +1152,8 @@ A thread's identity may be reused for another thread after it exits.");
|
|||
static PyObject *
|
||||
thread__count(PyObject *self)
|
||||
{
|
||||
return PyLong_FromLong(nb_threads);
|
||||
PyThreadState *tstate = PyThreadState_Get();
|
||||
return PyLong_FromLong(tstate->interp->num_threads);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_count_doc,
|
||||
|
@ -1345,6 +1346,7 @@ PyInit__thread(void)
|
|||
PyObject *m, *d, *v;
|
||||
double time_max;
|
||||
double timeout_max;
|
||||
PyThreadState *tstate = PyThreadState_Get();
|
||||
|
||||
/* Initialize types: */
|
||||
if (PyType_Ready(&localdummytype) < 0)
|
||||
|
@ -1389,7 +1391,7 @@ PyInit__thread(void)
|
|||
if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0)
|
||||
return NULL;
|
||||
|
||||
nb_threads = 0;
|
||||
tstate->interp->num_threads = 0;
|
||||
|
||||
str_dict = PyUnicode_InternFromString("__dict__");
|
||||
if (str_dict == NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue