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

Make len(memoryview) return Py_ssize_t #2992

Open
scoder opened this issue Jun 10, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@scoder
Copy link
Contributor

commented Jun 10, 2019

len(memoryview) currently returns a size_t. This diverges from the default Python behaviour of having signed indices to support negative indexing etc. CPython also treats the result of len() as a Py_ssize_t internally.

Cython should always return a Py_ssize_t from len(), not a size_t.

Originally raised in
pandas-dev/pandas#26757

The current len() implementation has two more similar cases: len(charptr) and len(Py_UNICODE_ptr), both mapping to strlen()-like code. In all three cases, the downside is that (especially in 32bit systems), Py_ssize_t has a smaller value range than size_t, which means that the length of very long data buffers can wrap around, currently without raising an error.

@scoder scoder added this to the 3.0 milestone Jun 10, 2019

@scoder scoder added the P: blocker label Jun 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.