-
Notifications
You must be signed in to change notification settings - Fork 927
Add PyBytes::new_with_writer
#5517
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
base: main
Are you sure you want to change the base?
Conversation
a016633 to
1593104
Compare
de94a5a to
89a3e09
Compare
|
How can I make pyo3-ffi-check happy? It is complaining that |
244df75 to
5318908
Compare
85b55d9 to
7bfa6f4
Compare
7bfa6f4 to
c367d60
Compare
c367d60 to
cb5a20d
Compare
7f64f95 to
dd65502
Compare
|
A possible future extension would be to implement |
davidhewitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thank you! It's cool to see these newer APIs improving ergonomics / solving cases which couldn't be done previously.
| return crate::PyBytes_AsString(op); | ||
| } | ||
|
|
||
| opaque_struct!(pub PyBytesWriter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably missing a cfg here?
| opaque_struct!(pub PyBytesWriter); | |
| #[cfg(Py_3_15)] | |
| opaque_struct!(pub PyBytesWriter); |
| #[inline] | ||
| pub unsafe fn PyBytesWriter_Create( | ||
| size: crate::Py_ssize_t, | ||
| ) -> *mut crate::PyBytesWriter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, the compat APIs produce a PyBytesWriter too, which exists before 3.15.
Maybe we should have pyo3_ffi::compat::PyBytesWriter opaque struct defined for pre-3.15? (On 3.15 it can be a re-export.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not get ffi-check to pass, with a public exposed struct that does not have a definition in the generated binding. So my only working solution so far was to force it to ignore this struct on pre-3.15.
For reference this is the error
error[E0412]: cannot find type `PyBytesWriter` in module `bindings`
--> src\main.rs:70:5
|
70 | pyo3_ffi_check_macro::for_all_structs!(check_struct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `bindings`
8b744fc to
07f9d6c
Compare
07f9d6c to
c0e68f4
Compare
Adds a new constructor on
PyBytesthat allows creating a python bytes object using astd::io::Writewriter. I've exposed the writer as&mut dyn Writedyn object so we do not have to expose the internal writer implementation. We can change this to&mut PyBytesWriterat a later stage if that seems necessary.closes #4003