Skip to content

Commit 8afc8c6

Browse files
committed
gh-158077: Remove deprecated PySlice_GetIndicesEx() function
Only remove the function implementation. PySlice_GetIndicesEx() remains available as a static inline function, so the API does not change. Convert PySlice_GetIndicesEx() macro to a static inline functions. Arguments are now only evaluated once. The function is no longer supported on limited C API older than 3.6.1.
1 parent a5a4659 commit 8afc8c6

8 files changed

Lines changed: 39 additions & 22 deletions

File tree

‎Doc/c-api/slice.rst‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ Slice Objects
6868
is replaced by ::
6969
7070
if (PySlice_Unpack(slice, &start, &stop, &step) < 0) {
71-
// return error
71+
slicelength = 0;
72+
return -1;
7273
}
7374
slicelength = PySlice_AdjustIndices(length, &start, &stop, step);
75+
return 0;
7476
7577
.. versionchanged:: 3.2
7678
The parameter type for the *slice* parameter was ``PySliceObject*``
@@ -83,10 +85,9 @@ Slice Objects
8385
:c:func:`!PySlice_Unpack` and :c:func:`!PySlice_AdjustIndices`.
8486
Arguments *start*, *stop* and *step* are evaluated more than once.
8587
86-
.. deprecated:: 3.6.1
87-
If ``Py_LIMITED_API`` is set to the value less than ``0x03050400`` or
88-
between ``0x03060000`` and ``0x03060100`` (not including)
89-
:c:func:`!PySlice_GetIndicesEx` is a deprecated function.
88+
.. versionchanged:: next
89+
:c:func:`!PySlice_GetIndicesEx` is now implemented as a static inline
90+
function. Arguments are only evaluated once.
9091
9192
9293
.. c:function:: int PySlice_Unpack(PyObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step)

‎Doc/data/stable_abi.dat‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Doc/deprecations/c-api-pending-removal-in-future.rst‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ although there is currently no date scheduled for their removal.
1616
Use :c:func:`PyModule_GetFilenameObject` instead.
1717
* :c:func:`PyOS_AfterFork`:
1818
Use :c:func:`PyOS_AfterFork_Child` instead.
19-
* :c:func:`PySlice_GetIndicesEx`:
20-
Use :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices` instead.
2119
* :c:func:`PyUnicode_READY`:
2220
Unneeded since Python 3.12
2321
* :c:func:`!PyErr_Display`:

‎Doc/whatsnew/3.16.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@ Deprecated C APIs
11281128
and :c:func:`PyAsyncGen_New` are deprecated.
11291129
They are scheduled for removal in 3.18.
11301130

1131+
* Remove :c:func:`PySlice_GetIndicesEx` function, deprecated since Python 3.7.
1132+
Only remove the function implementation: :c:func:`PySlice_GetIndicesEx`
1133+
remains available as a static inline function, so the API does not change.
1134+
(Contributed by Victor Stinner in :gh:`158077`.)
1135+
11311136
.. Add C API deprecations above alphabetically, not here at the end.
11321137
11331138
.. include:: ../deprecations/c-api-pending-removal-in-3.18.rst

‎Include/sliceobject.h‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,28 @@ PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
2525
PyObject* step);
2626
PyAPI_FUNC(int) PySlice_GetIndices(PyObject *r, Py_ssize_t length,
2727
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
28-
Py_DEPRECATED(3.7)
29-
PyAPI_FUNC(int) PySlice_GetIndicesEx(PyObject *r, Py_ssize_t length,
30-
Py_ssize_t *start, Py_ssize_t *stop,
31-
Py_ssize_t *step,
32-
Py_ssize_t *slicelength);
33-
34-
#if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100
35-
#define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) ( \
36-
PySlice_Unpack((slice), (start), (stop), (step)) < 0 ? \
37-
((*(slicelen) = 0), -1) : \
38-
((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \
39-
0))
28+
29+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060100
4030
PyAPI_FUNC(int) PySlice_Unpack(PyObject *slice,
4131
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
4232
PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length,
4333
Py_ssize_t *start, Py_ssize_t *stop,
4434
Py_ssize_t step);
35+
36+
static inline int
37+
_PySlice_GetIndicesEx(PyObject *slice, Py_ssize_t length,
38+
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
39+
Py_ssize_t *slicelen)
40+
{
41+
if (PySlice_Unpack(slice, start, stop, step) < 0) {
42+
*slicelen = 0;
43+
return -1;
44+
}
45+
46+
*slicelen = PySlice_AdjustIndices(length, start, stop, *step);
47+
return 0;
48+
}
49+
#define PySlice_GetIndicesEx _PySlice_GetIndicesEx
4550
#endif
4651

4752
#ifndef Py_LIMITED_API
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Remove :c:func:`PySlice_GetIndicesEx` function, deprecated since Python 3.7.
2+
Only remove the function implementation: :c:func:`PySlice_GetIndicesEx`
3+
remains available as a static inline function, so the API does not change.
4+
Patch by Victor Stinner.

‎Misc/stable_abi.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@
13141314
added = '3.2'
13151315
[function.PySlice_GetIndicesEx]
13161316
added = '3.2'
1317+
abi_only = true
13171318
[function.PySlice_New]
13181319
added = '3.2'
13191320
[data.PySlice_Type]

‎Objects/sliceobject.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,17 @@ PySlice_AdjustIndices(Py_ssize_t length,
297297

298298
#undef PySlice_GetIndicesEx
299299

300-
int
300+
// Function removed from Python 3.16 C API, but kept in the stable ABI
301+
PyAPI_FUNC(int)
301302
PySlice_GetIndicesEx(PyObject *_r, Py_ssize_t length,
302303
Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step,
303304
Py_ssize_t *slicelength)
304305
{
305-
if (PySlice_Unpack(_r, start, stop, step) < 0)
306+
if (PySlice_Unpack(_r, start, stop, step) < 0) {
307+
*slicelength = 0;
306308
return -1;
309+
}
310+
307311
*slicelength = PySlice_AdjustIndices(length, start, stop, *step);
308312
return 0;
309313
}

0 commit comments

Comments
 (0)