From f51e71407030e12f14769129ee48932011052c6c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 11 May 2019 03:53:16 +0200 Subject: [PATCH 1/2] bpo-36728: Remove PyEval_ReInitThreads() from C API Remove the PyEval_ReInitThreads() function from the Python C API. It should not be called explicitly: use PyOS_AfterFork_Child() instead. Rename PyEval_ReInitThreads() to _PyEval_ReInitThreads() and add a 'runtime' parameter. --- Doc/whatsnew/3.8.rst | 5 +++++ Include/ceval.h | 1 - Include/internal/pycore_ceval.h | 2 ++ .../next/C API/2019-05-11-03-56-23.bpo-36728.FR-dMP.rst | 2 ++ Modules/posixmodule.c | 3 ++- Python/ceval.c | 3 +-- 6 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2019-05-11-03-56-23.bpo-36728.FR-dMP.rst diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 684656fc2a58f6..ac253059f328e3 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -990,6 +990,11 @@ Changes in the Python API Changes in the C API -------------------- +* The :c:func:`PyEval_ReInitThreads` function has been removed from the C API. + It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child` + instead. + (Contributed by Victor Stinner in :issue:`36728`.) + * On Unix, C extensions are no longer linked to libpython except on Android. When Python is embedded, ``libpython`` must not be loaded with ``RTLD_LOCAL``, but ``RTLD_GLOBAL`` instead. Previously, using diff --git a/Include/ceval.h b/Include/ceval.h index 2d4b67d092bc3e..8cdf353b05fd07 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -195,7 +195,6 @@ PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2); PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */; PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate); PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate); -PyAPI_FUNC(void) PyEval_ReInitThreads(void); #ifndef Py_LIMITED_API PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index cdc73a36e5bc1b..7a3166e86dab7f 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -24,6 +24,8 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall( void *arg); PyAPI_FUNC(void) _PyEval_SignalAsyncExc( struct _ceval_runtime_state *ceval); +PyAPI_FUNC(void) _PyEval_ReInitThreads( + _PyRuntimeState *runtime); #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/C API/2019-05-11-03-56-23.bpo-36728.FR-dMP.rst b/Misc/NEWS.d/next/C API/2019-05-11-03-56-23.bpo-36728.FR-dMP.rst new file mode 100644 index 00000000000000..c691cc412c2194 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-05-11-03-56-23.bpo-36728.FR-dMP.rst @@ -0,0 +1,2 @@ +The :c:func:`PyEval_ReInitThreads` function has been removed from the C API. +It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child` instead. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index aa77094da06a93..5ee0182c1f11a1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -25,6 +25,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "pycore_ceval.h" /* _PyEval_ReInitThreads() */ #include "pythread.h" #include "structmember.h" #ifndef MS_WINDOWS @@ -424,7 +425,7 @@ PyOS_AfterFork_Child(void) _PyRuntimeState *runtime = &_PyRuntime; _PyGILState_Reinit(runtime); _PyInterpreterState_DeleteExceptMain(runtime); - PyEval_ReInitThreads(); + _PyEval_ReInitThreads(runtime); _PyImport_ReInitLock(); _PySignal_AfterFork(); _PyRuntimeState_ReInitThreads(runtime); diff --git a/Python/ceval.c b/Python/ceval.c index 17439533a3f235..1bb4704572b44b 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -289,9 +289,8 @@ PyEval_ReleaseThread(PyThreadState *tstate) */ void -PyEval_ReInitThreads(void) +_PyEval_ReInitThreads(_PyRuntimeState *runtime) { - _PyRuntimeState *runtime = &_PyRuntime; struct _ceval_runtime_state *ceval = &runtime->ceval; if (!gil_created(&ceval->gil)) { return; From 7fcd6169819475c02f62b7454c1eae1036d1938f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 13 May 2019 12:19:03 +0200 Subject: [PATCH 2/2] Fix includes on Windows --- Modules/posixmodule.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5ee0182c1f11a1..aca64efeb1e37f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -25,15 +25,25 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "pycore_ceval.h" /* _PyEval_ReInitThreads() */ +#ifdef MS_WINDOWS + /* include early to avoid conflict with pycore_condvar.h: + + #define WIN32_LEAN_AND_MEAN + #include + + FSCTL_GET_REPARSE_POINT is not exported with WIN32_LEAN_AND_MEAN. */ +# include +#endif + +#include "pycore_ceval.h" /* _PyEval_ReInitThreads() */ +#include "pycore_pystate.h" /* _PyRuntime */ #include "pythread.h" #include "structmember.h" #ifndef MS_WINDOWS -#include "posixmodule.h" +# include "posixmodule.h" #else -#include "winreparse.h" +# include "winreparse.h" #endif -#include "pycore_pystate.h" /* On android API level 21, 'AT_EACCESS' is not declared although * HAVE_FACCESSAT is defined. */