feat: introduce stack-allocated PyBuffer#5894
Conversation
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks very much for this. Various thoughts around the accessor methods.
Also, out of scope for this PR, but I keep wondering if we should provide iterators for these structures. Especially with the strides / suboffsets etc, it's not necessarily trivial to get this right.
Yes, I think it would definitely be useful as well. I am not yet sure how this would look like though. |
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks for the continued work here, looking great!
Implementing Drop directly on PyUntypedBufferView is functionally equivalent to what I had in mind from the "drop guard", so gets a 👍 from me.
Afraid I had quite a few more thoughts around some of the edge cases (plus some ideas we can probably ignore). Hopefully helps us get to the right eventual abstraction!
src/buffer.rs
Outdated
| /// | ||
| /// Returns `None` if the exporter set `shape` to NULL (e.g. `PyBUF_SIMPLE` was requested). | ||
| #[inline] | ||
| pub fn shape(&self) -> Option<&[usize]> { |
There was a problem hiding this comment.
I wonder if there's some way with const generics that we could make a compile-time guarantee on the nullability of this field (and others).
Probably leads to a horrendously messy type system where in practice these null checks are not the bottleneck.
There was a problem hiding this comment.
No, not at all. I agree with you. It's a great idea. Let me think about this.
There was a problem hiding this comment.
Okay, I think I came up with something good, but it makes a lot of the other suggestions moot now.
Co-authored-by: David Hewitt <mail@davidhewitt.dev>
37f9233 to
5430e96
Compare
5430e96 to
48b5fdd
Compare
Summary
This PR implements a pinned stack-allocated
PyUntypedBuffervariant,PyUntypedBufferView.Closes #5836