Skip to content

Commit 079ce54

Browse files
committed
Issue #9797: pystate.c wrongly assumed that zero couldn't be a valid
thread-local storage key.
1 parent 121a1c4 commit 079ce54

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Alpha 3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9797: pystate.c wrongly assumed that zero couldn't be a valid
14+
thread-local storage key.
15+
1316
Library
1417
-------
1518

Python/pystate.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ PyThreadState_Delete(PyThreadState *tstate)
340340
Py_FatalError("PyThreadState_Delete: tstate is still current");
341341
tstate_delete_common(tstate);
342342
#ifdef WITH_THREAD
343-
if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate)
343+
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
344344
PyThread_delete_key_value(autoTLSkey);
345345
#endif /* WITH_THREAD */
346346
}
@@ -357,7 +357,7 @@ PyThreadState_DeleteCurrent()
357357
"PyThreadState_DeleteCurrent: no current tstate");
358358
_Py_atomic_store_relaxed(&_PyThreadState_Current, NULL);
359359
tstate_delete_common(tstate);
360-
if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate)
360+
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
361361
PyThread_delete_key_value(autoTLSkey);
362362
PyEval_ReleaseLock();
363363
}
@@ -580,7 +580,6 @@ void
580580
_PyGILState_Fini(void)
581581
{
582582
PyThread_delete_key(autoTLSkey);
583-
autoTLSkey = 0;
584583
autoInterpreterState = NULL;
585584
}
586585

@@ -592,10 +591,10 @@ _PyGILState_Fini(void)
592591
static void
593592
_PyGILState_NoteThreadState(PyThreadState* tstate)
594593
{
595-
/* If autoTLSkey is 0, this must be the very first threadstate created
596-
in Py_Initialize(). Don't do anything for now (we'll be back here
597-
when _PyGILState_Init is called). */
598-
if (!autoTLSkey)
594+
/* If autoTLSkey isn't initialized, this must be the very first
595+
threadstate created in Py_Initialize(). Don't do anything for now
596+
(we'll be back here when _PyGILState_Init is called). */
597+
if (!autoInterpreterState)
599598
return;
600599

601600
/* Stick the thread state for this thread in thread local storage.
@@ -623,7 +622,7 @@ _PyGILState_NoteThreadState(PyThreadState* tstate)
623622
PyThreadState *
624623
PyGILState_GetThisThreadState(void)
625624
{
626-
if (autoInterpreterState == NULL || autoTLSkey == 0)
625+
if (autoInterpreterState == NULL)
627626
return NULL;
628627
return (PyThreadState *)PyThread_get_key_value(autoTLSkey);
629628
}

0 commit comments

Comments
 (0)