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

Type Buffer's flags argument #648

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numcodecs/compat_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from .compat import ensure_contiguous_ndarray
cdef class Buffer:
"""Convenience class for buffer interface."""

def __cinit__(self, obj, flags):
def __cinit__(self, obj, int flags):
PyObject_GetBuffer(obj, &(self.buffer), flags)
Comment on lines +15 to 16
Copy link
Member Author

@jakirkham jakirkham Nov 18, 2024

Choose a reason for hiding this comment

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

The flags argument here is only used in this PyObject_GetBuffer call. The signature of this function in Cython or in Python is

int PyObject_GetBuffer(object obj, Py_buffer *view, int flags)

Here flags is an int specified by a range of possible constants to provide a specific kind of Py_buffer object

To make sure that flags can be passed through unaltered to this function call, this types the __cinit__ arguments to match

Without this typing, Cython will convert values to Python objects first and then convert them back in this constructor (a needless exercise). This change will fix that issue going forward

self.acquired = True
self.ptr = <char *> self.buffer.buf
Expand Down
Loading