summaryrefslogtreecommitdiff
path: root/Python/pystate.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 24e20c3e23..65c244e6f7 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -6,7 +6,7 @@
#define GET_TSTATE() \
((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
#define SET_TSTATE(value) \
- _Py_atomic_store_relaxed(&_PyThreadState_Current, (Py_uintptr_t)(value))
+ _Py_atomic_store_relaxed(&_PyThreadState_Current, (uintptr_t)(value))
#define GET_INTERP_STATE() \
(GET_TSTATE()->interp)
@@ -25,7 +25,7 @@ to avoid the expense of doing their own locking).
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif
-#ifndef RTLD_LAZY
+#if !HAVE_DECL_RTLD_LAZY
#define RTLD_LAZY 1
#endif
#endif
@@ -34,6 +34,8 @@ to avoid the expense of doing their own locking).
extern "C" {
#endif
+int _PyGILState_check_enabled = 1;
+
#ifdef WITH_THREAD
#include "pythread.h"
static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */
@@ -45,7 +47,7 @@ static PyThread_type_lock head_mutex = NULL; /* Protects interp->tstate_head */
GILState implementation
*/
static PyInterpreterState *autoInterpreterState = NULL;
-static int autoTLSkey = 0;
+static int autoTLSkey = -1;
#else
#define HEAD_INIT() /* Nothing */
#define HEAD_LOCK() /* Nothing */
@@ -88,16 +90,15 @@ PyInterpreterState_New(void)
interp->codecs_initialized = 0;
interp->fscodec_initialized = 0;
interp->importlib = NULL;
+ interp->import_func = NULL;
+ interp->eval_frame = _PyEval_EvalFrameDefault;
#ifdef HAVE_DLOPEN
-#ifdef RTLD_NOW
+#if HAVE_DECL_RTLD_NOW
interp->dlopenflags = RTLD_NOW;
#else
interp->dlopenflags = RTLD_LAZY;
#endif
#endif
-#ifdef WITH_TSC
- interp->tscdump = 0;
-#endif
HEAD_LOCK();
interp->next = interp_head;
@@ -126,6 +127,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
Py_CLEAR(interp->builtins);
Py_CLEAR(interp->builtins_copy);
Py_CLEAR(interp->importlib);
+ Py_CLEAR(interp->import_func);
}
@@ -222,6 +224,10 @@ new_threadstate(PyInterpreterState *interp, int init)
tstate->coroutine_wrapper = NULL;
tstate->in_coroutine_wrapper = 0;
+ tstate->co_extra_user_count = 0;
+
+ tstate->async_gen_firstiter = NULL;
+ tstate->async_gen_finalizer = NULL;
if (init)
_PyThreadState_Init(tstate);
@@ -402,6 +408,8 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->c_traceobj);
Py_CLEAR(tstate->coroutine_wrapper);
+ Py_CLEAR(tstate->async_gen_firstiter);
+ Py_CLEAR(tstate->async_gen_finalizer);
}
@@ -451,10 +459,10 @@ PyThreadState_DeleteCurrent()
if (tstate == NULL)
Py_FatalError(
"PyThreadState_DeleteCurrent: no current tstate");
- SET_TSTATE(NULL);
+ tstate_delete_common(tstate);
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
PyThread_delete_key_value(autoTLSkey);
- tstate_delete_common(tstate);
+ SET_TSTATE(NULL);
PyEval_ReleaseLock();
}
#endif /* WITH_THREAD */
@@ -698,7 +706,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
}
/* Internal initialization/finalization functions called by
- Py_Initialize/Py_Finalize
+ Py_Initialize/Py_FinalizeEx
*/
void
_PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
@@ -714,10 +722,17 @@ _PyGILState_Init(PyInterpreterState *i, PyThreadState *t)
_PyGILState_NoteThreadState(t);
}
+PyInterpreterState *
+_PyGILState_GetInterpreterStateUnsafe(void)
+{
+ return autoInterpreterState;
+}
+
void
_PyGILState_Fini(void)
{
PyThread_delete_key(autoTLSkey);
+ autoTLSkey = -1;
autoInterpreterState = NULL;
}
@@ -786,8 +801,19 @@ PyGILState_GetThisThreadState(void)
int
PyGILState_Check(void)
{
- PyThreadState *tstate = GET_TSTATE();
- return tstate && (tstate == PyGILState_GetThisThreadState());
+ PyThreadState *tstate;
+
+ if (!_PyGILState_check_enabled)
+ return 1;
+
+ if (autoTLSkey == -1)
+ return 1;
+
+ tstate = GET_TSTATE();
+ if (tstate == NULL)
+ return 0;
+
+ return (tstate == PyGILState_GetThisThreadState());
}
PyGILState_STATE