Skip to content

Commit b4d0cce

Browse files
make pyThreadState_DeleteCurrent internal
1 parent 5034af8 commit b4d0cce

File tree

6 files changed

+8
-19
lines changed

6 files changed

+8
-19
lines changed

Doc/c-api/init.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,12 +1023,6 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
10231023
The thread state must have been reset with a previous call to
10241024
:c:func:`PyThreadState_Clear`.
10251025
1026-
.. c:function:: void PyThreadState_DeleteCurrent()
1027-
1028-
Destroy the current thread state and release the global interpreter lock.
1029-
interpreter lock need not be held. Like :c:func:`PyThreadState_Delete`, the global
1030-
interpreter lock need not be held. When using :c:func:`PyThreadState_DeleteCurrent`, the thread state must have been reset with a previous
1031-
call to :c:func:`PyThreadState_Clear`.
10321026
10331027
.. c:function:: PY_INT64_T PyInterpreterState_GetID(PyInterpreterState *interp)
10341028

Include/internal/pycore_pylifecycle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ PyAPI_FUNC(void) _PyErr_Print(PyThreadState *tstate);
109109
PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception,
110110
PyObject *value, PyObject *tb);
111111

112+
PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime);
113+
112114
#ifdef __cplusplus
113115
}
114116
#endif

Include/pystate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
5050
PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
5151
PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
5252
PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
53-
PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
5453

5554
/* Get the current thread state.
5655

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ t_bootstrap(void *boot_raw)
10251025
PyMem_DEL(boot_raw);
10261026
tstate->interp->num_threads--;
10271027
PyThreadState_Clear(tstate);
1028-
PyThreadState_DeleteCurrent();
1028+
_PyThreadState_DeleteCurrent(&_PyRuntime);
10291029
PyThread_exit_thread();
10301030
}
10311031

Modules/_tracemalloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static struct {
3434
#if defined(TRACE_RAW_MALLOC)
3535
/* This lock is needed because tracemalloc_free() is called without
3636
the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
37-
would introduce a deadlock in PyThreadState_DeleteCurrent(). */
37+
would introduce a deadlock in _PyThreadState_DeleteCurrent(). */
3838
static PyThread_type_lock tables_lock;
3939
# define TABLES_LOCK() PyThread_acquire_lock(tables_lock, 1)
4040
# define TABLES_UNLOCK() PyThread_release_lock(tables_lock)
@@ -728,7 +728,7 @@ tracemalloc_free(void *ctx, void *ptr)
728728
return;
729729

730730
/* GIL cannot be locked in PyMem_RawFree() because it would introduce
731-
a deadlock in PyThreadState_DeleteCurrent(). */
731+
a deadlock in _PyThreadState_DeleteCurrent(). */
732732

733733
alloc->free(alloc->ctx, ptr);
734734

Python/pystate.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ PyThreadState_Clear(PyThreadState *tstate)
809809
}
810810

811811

812-
/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
812+
/* Common code for PyThreadState_Delete() and _PyThreadState_DeleteCurrent() */
813813
static void
814814
tstate_delete_common(_PyRuntimeState *runtime, PyThreadState *tstate)
815815
{
@@ -858,14 +858,14 @@ PyThreadState_Delete(PyThreadState *tstate)
858858
}
859859

860860

861-
static void
861+
void
862862
_PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
863863
{
864864
struct _gilstate_runtime_state *gilstate = &runtime->gilstate;
865865
PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
866866
if (tstate == NULL)
867867
Py_FatalError(
868-
"PyThreadState_DeleteCurrent: no current tstate");
868+
"_PyThreadState_DeleteCurrent: no current tstate");
869869
tstate_delete_common(runtime, tstate);
870870
if (gilstate->autoInterpreterState &&
871871
PyThread_tss_get(&gilstate->autoTSSkey) == tstate)
@@ -876,12 +876,6 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
876876
PyEval_ReleaseLock();
877877
}
878878

879-
void
880-
PyThreadState_DeleteCurrent()
881-
{
882-
_PyThreadState_DeleteCurrent(&_PyRuntime);
883-
}
884-
885879

886880
/*
887881
* Delete all thread states except the one passed as argument.

0 commit comments

Comments
 (0)