[Python-checkins] bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal (GH-16558)

Victor Stinner webhook-mailer at python.org
Fri Oct 4 07:35:54 EDT 2019


https://github.com/python/cpython/commit/8855e47d09d4db1206c65b24efc8ad0df585ac46
commit: 8855e47d09d4db1206c65b24efc8ad0df585ac46
branch: master
author: Joannah Nanjekye <33177550+nanjekyejoannah at users.noreply.github.com>
committer: Victor Stinner <vstinner at python.org>
date: 2019-10-04T13:35:42+02:00
summary:

bpo-38266: Revert bpo-37878: Make PyThreadState_DeleteCurrent() Internal (GH-16558)

Revert the removal of PyThreadState_DeleteCurrent() with documentation.

files:
A Misc/NEWS.d/next/C API/2019-10-03-12-53-53.bpo-38266.0FIC1q.rst
M Doc/c-api/init.rst
M Include/cpython/pystate.h
M Python/pystate.c

diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 0b7a84d031532..5456ad446cf23 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -1035,6 +1035,14 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
    :c:func:`PyThreadState_Clear`.
 
 
+   .. c:function:: void PyThreadState_DeleteCurrent()
+
+    Destroy the current thread state and release the global interpreter lock.
+    Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
+    be held. The thread state must have been reset with a previous call
+    to :c:func:`PyThreadState_Clear`.
+
+
 .. c:function:: PY_INT64_T PyInterpreterState_GetID(PyInterpreterState *interp)
 
    Return the interpreter's unique ID.  If there was any error in doing
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index f872351780367..6c8d2ae041ea5 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -183,6 +183,7 @@ PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
 PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
 PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
 PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
+PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
 
 typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
 
diff --git a/Misc/NEWS.d/next/C API/2019-10-03-12-53-53.bpo-38266.0FIC1q.rst b/Misc/NEWS.d/next/C API/2019-10-03-12-53-53.bpo-38266.0FIC1q.rst
new file mode 100644
index 0000000000000..3b4c4232eb897
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2019-10-03-12-53-53.bpo-38266.0FIC1q.rst	
@@ -0,0 +1 @@
+Revert the removal of PyThreadState_DeleteCurrent() with documentation.
\ No newline at end of file
diff --git a/Python/pystate.c b/Python/pystate.c
index f3d89e7d2b256..b4b12472286a3 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -801,7 +801,7 @@ PyThreadState_Clear(PyThreadState *tstate)
 }
 
 
-/* Common code for PyThreadState_Delete() and _PyThreadState_DeleteCurrent() */
+/* Common code for PyThreadState_Delete() and PyThreadState_DeleteCurrent() */
 static void
 tstate_delete_common(_PyRuntimeState *runtime, PyThreadState *tstate)
 {
@@ -857,7 +857,7 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
     PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
     if (tstate == NULL)
         Py_FatalError(
-            "_PyThreadState_DeleteCurrent: no current tstate");
+            "PyThreadState_DeleteCurrent: no current tstate");
     tstate_delete_common(runtime, tstate);
     if (gilstate->autoInterpreterState &&
         PyThread_tss_get(&gilstate->autoTSSkey) == tstate)
@@ -868,6 +868,12 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
     PyEval_ReleaseLock();
 }
 
+void
+PyThreadState_DeleteCurrent(void)
+{
+    _PyThreadState_DeleteCurrent(&_PyRuntime);
+}
+
 
 /*
  * Delete all thread states except the one passed as argument.



More information about the Python-checkins mailing list