Skip to content
New issue

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

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

Already on GitHub? # to your account

Change the type of length from c_long to isize (in PySlice::index) #3756

Closed
cmpute opened this issue Jan 23, 2024 · 5 comments · Fixed by #3761
Closed

Change the type of length from c_long to isize (in PySlice::index) #3756

cmpute opened this issue Jan 23, 2024 · 5 comments · Fixed by #3761

Comments

@cmpute
Copy link
Contributor

cmpute commented Jan 23, 2024

pub fn indices(&self, length: c_long) -> PyResult<PySliceIndices> {

The underlying function PySlice_GetIndicesEx has an input length of type Py_ssize_t, which should be mapped to isize, instead of c_long. The conversion from c_long to Py_ssize_t seems unnecessary.

@davidhewitt
Copy link
Member

Agreed, a PR to fix this would be greatly appreciated 👍

@davidhewitt
Copy link
Member

davidhewitt commented Jan 23, 2024

That said, I assume the length should be non-negative? Maybe usize is better, and we can return an overflow error if the usize is greater than isize::MAX?

@cmpute
Copy link
Contributor Author

cmpute commented Jan 24, 2024

Agree!. And if more changes are allowed, I propose to further change the type of start/stop/length of PySliceIndices all to usize, and impleming using the recommended new APIs PySlice_Unpack and PySlice_AdjustIndices. (according to official C-API docs)

@davidhewitt
Copy link
Member

I'm certainly open to making those changes to fit better with what Python offers, but we should consider the compatibility story. There's a lot changing in 0.21 already and I'm cautious of adding too much more.

@cmpute
Copy link
Contributor Author

cmpute commented Jan 25, 2024

I'm certainly open to making those changes to fit better with what Python offers, but we should consider the compatibility story. There's a lot changing in 0.21 already and I'm cautious of adding too much more.

This change is already a break change, but I will try to make the changes small, when I create the PR probably this or next week.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants