https://github.com/python/cpython/commit/75eed5b3734edb221cabb8322d8b8bdf9e3ee6b1
commit: 75eed5b3734edb221cabb8322d8b8bdf9e3ee6b1
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-04-17T15:01:28+02:00
summary:

gh-117929: Restore removed PyEval_InitThreads() function (#117931)

files:
A Misc/NEWS.d/next/C API/2024-04-16-13-34-01.gh-issue-117929.HSr419.rst
M Doc/c-api/init.rst
M Doc/data/stable_abi.dat
M Doc/whatsnew/3.13.rst
M Include/ceval.h
M Misc/stable_abi.toml
M Python/ceval_gil.c

diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 05f2fd13cf2069..9b98e71ae533ec 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -59,7 +59,7 @@ The following functions can be safely called before Python is 
initialized:
    :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`,
-   and :c:func:`Py_GetProgramName`.
+   :c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
 
 
 .. _global-conf-vars:
@@ -326,6 +326,7 @@ Initializing and finalizing the interpreter
 .. c:function:: void Py_Initialize()
 
    .. index::
+      single: PyEval_InitThreads()
       single: modules (in module sys)
       single: path (in module sys)
       pair: module; builtins
@@ -841,6 +842,33 @@ 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:: 3.9
+
+   .. index:: pair: module; _thread
+
+
 .. c:function:: PyThreadState* PyEval_SaveThread()
 
    Release the global interpreter lock (if it has been created) and reset the
diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index 2763bea5137cc7..aa902235784194 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -192,6 +192,7 @@ 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_ReleaseThread,3.2,,
 function,PyEval_RestoreThread,3.2,,
 function,PyEval_SaveThread,3.2,,
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index f957698ecb06d8..86c6a7e93f0a55 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -2027,9 +2027,9 @@ Removed
   added in Python 3.8 and the old macros were deprecated in Python 3.11.
   (Contributed by Irit Katriel in :gh:`105111`.)
 
-* Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
-  functions, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
-  always creates the GIL: calling ``PyEval_InitThreads()`` did nothing and
+* Remove ``PyEval_ThreadsInitialized()``
+  function, deprecated in Python 3.9. Since Python 3.7, ``Py_Initialize()``
+  always creates the GIL: calling ``PyEval_InitThreads()`` does nothing and
   ``PyEval_ThreadsInitialized()`` always returned non-zero.
   (Contributed by Victor Stinner in :gh:`105182`.)
 
diff --git a/Include/ceval.h b/Include/ceval.h
index 9885bdb7febc21..8ea9da8d134ee0 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -107,6 +107,8 @@ 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(void) PyEval_InitThreads(void);
+
 PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
 PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
 
diff --git a/Misc/NEWS.d/next/C 
API/2024-04-16-13-34-01.gh-issue-117929.HSr419.rst b/Misc/NEWS.d/next/C 
API/2024-04-16-13-34-01.gh-issue-117929.HSr419.rst
new file mode 100644
index 00000000000000..58d475bbf21981
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2024-04-16-13-34-01.gh-issue-117929.HSr419.rst     
@@ -0,0 +1,2 @@
+Restore removed :c:func:`PyEval_InitThreads` function. Patch by Victor
+Stinner.
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index 14dda7db1c323e..ad6f0ee3a5c212 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -702,7 +702,6 @@
     added = '3.2'
 [function.PyEval_InitThreads]
     added = '3.2'
-    abi_only = true
 [function.PyEval_ReleaseLock]
     added = '3.2'
     abi_only = true
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index d88ac65c5cf300..c0819d8ab1d8d0 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -512,8 +512,7 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
     interp->ceval.gil = NULL;
 }
 
-// Function removed in the Python 3.13 API but kept in the stable ABI.
-PyAPI_FUNC(void)
+void
 PyEval_InitThreads(void)
 {
     /* Do nothing: kept for backward compatibility */

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to