[Python-checkins] bpo-37878: Remove PyThreadState_DeleteCurrent() function (GH-15315)

Victor Stinner webhook-mailer at python.org
Thu Sep 5 12:06:55 EDT 2019


https://github.com/python/cpython/commit/2bc43cdc015eda4f1a651bb2b308a17a83c38e14
commit: 2bc43cdc015eda4f1a651bb2b308a17a83c38e14
branch: master
author: Joannah Nanjekye <33177550+nanjekyejoannah at users.noreply.github.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019年09月05日T18:06:49+02:00
summary:
bpo-37878: Remove PyThreadState_DeleteCurrent() function (GH-15315)
* Rename PyThreadState_DeleteCurrent()
 to _PyThreadState_DeleteCurrent()
* Move it to the internal C API
Co-Authored-By: Carol Willing <carolcode at willingconsulting.com>
files:
A Misc/NEWS.d/next/Documentation/2019-08-16-20-01-10.bpo-37878.MvA6rZ.rst
M Doc/whatsnew/3.9.rst
M Include/internal/pycore_pylifecycle.h
M Include/pystate.h
M Modules/_threadmodule.c
M Modules/_tracemalloc.c
M Python/pystate.c
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst
index 009a66adff7d..756690d93793 100644
--- a/Doc/whatsnew/3.9.rst
+++ b/Doc/whatsnew/3.9.rst
@@ -219,6 +219,9 @@ Removed
 standard :class:`bytes` objects are always used.
 (Contributed by Jon Janzen in :issue:`36409`.)
 
+* ``PyThreadState_DeleteCurrent()`` has been removed. It was not documented.
+ (Contributed by Joannah Nanjekye in :issue:`37878`.)
+
 
 Porting to Python 3.9
 =====================
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h
index 7ea4488a9364..cf844cc063f8 100644
--- a/Include/internal/pycore_pylifecycle.h
+++ b/Include/internal/pycore_pylifecycle.h
@@ -110,6 +110,8 @@ PyAPI_FUNC(void) _PyErr_Print(PyThreadState *tstate);
 PyAPI_FUNC(void) _PyErr_Display(PyObject *file, PyObject *exception,
 PyObject *value, PyObject *tb);
 
+PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/pystate.h b/Include/pystate.h
index 4c25e3f7ef84..1cb2305696f2 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -50,7 +50,6 @@ PyAPI_FUNC(PyObject*) PyState_FindModule(struct PyModuleDef*);
 PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
 PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
 PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
-PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
 
 /* Get the current thread state.
 
diff --git a/Misc/NEWS.d/next/Documentation/2019-08-16-20-01-10.bpo-37878.MvA6rZ.rst b/Misc/NEWS.d/next/Documentation/2019-08-16-20-01-10.bpo-37878.MvA6rZ.rst
new file mode 100644
index 000000000000..8da4eb9717d8
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2019-08-16-20-01-10.bpo-37878.MvA6rZ.rst
@@ -0,0 +1 @@
+Make :c:func:`PyThreadState_DeleteCurrent` Internal.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index a3ecd2e74e8c..1c7df3f87414 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -993,6 +993,7 @@ struct bootstate {
 PyObject *args;
 PyObject *keyw;
 PyThreadState *tstate;
+ _PyRuntimeState *runtime;
 };
 
 static void
@@ -1000,11 +1001,13 @@ t_bootstrap(void *boot_raw)
 {
 struct bootstate *boot = (struct bootstate *) boot_raw;
 PyThreadState *tstate;
+ _PyRuntimeState *runtime;
 PyObject *res;
 
+ runtime = boot->runtime;
 tstate = boot->tstate;
 tstate->thread_id = PyThread_get_thread_ident();
- _PyThreadState_Init(&_PyRuntime, tstate);
+ _PyThreadState_Init(runtime, tstate);
 PyEval_AcquireThread(tstate);
 tstate->interp->num_threads++;
 res = PyObject_Call(boot->func, boot->args, boot->keyw);
@@ -1025,13 +1028,14 @@ t_bootstrap(void *boot_raw)
 PyMem_DEL(boot_raw);
 tstate->interp->num_threads--;
 PyThreadState_Clear(tstate);
- PyThreadState_DeleteCurrent();
+ _PyThreadState_DeleteCurrent(runtime);
 PyThread_exit_thread();
 }
 
 static PyObject *
 thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
 {
+ _PyRuntimeState *runtime = &_PyRuntime;
 PyObject *func, *args, *keyw = NULL;
 struct bootstate *boot;
 unsigned long ident;
@@ -1062,6 +1066,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
 boot->args = args;
 boot->keyw = keyw;
 boot->tstate = _PyThreadState_Prealloc(boot->interp);
+ boot->runtime = runtime;
 if (boot->tstate == NULL) {
 PyMem_DEL(boot);
 return PyErr_NoMemory();
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index ee32ac29b7ee..26d76004aaa5 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -34,7 +34,7 @@ static struct {
 #if defined(TRACE_RAW_MALLOC)
 /* This lock is needed because tracemalloc_free() is called without
 the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
- would introduce a deadlock in PyThreadState_DeleteCurrent(). */
+ would introduce a deadlock in _PyThreadState_DeleteCurrent(). */
 static PyThread_type_lock tables_lock;
 # define TABLES_LOCK() PyThread_acquire_lock(tables_lock, 1)
 # define TABLES_UNLOCK() PyThread_release_lock(tables_lock)
@@ -728,7 +728,7 @@ tracemalloc_free(void *ctx, void *ptr)
 return;
 
 /* GIL cannot be locked in PyMem_RawFree() because it would introduce
- a deadlock in PyThreadState_DeleteCurrent(). */
+ a deadlock in _PyThreadState_DeleteCurrent(). */
 
 alloc->free(alloc->ctx, ptr);
 
diff --git a/Python/pystate.c b/Python/pystate.c
index dc5240048ba0..02bc90394361 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -809,7 +809,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)
 {
@@ -858,14 +858,14 @@ PyThreadState_Delete(PyThreadState *tstate)
 }
 
 
-static void
+void
 _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
 {
 struct _gilstate_runtime_state *gilstate = &runtime->gilstate;
 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)
@@ -876,12 +876,6 @@ _PyThreadState_DeleteCurrent(_PyRuntimeState *runtime)
 PyEval_ReleaseLock();
 }
 
-void
-PyThreadState_DeleteCurrent()
-{
- _PyThreadState_DeleteCurrent(&_PyRuntime);
-}
-
 
 /*
 * Delete all thread states except the one passed as argument.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /