Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: cleanup sliceobject #1866

Merged
merged 1 commit into from
Sep 13, 2021
Merged

Conversation

deantvv
Copy link
Contributor

@deantvv deantvv commented Sep 11, 2021

For #1289

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good, just one suggestion related to the deprecation...

@@ -61,6 +61,7 @@ impl PySlice {
let start: isize = 0;
let stop: isize = 0;
let step: isize = 0;
#[allow(deprecated)]
let r = ffi::PySlice_GetIndicesEx(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the recommended replacement to using PySlice_GetIndicesEx? It would be great to remove this usage of a deprecated API...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cpython, they define a macro PySlice_GetIndicesEx (shown below)

#define PySlice_GetIndicesEx(slice, length, start, stop, step, slicelen) (  \
    PySlice_Unpack((slice), (start), (stop), (step)) < 0 ?                  \
    ((*(slicelen) = 0), -1) :                                               \
    ((*(slicelen) = PySlice_AdjustIndices((length), (start), (stop), *(step))), \
     0))

Which I didn't implement since currently we didn't have PySlice_Unpack and PySlice_AdjustIndices.
These method seems not so hard. If you like, I can also implement these.

Copy link
Member

@davidhewitt davidhewitt Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, yes please!

Given the function is deprecated in Python 3.7, and there's quite a complex condition on the macro, PySlice_Unpack and PySlice_AdjustIndices which suggest they were added in Python 3.6.1, I think we can only use the new macro form in Python 3.7 and up.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! If you rebase on main it should fix the CI issues with Rust 1.55 and then we can merge 👍

@davidhewitt
Copy link
Member

Perfect, thanks again!

@davidhewitt davidhewitt merged commit 24b92af into PyO3:main Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants