diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 0f759732b35ea8..b03ac39d4d3699 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -64,8 +64,8 @@ The following functions can be safely called before Python is initialized: The following functions **should not be called** before :c:func:`Py_Initialize`: :c:func:`Py_EncodeLocale`, :c:func:`Py_GetPath`, :c:func:`Py_GetPrefix`, :c:func:`Py_GetExecPrefix`, - :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome`, - :c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`. + :c:func:`Py_GetProgramFullPath`, :c:func:`Py_GetPythonHome` + and :c:func:`Py_GetProgramName`. .. _global-conf-vars: @@ -230,7 +230,6 @@ Initializing and finalizing the interpreter .. index:: single: Py_SetProgramName() - single: PyEval_InitThreads() single: modules (in module sys) single: path (in module sys) module: builtins @@ -871,45 +870,6 @@ code, or when embedding the Python interpreter: this thread's interpreter state. -.. c:function:: void PyEval_InitThreads() - - .. index:: - single: PyEval_AcquireThread() - single: PyEval_ReleaseThread() - single: PyEval_SaveThread() - single: PyEval_RestoreThread() - - Deprecated function which does nothing. - - In Python 3.6 and older, this function created the GIL if it didn't exist. - - .. versionchanged:: 3.9 - The function now does nothing. - - .. versionchanged:: 3.7 - This function is now called by :c:func:`Py_Initialize()`, so you don't - have to call it yourself anymore. - - .. versionchanged:: 3.2 - This function cannot be called before :c:func:`Py_Initialize()` anymore. - - .. deprecated-removed:: 3.9 3.11 - - .. index:: module: _thread - - -.. c:function:: int PyEval_ThreadsInitialized() - - Returns a non-zero value if :c:func:`PyEval_InitThreads` has been called. This - function can be called without holding the GIL, and therefore can be used to - avoid calls to the locking API when running single-threaded. - - .. versionchanged:: 3.7 - The :term:`GIL` is now initialized by :c:func:`Py_Initialize()`. - - .. deprecated-removed:: 3.9 3.11 - - .. c:function:: PyThreadState* PyEval_SaveThread() Release the global interpreter lock (if it has been created) and reset the diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat index f3aacb8ed8ed0d..f79bbb54bb6b4d 100644 --- a/Doc/data/refcounts.dat +++ b/Doc/data/refcounts.dat @@ -780,8 +780,6 @@ PyEval_GetFuncDesc:PyObject*:func:0: PyEval_GetFuncName:const char*::: PyEval_GetFuncName:PyObject*:func:0: -PyEval_InitThreads:void::: - PyEval_ReleaseLock:void::: PyEval_ReleaseThread:void::: diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index d582204f5626b9..3b76c88f5d2e13 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -179,12 +179,10 @@ function,PyEval_GetFuncDesc,3.2, function,PyEval_GetFuncName,3.2, function,PyEval_GetGlobals,3.2, function,PyEval_GetLocals,3.2, -function,PyEval_InitThreads,3.2, function,PyEval_ReleaseLock,3.2, function,PyEval_ReleaseThread,3.2, function,PyEval_RestoreThread,3.2, function,PyEval_SaveThread,3.2, -function,PyEval_ThreadsInitialized,3.2, var,PyExc_ArithmeticError,3.2, var,PyExc_AssertionError,3.2, var,PyExc_AttributeError,3.2, diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 464a97ef6e01eb..76f21ea5ae9eab 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -96,10 +96,9 @@ Optimizations (Contributed by Serhiy Storchaka in :issue:`28307`.) -Build and C API Changes -======================= +Build Changes +============= -* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been removed. Deprecated ========== @@ -116,3 +115,30 @@ Porting to Python 3.11 This section lists previously described changes and other bugfixes that may require changes to your code. + + +C API Changes +============= + +New Features +------------ + +Porting to Python 3.11 +---------------------- + +Deprecated +---------- + +Removed +------- + +* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been + removed. + (Contributed by Mark Shannon in :issue:`40222`.) + +* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()`` + functions. The GIL is created by :c:func:`Py_Initialize` since Python 3.7, + and so calling explicitly ``PyEval_InitThreads()`` was useless since Python + 3.7. Deprecated in 3.9, ``PyEval_InitThreads()`` did nothing and + ``PyEval_ThreadsInitialized()`` already returned true. + (Contributed by Victor Stinner in :issue:`44117`.) diff --git a/Include/ceval.h b/Include/ceval.h index 0f687666e2bccf..83fbe231911459 100644 --- a/Include/ceval.h +++ b/Include/ceval.h @@ -118,8 +118,6 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(PyFrameObject *f, int exc); PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void); PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *); -Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void); -Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void); /* PyEval_AcquireLock() and PyEval_ReleaseLock() are part of stable ABI. * They will be removed from this header file in the future version. * But they will be remained in ABI until Python 4.0. diff --git a/Misc/NEWS.d/next/C API/2021-05-12-17-23-57.bpo-44117.nZMB-N.rst b/Misc/NEWS.d/next/C API/2021-05-12-17-23-57.bpo-44117.nZMB-N.rst new file mode 100644 index 00000000000000..0d212da58b720a --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-05-12-17-23-57.bpo-44117.nZMB-N.rst @@ -0,0 +1,5 @@ +Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()`` +functions. The GIL is created by :c:func:`Py_Initialize` since Python 3.7, +and so calling explicitly ``PyEval_InitThreads()`` was useless since Python +3.7. Deprecated in 3.9, ``PyEval_InitThreads()`` did nothing and +``PyEval_ThreadsInitialized()`` already returned true. diff --git a/Misc/stable_abi.txt b/Misc/stable_abi.txt index a78bcb76b41df6..de719632343872 100644 --- a/Misc/stable_abi.txt +++ b/Misc/stable_abi.txt @@ -601,8 +601,6 @@ function PyEval_GetGlobals added 3.2 function PyEval_GetLocals added 3.2 -function PyEval_InitThreads - added 3.2 function PyEval_ReleaseLock added 3.2 function PyEval_ReleaseThread @@ -611,8 +609,6 @@ function PyEval_RestoreThread added 3.2 function PyEval_SaveThread added 3.2 -function PyEval_ThreadsInitialized - added 3.2 data PyExc_ArithmeticError added 3.2 data PyExc_AssertionError diff --git a/Misc/valgrind-python.supp b/Misc/valgrind-python.supp index c9c45ba7ed6de4..9d2552ae83b258 100644 --- a/Misc/valgrind-python.supp +++ b/Misc/valgrind-python.supp @@ -46,22 +46,6 @@ # Will need to fix that. # -{ - Suppress leaking the GIL. Happens once per process, see comment in ceval.c. - Memcheck:Leak - fun:malloc - fun:PyThread_allocate_lock - fun:PyEval_InitThreads -} - -{ - Suppress leaking the GIL after a fork. - Memcheck:Leak - fun:malloc - fun:PyThread_allocate_lock - fun:PyEval_ReInitThreads -} - { Suppress leaking the autoTLSkey. This looks like it shouldn't leak though. Memcheck:Leak diff --git a/PC/python3dll.c b/PC/python3dll.c index 200d1d14e294d1..eb8ae5db5a0677 100755 --- a/PC/python3dll.c +++ b/PC/python3dll.c @@ -245,12 +245,10 @@ EXPORT_FUNC(PyEval_GetFuncDesc) EXPORT_FUNC(PyEval_GetFuncName) EXPORT_FUNC(PyEval_GetGlobals) EXPORT_FUNC(PyEval_GetLocals) -EXPORT_FUNC(PyEval_InitThreads) EXPORT_FUNC(PyEval_ReleaseLock) EXPORT_FUNC(PyEval_ReleaseThread) EXPORT_FUNC(PyEval_RestoreThread) EXPORT_FUNC(PyEval_SaveThread) -EXPORT_FUNC(PyEval_ThreadsInitialized) EXPORT_FUNC(PyException_GetCause) EXPORT_FUNC(PyException_GetContext) EXPORT_FUNC(PyException_GetTraceback) diff --git a/Python/ceval.c b/Python/ceval.c index 8e1c5bdf033074..fb2ad0ffa2e763 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -282,27 +282,12 @@ _PyEval_ThreadsInitialized(PyInterpreterState *interp) { return gil_created(&interp->ceval.gil); } - -int -PyEval_ThreadsInitialized(void) -{ - // Fatal error if there is no current interpreter - PyInterpreterState *interp = PyInterpreterState_Get(); - return _PyEval_ThreadsInitialized(interp); -} #else int _PyEval_ThreadsInitialized(_PyRuntimeState *runtime) { return gil_created(&runtime->ceval.gil); } - -int -PyEval_ThreadsInitialized(void) -{ - _PyRuntimeState *runtime = &_PyRuntime; - return _PyEval_ThreadsInitialized(runtime); -} #endif PyStatus @@ -360,12 +345,6 @@ _PyEval_FiniGIL(PyInterpreterState *interp) assert(!gil_created(gil)); } -void -PyEval_InitThreads(void) -{ - /* Do nothing: kept for backward compatibility */ -} - void _PyEval_Fini(void) {