Skip to content

Commit ddcc3f2

Browse files
fix msrv
1 parent 05302b1 commit ddcc3f2

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

pyo3-ffi/src/compat/py_3_15.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ compat_function!(
1212
return std::ptr::null_mut();
1313
}
1414

15-
let writer: *mut crate::PyBytesWriter = crate::PyMem_Malloc(size_of::<crate::PyBytesWriter>()).cast();
15+
let writer: *mut crate::PyBytesWriter = crate::PyMem_Malloc(std::mem::size_of::<crate::PyBytesWriter>()).cast();
1616
if writer.is_null() {
1717
crate::PyErr_NoMemory();
1818
return std::ptr::null_mut();
@@ -74,7 +74,7 @@ compat_function!(
7474
PyBytesWriter_Discard(writer);
7575
return std::ptr::null_mut();
7676
}
77-
std::mem::take(&mut (*writer).obj)
77+
std::mem::replace(&mut (*writer).obj, std::ptr::null_mut())
7878
};
7979

8080
PyBytesWriter_Discard(writer);
@@ -89,7 +89,7 @@ compat_function!(
8989
#[inline]
9090
pub unsafe fn _PyBytesWriter_GetAllocated(writer: *mut crate::PyBytesWriter) -> crate::Py_ssize_t {
9191
if (*writer).obj.is_null() {
92-
size_of_val(&(*writer).small_buffer) as _
92+
std::mem::size_of_val(&(*writer).small_buffer) as _
9393
} else {
9494
crate::PyBytes_Size((*writer).obj)
9595
}
@@ -212,12 +212,12 @@ unsafe fn _PyBytesWriter_Resize_impl(
212212
}
213213

214214
if resize > 0 {
215-
assert!((size as usize) > size_of_val(&(*writer).small_buffer));
215+
assert!((size as usize) > std::mem::size_of_val(&(*writer).small_buffer));
216216

217217
std::ptr::copy_nonoverlapping(
218218
(*writer).small_buffer.as_ptr(),
219219
crate::PyBytes_AS_STRING((*writer).obj) as *mut _,
220-
size_of_val(&(*writer).small_buffer),
220+
std::mem::size_of_val(&(*writer).small_buffer),
221221
);
222222
}
223223
}

src/byteswriter.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
use crate::ffi_ptr_ext::FfiPtrExt;
2-
use crate::py_result_ext::PyResultExt;
31
use crate::types::PyBytes;
4-
use crate::{ffi, Bound, IntoPyObject, PyErr, PyResult, Python};
52
#[cfg(not(Py_LIMITED_API))]
6-
use pyo3_ffi::compat::{
7-
PyBytesWriter_Create, PyBytesWriter_Discard, PyBytesWriter_Finish, PyBytesWriter_GetData,
8-
PyBytesWriter_GetSize, PyBytesWriter_Grow, PyBytesWriter_WriteBytes,
9-
_PyBytesWriter_GetAllocated,
3+
use crate::{
4+
ffi::{
5+
self,
6+
compat::{
7+
PyBytesWriter_Create, PyBytesWriter_Discard, PyBytesWriter_Finish,
8+
PyBytesWriter_GetData, PyBytesWriter_GetSize, PyBytesWriter_Grow,
9+
PyBytesWriter_WriteBytes, _PyBytesWriter_GetAllocated,
10+
},
11+
},
12+
ffi_ptr_ext::FfiPtrExt,
13+
py_result_ext::PyResultExt,
1014
};
15+
use crate::{Bound, IntoPyObject, PyErr, PyResult, Python};
1116
use std::io::IoSlice;
1217
#[cfg(not(Py_LIMITED_API))]
1318
use std::ptr::{self, NonNull};
@@ -95,7 +100,7 @@ impl<'py> TryFrom<PyBytesWriter<'py>> for Bound<'py, PyBytes> {
95100
impl<'py> From<PyBytesWriter<'py>> for Bound<'py, PyBytes> {
96101
#[inline]
97102
fn from(writer: PyBytesWriter<'py>) -> Self {
98-
Ok(PyBytes::new(&writer.buffer))
103+
PyBytes::new(writer.python, &writer.buffer)
99104
}
100105
}
101106

@@ -186,7 +191,7 @@ impl std::io::Write for PyBytesWriter<'_> {
186191
}
187192

188193
#[inline]
189-
fn write_fmt(&mut self, args: Arguments<'_>) -> std::io::Result<()> {
194+
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> {
190195
self.buffer.write_fmt(args)
191196
}
192197
}
@@ -199,7 +204,7 @@ mod tests {
199204
#[test]
200205
fn test_io_write() {
201206
Python::attach(|py| {
202-
let buf: [u8; _] = [1, 2, 3, 4];
207+
let buf = [1, 2, 3, 4];
203208
let mut writer = PyBytesWriter::new(py).unwrap();
204209
writer.write(&buf).unwrap();
205210
let bytes: Bound<'_, PyBytes> = writer.try_into().unwrap();

0 commit comments

Comments
 (0)