diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2017-05-22 21:36:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 21:36:03 -0700 |
commit | 6b4be195cd8868b76eb6fbe166acc39beee8ce36 (patch) | |
tree | bbab44fad32c576b9eb7e4b83368e200adc33f00 /Python/pystate.c | |
parent | f9169ce6b48c7cc7cc62d9eb5e4ee1ac7066d14b (diff) | |
download | cpython-git-6b4be195cd8868b76eb6fbe166acc39beee8ce36.tar.gz |
bpo-22257: Small changes for PEP 432. (#1728)
PEP 432 specifies a number of large changes to interpreter startup code, including exposing a cleaner C-API. The major changes depend on a number of smaller changes. This patch includes all those smaller changes.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 99a579a069..0a4e63b29d 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -46,6 +46,7 @@ static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */ /* The single PyInterpreterState used by this process' GILState implementation */ +/* TODO: Given interp_main, it may be possible to kill this ref */ static PyInterpreterState *autoInterpreterState = NULL; static int autoTLSkey = -1; #else @@ -55,6 +56,7 @@ static int autoTLSkey = -1; #endif static PyInterpreterState *interp_head = NULL; +static PyInterpreterState *interp_main = NULL; /* Assuming the current thread holds the GIL, this is the PyThreadState for the current thread. */ @@ -119,6 +121,9 @@ PyInterpreterState_New(void) HEAD_LOCK(); interp->next = interp_head; + if (interp_main == NULL) { + interp_main = interp; + } interp_head = interp; if (_next_interp_id < 0) { /* overflow or Py_Initialize() not called! */ @@ -185,6 +190,11 @@ PyInterpreterState_Delete(PyInterpreterState *interp) if (interp->tstate_head != NULL) Py_FatalError("PyInterpreterState_Delete: remaining threads"); *p = interp->next; + if (interp_main == interp) { + interp_main = NULL; + if (interp_head != NULL) + Py_FatalError("PyInterpreterState_Delete: remaining subinterpreters"); + } HEAD_UNLOCK(); PyMem_RawFree(interp); #ifdef WITH_THREAD @@ -662,6 +672,12 @@ PyInterpreterState_Head(void) } PyInterpreterState * +PyInterpreterState_Main(void) +{ + return interp_main; +} + +PyInterpreterState * PyInterpreterState_Next(PyInterpreterState *interp) { return interp->next; } |