Skip to content

Commit

Permalink
Stop using PySlice_GetIndicesEx
Browse files Browse the repository at this point in the history
This function was deprecated in Python 3.6.

Fixes #506
  • Loading branch information
ronaldoussoren committed Dec 16, 2022
1 parent 754127f commit 4b37308
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pyobjc-core/Modules/objc/python-api-used.h
Expand Up @@ -386,5 +386,11 @@ PyAPI_FUNC(const Py_buffer*) PyPickleBuffer_GetBuffer(PyObject*)
__attribute__((warn_unused_result));
PyAPI_FUNC(PyObject* _Nullable) PyMemoryView_FromBuffer(Py_buffer* info)
__attribute__((warn_unused_result));
PyAPI_FUNC(int) PySlice_Unpack(PyObject* slice, Py_ssize_t* start, Py_ssize_t* stop,
Py_ssize_t* step) __attribute__((warn_unused_result));
PyAPI_FUNC(Py_ssize_t) PySlice_AdjustIndices(Py_ssize_t length, Py_ssize_t* start,
Py_ssize_t* stop, Py_ssize_t step)
__attribute__((warn_unused_result));

NS_ASSUME_NONNULL_END
#endif /* USE_STATIC_ANALYZER */
11 changes: 4 additions & 7 deletions pyobjc-core/Modules/objc/struct-wrapper.m
Expand Up @@ -394,12 +394,10 @@
PyObject* result;
PyObject* it;

if (PySlice_GetIndicesEx(item, STRUCT_LENGTH(self), &start, &stop, &step,
&slicelength)
< 0) {
if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return NULL;
}

slicelength = PySlice_AdjustIndices(STRUCT_LENGTH(self), &start, &stop, step);
if (slicelength <= 0) {
return PyTuple_New(0);

Expand Down Expand Up @@ -454,11 +452,10 @@
} else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength;

if (PySlice_GetIndicesEx(item, STRUCT_LENGTH(self), &start, &stop, &step,
&slicelength)
< 0) {
if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
return -1;
}
slicelength = PySlice_AdjustIndices(STRUCT_LENGTH(self), &start, &stop, step);

if (step == 1) {
return struct_sq_ass_slice(self, start, stop, value);
Expand Down

0 comments on commit 4b37308

Please sign in to comment.