Index: Python/pystate.c =================================================================== --- Python/pystate.c (révision 84618) +++ Python/pystate.c (copie de travail) @@ -39,6 +39,8 @@ */ static PyInterpreterState *autoInterpreterState = NULL; static int autoTLSkey = 0; +static int autoTLSkey_initialized = 0; + #else #define HEAD_INIT() /* Nothing */ #define HEAD_LOCK() /* Nothing */ @@ -340,7 +342,8 @@ Py_FatalError("PyThreadState_Delete: tstate is still current"); tstate_delete_common(tstate); #ifdef WITH_THREAD - if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate) + if (autoTLSkey_initialized + && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); #endif /* WITH_THREAD */ } @@ -357,7 +360,8 @@ "PyThreadState_DeleteCurrent: no current tstate"); _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); tstate_delete_common(tstate); - if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate) + if (autoTLSkey_initialized + && PyThread_get_key_value(autoTLSkey) == tstate) PyThread_delete_key_value(autoTLSkey); PyEval_ReleaseLock(); } @@ -569,6 +573,7 @@ { assert(i && t); /* must init with valid states */ autoTLSkey = PyThread_create_key(); + autoTLSkey_initialized = 1; autoInterpreterState = i; assert(PyThread_get_key_value(autoTLSkey) == NULL); assert(t->gilstate_counter == 0); @@ -581,6 +586,7 @@ { PyThread_delete_key(autoTLSkey); autoTLSkey = 0; + autoTLSkey_initialized = 0; autoInterpreterState = NULL; } @@ -592,10 +598,10 @@ static void _PyGILState_NoteThreadState(PyThreadState* tstate) { - /* If autoTLSkey is 0, this must be the very first threadstate created - in Py_Initialize(). Don't do anything for now (we'll be back here - when _PyGILState_Init is called). */ - if (!autoTLSkey) + /* If autoTLSkey isn't initialized, this must be the very first + threadstate created in Py_Initialize(). Don't do anything for now + (we'll be back here when _PyGILState_Init is called). */ + if (!autoTLSkey_initialized) return; /* Stick the thread state for this thread in thread local storage. @@ -623,7 +629,7 @@ PyThreadState * PyGILState_GetThisThreadState(void) { - if (autoInterpreterState == NULL || autoTLSkey == 0) + if (autoInterpreterState == NULL || autoTLSkey_initialized == 0) return NULL; return (PyThreadState *)PyThread_get_key_value(autoTLSkey); }