Skip to content

Commit 8855e47

Browse files
nanjekyejoannahvstinner
authored andcommitted
bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal (GH-16558)
Revert the removal of PyThreadState_DeleteCurrent() with documentation.
1 parent 06cb94b commit 8855e47

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Doc/c-api/init.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,14 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
10351035
:c:func:`PyThreadState_Clear`.
10361036
10371037
1038+
.. c:function:: void PyThreadState_DeleteCurrent()
1039+
1040+
Destroy the current thread state and release the global interpreter lock.
1041+
Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
1042+
be held. The thread state must have been reset with a previous call
1043+
to :c:func:`PyThreadState_Clear`.
1044+
1045+
10381046
.. c:function:: PY_INT64_T PyInterpreterState_GetID(PyInterpreterState *interp)
10391047
10401048
Return the interpreter's unique ID. If there was any error in doing

Include/cpython/pystate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
183183
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
184184
PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
185185
PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
186+
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
186187

187188
typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
188189

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Revert the removal of PyThreadState_DeleteCurrent() with documentation.

Python/pystate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ PyThreadState_Clear(PyThreadState *tstate)
801801
}
802802

803803

804-
/* Common code for PyThreadState_Delete() and _PyThreadState_DeleteCurrent() */
804+
/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
805805
static void
806806
tstate_delete_common(_PyRuntimeState *runtime, PyThreadState *tstate)
807807
{
@@ -857,7 +857,7 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
857857
PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
858858
if (tstate == NULL)
859859
Py_FatalError(
860-
"_PyThreadState_DeleteCurrent: no current tstate");
860+
"PyThreadState_DeleteCurrent: no current tstate");
861861
tstate_delete_common(runtime, tstate);
862862
if (gilstate->autoInterpreterState &&
863863
PyThread_tss_get(&gilstate->autoTSSkey) == tstate)
@@ -868,6 +868,12 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
868868
PyEval_ReleaseLock();
869869
}
870870

871+
void
872+
PyThreadState_DeleteCurrent(void)
873+
{
874+
_PyThreadState_DeleteCurrent(&_PyRuntime);
875+
}
876+
871877

872878
/*
873879
* Delete all thread states except the one passed as argument.

0 commit comments

Comments
 (0)