Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5d9e81

Browse files
authored
bpo-36728: Remove PyEval_ReInitThreads() from C API (GH-13241)
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.
1 parent 3aef48e commit d5d9e81

6 files changed

Lines changed: 25 additions & 7 deletions

File tree

Doc/whatsnew/3.8.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ Changes in the Python API
990990
Changes in the C API
991991
--------------------
992992

993+
* The :c:func:`PyEval_ReInitThreads` function has been removed from the C API.
994+
It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child`
995+
instead.
996+
(Contributed by Victor Stinner in :issue:`36728`.)
997+
993998
* On Unix, C extensions are no longer linked to libpython except on
994999
Android. When Python is embedded, ``libpython`` must not be loaded with
9951000
``RTLD_LOCAL``, but ``RTLD_GLOBAL`` instead. Previously, using

Include/ceval.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ PyAPI_FUNC(void) PyEval_AcquireLock(void) Py_DEPRECATED(3.2);
195195
PyAPI_FUNC(void) PyEval_ReleaseLock(void) /* Py_DEPRECATED(3.2) */;
196196
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
197197
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
198-
PyAPI_FUNC(void) PyEval_ReInitThreads(void);
199198

200199
#ifndef Py_LIMITED_API
201200
PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall(
2424
void *arg);
2525
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(
2626
struct _ceval_runtime_state *ceval);
27+
PyAPI_FUNC(void) _PyEval_ReInitThreads(
28+
_PyRuntimeState *runtime);
2729

2830
#ifdef __cplusplus
2931
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :c:func:`PyEval_ReInitThreads` function has been removed from the C API.
2+
It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child` instead.

Modules/posixmodule.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,25 @@
2525
#define PY_SSIZE_T_CLEAN
2626

2727
#include "Python.h"
28+
#ifdef MS_WINDOWS
29+
/* include <windows.h> early to avoid conflict with pycore_condvar.h:
30+
31+
#define WIN32_LEAN_AND_MEAN
32+
#include <windows.h>
33+
34+
FSCTL_GET_REPARSE_POINT is not exported with WIN32_LEAN_AND_MEAN. */
35+
# include <windows.h>
36+
#endif
37+
38+
#include "pycore_ceval.h" /* _PyEval_ReInitThreads() */
39+
#include "pycore_pystate.h" /* _PyRuntime */
2840
#include "pythread.h"
2941
#include "structmember.h"
3042
#ifndef MS_WINDOWS
31-
#include "posixmodule.h"
43+
# include "posixmodule.h"
3244
#else
33-
#include "winreparse.h"
45+
# include "winreparse.h"
3446
#endif
35-
#include "pycore_pystate.h"
3647

3748
/* On android API level 21, 'AT_EACCESS' is not declared although
3849
* HAVE_FACCESSAT is defined. */
@@ -424,7 +435,7 @@ PyOS_AfterFork_Child(void)
424435
_PyRuntimeState *runtime = &_PyRuntime;
425436
_PyGILState_Reinit(runtime);
426437
_PyInterpreterState_DeleteExceptMain(runtime);
427-
PyEval_ReInitThreads();
438+
_PyEval_ReInitThreads(runtime);
428439
_PyImport_ReInitLock();
429440
_PySignal_AfterFork();
430441
_PyRuntimeState_ReInitThreads(runtime);

Python/ceval.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,8 @@ PyEval_ReleaseThread(PyThreadState *tstate)
289289
*/
290290

291291
void
292-
PyEval_ReInitThreads(void)
292+
_PyEval_ReInitThreads(_PyRuntimeState *runtime)
293293
{
294-
_PyRuntimeState *runtime = &_PyRuntime;
295294
struct _ceval_runtime_state *ceval = &runtime->ceval;
296295
if (!gil_created(&ceval->gil)) {
297296
return;

0 commit comments

Comments
 (0)