summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-06-01 11:41:56 (GMT)
committerGitHub <noreply@github.com>2023-06-01 11:41:56 (GMT)
commitec0082ca460f6b5eaf987536d28d6bc252322307 (patch)
tree0eb0150c09e917aa1b37acffa3c6168d625a080a
parent9ab587b7146618866cee52c220aecf7bd5b44b02 (diff)
downloadcpython-ec0082ca460f6b5eaf987536d28d6bc252322307.zip
cpython-ec0082ca460f6b5eaf987536d28d6bc252322307.tar.gz
cpython-ec0082ca460f6b5eaf987536d28d6bc252322307.tar.bz2
gh-105182: Remove PyEval_AcquireLock() and PyEval_InitThreads() (#105183)
Remove functions in the C API: * PyEval_AcquireLock() * PyEval_ReleaseLock() * PyEval_InitThreads() * PyEval_ThreadsInitialized() But keep these functions in the stable ABI. Mention "make regen-limited-abi" in "make regen-all".
-rw-r--r--Doc/c-api/init.rst75
-rw-r--r--Doc/data/refcounts.dat6
-rw-r--r--Doc/data/stable_abi.dat4
-rw-r--r--Doc/whatsnew/3.13.rst16
-rw-r--r--Include/ceval.h8
-rw-r--r--Makefile.pre.in3
-rw-r--r--Misc/NEWS.d/next/C API/2023-06-01-11-23-28.gh-issue-105182.kLEHl-.rst2
-rw-r--r--Misc/NEWS.d/next/C API/2023-06-01-11-24-03.gh-issue-105182.l5sCw4.rst2
-rw-r--r--Misc/stable_abi.toml4
-rw-r--r--Misc/valgrind-python.supp8
-rw-r--r--Python/ceval_gil.c13
11 files changed, 36 insertions, 105 deletions
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index f3690eb..dfb3819 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`,
- :c:func:`Py_GetProgramName` and :c:func:`PyEval_InitThreads`.
+ and :c:func:`Py_GetProgramName`.
.. _global-conf-vars:
@@ -326,7 +326,6 @@ 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
@@ -813,45 +812,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:: 3.9
-
- .. index:: pair: 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:: 3.9
-
-
.. c:function:: PyThreadState* PyEval_SaveThread()
Release the global interpreter lock (if it has been created) and reset the
@@ -1223,39 +1183,6 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
available (even when threads have not been initialized).
-.. c:function:: void PyEval_AcquireLock()
-
- Acquire the global interpreter lock. The lock must have been created earlier.
- If this thread already has the lock, a deadlock ensues.
-
- .. deprecated:: 3.2
- This function does not update the current thread state. Please use
- :c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread`
- instead.
-
- .. note::
- Calling this function from a thread when the runtime is finalizing
- will terminate the thread, even if the thread was not created by Python.
- You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
- check if the interpreter is in process of being finalized before calling
- this function to avoid unwanted termination.
-
- .. versionchanged:: 3.8
- Updated to be consistent with :c:func:`PyEval_RestoreThread`,
- :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
- and terminate the current thread if called while the interpreter is finalizing.
-
-
-.. c:function:: void PyEval_ReleaseLock()
-
- Release the global interpreter lock. The lock must have been created earlier.
-
- .. deprecated:: 3.2
- This function does not update the current thread state. Please use
- :c:func:`PyEval_SaveThread` or :c:func:`PyEval_ReleaseThread`
- instead.
-
-
.. _sub-interpreter-support:
Sub-interpreter support
diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat
index ef37b83..65ffb96 100644
--- a/Doc/data/refcounts.dat
+++ b/Doc/data/refcounts.dat
@@ -764,8 +764,6 @@ PyErr_WarnFormat::...::
PyErr_WriteUnraisable:void:::
PyErr_WriteUnraisable:PyObject*:obj:0:
-PyEval_AcquireLock:void:::
-
PyEval_AcquireThread:void:::
PyEval_AcquireThread:PyThreadState*:tstate::
@@ -783,10 +781,6 @@ PyEval_GetFuncDesc:PyObject*:func:0:
PyEval_GetFuncName:const char*:::
PyEval_GetFuncName:PyObject*:func:0:
-PyEval_InitThreads:void:::
-
-PyEval_ReleaseLock:void:::
-
PyEval_ReleaseThread:void:::
PyEval_ReleaseThread:PyThreadState*:tstate::
diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index 8452352..767025b 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -177,7 +177,6 @@ function,PyErr_WarnEx,3.2,,
function,PyErr_WarnExplicit,3.2,,
function,PyErr_WarnFormat,3.2,,
function,PyErr_WriteUnraisable,3.2,,
-function,PyEval_AcquireLock,3.2,,
function,PyEval_AcquireThread,3.2,,
function,PyEval_EvalCode,3.2,,
function,PyEval_EvalCodeEx,3.2,,
@@ -189,12 +188,9 @@ 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.13.rst b/Doc/whatsnew/3.13.rst
index 1f11724..f3ded6a 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -396,3 +396,19 @@ Removed
Use the new :c:type:`PyConfig` API of the :ref:`Python Initialization
Configuration <init-config>` instead (:pep:`587`), added to Python 3.8.
(Contributed by Victor Stinner in :gh:`105145`.)
+
+* 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
+ ``PyEval_ThreadsInitialized()`` always returned non-zero.
+ (Contributed by Victor Stinner in :gh:`105182`.)
+
+* Remove ``PyEval_AcquireLock()`` and ``PyEval_ReleaseLock()`` functions,
+ deprecated in Python 3.2. They didn't update the current thread state.
+ They can be replaced with:
+
+ * :c:func:`PyEval_SaveThread` and :c:func:`PyEval_RestoreThread`;
+ * low-level :c:func:`PyEval_AcquireThread` and :c:func:`PyEval_RestoreThread`;
+ * or :c:func:`PyGILState_Ensure` and :c:func:`PyGILState_Release`.
+
+ (Contributed by Victor Stinner in :gh:`105182`.)
diff --git a/Include/ceval.h b/Include/ceval.h
index cf231b7..9885bdb 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -107,14 +107,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.
- */
-Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_AcquireLock(void);
-Py_DEPRECATED(3.2) PyAPI_FUNC(void) PyEval_ReleaseLock(void);
PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 7ae94ff..0b0651e 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1319,7 +1319,8 @@ regen-all: regen-cases regen-opcode regen-opcode-targets regen-typeslots \
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
regen-test-levenshtein regen-global-objects
@echo
- @echo "Note: make regen-stdlib-module-names and make regen-configure should be run manually"
+ @echo "Note: make regen-stdlib-module-names, make regen-limited-abi"
+ @echo "and make regen-configure should be run manually"
############################################################################
# Special rules for object files
diff --git a/Misc/NEWS.d/next/C API/2023-06-01-11-23-28.gh-issue-105182.kLEHl-.rst b/Misc/NEWS.d/next/C API/2023-06-01-11-23-28.gh-issue-105182.kLEHl-.rst
new file mode 100644
index 0000000..ad9c9e5
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-06-01-11-23-28.gh-issue-105182.kLEHl-.rst
@@ -0,0 +1,2 @@
+Remove ``PyEval_InitThreads()`` and ``PyEval_ThreadsInitialized()``
+functions, deprecated in Python 3.9. Patch by Victor Stinner.
diff --git a/Misc/NEWS.d/next/C API/2023-06-01-11-24-03.gh-issue-105182.l5sCw4.rst b/Misc/NEWS.d/next/C API/2023-06-01-11-24-03.gh-issue-105182.l5sCw4.rst
new file mode 100644
index 0000000..0fe5487
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-06-01-11-24-03.gh-issue-105182.l5sCw4.rst
@@ -0,0 +1,2 @@
+Remove ``PyEval_AcquireLock()`` and ``PyEval_ReleaseLock()`` functions,
+deprecated in Python 3.2. Patch by Victor Stinner.
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index fac59c9..2209f6e 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -664,6 +664,7 @@
added = '3.2'
[function.PyEval_AcquireLock]
added = '3.2'
+ abi_only = true
[function.PyEval_AcquireThread]
added = '3.2'
[function.PyEval_CallFunction]
@@ -697,8 +698,10 @@
added = '3.2'
[function.PyEval_InitThreads]
added = '3.2'
+ abi_only = true
[function.PyEval_ReleaseLock]
added = '3.2'
+ abi_only = true
[function.PyEval_ReleaseThread]
added = '3.2'
[function.PyEval_RestoreThread]
@@ -707,6 +710,7 @@
added = '3.2'
[function.PyEval_ThreadsInitialized]
added = '3.2'
+ abi_only = true
[data.PyExc_ArithmeticError]
added = '3.2'
[data.PyExc_AssertionError]
diff --git a/Misc/valgrind-python.supp b/Misc/valgrind-python.supp
index c9c45ba..29954c1 100644
--- a/Misc/valgrind-python.supp
+++ b/Misc/valgrind-python.supp
@@ -47,14 +47,6 @@
#
{
- 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
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index b9bdb74..536991f 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -496,7 +496,8 @@ _PyEval_ThreadsInitialized(void)
return gil_created(gil);
}
-int
+// Function removed in the Python 3.13 API but kept in the stable ABI.
+PyAPI_FUNC(int)
PyEval_ThreadsInitialized(void)
{
return _PyEval_ThreadsInitialized();
@@ -584,7 +585,8 @@ _PyEval_FiniGIL(PyInterpreterState *interp)
interp->ceval.gil = NULL;
}
-void
+// Function removed in the Python 3.13 API but kept in the stable ABI.
+PyAPI_FUNC(void)
PyEval_InitThreads(void)
{
/* Do nothing: kept for backward compatibility */
@@ -597,7 +599,9 @@ _PyEval_Fini(void)
_Py_PrintSpecializationStats(1);
#endif
}
-void
+
+// Function removed in the Python 3.13 API but kept in the stable ABI.
+PyAPI_FUNC(void)
PyEval_AcquireLock(void)
{
PyThreadState *tstate = _PyThreadState_GET();
@@ -606,7 +610,8 @@ PyEval_AcquireLock(void)
take_gil(tstate);
}
-void
+// Function removed in the Python 3.13 API but kept in the stable ABI.
+PyAPI_FUNC(void)
PyEval_ReleaseLock(void)
{
PyThreadState *tstate = _PyThreadState_GET();