Skip to content

Commit 71b6cb5

Browse files
committed
std::mem::MaybeUninit
1 parent bdac329 commit 71b6cb5

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/decode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub fn deserialize(ptr: *mut pyo3::ffi::PyObject) -> PyResult<NonNull<pyo3::ffi:
1515
let obj_type_ptr = unsafe { (*ptr).ob_type };
1616
let data: Cow<str>;
1717
if unsafe { obj_type_ptr == typeref::STR_PTR } {
18-
let mut str_size: pyo3::ffi::Py_ssize_t = unsafe { std::mem::uninitialized() };
18+
let mut str_size: pyo3::ffi::Py_ssize_t =
19+
unsafe { std::mem::MaybeUninit::uninit().assume_init() };
1920
let uni = unsafe { pyo3::ffi::PyUnicode_AsUTF8AndSize(ptr, &mut str_size) as *const u8 };
2021
if unsafe { std::intrinsics::unlikely(uni.is_null()) } {
2122
return Err(JSONDecodeError::py_err((INVALID_STR, "", 0)));

src/encode.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ impl<'p> Serialize for SerializePyObject {
6565
{
6666
let obj_ptr = unsafe { (*self.ptr).ob_type };
6767
if unsafe { obj_ptr == STR_PTR } {
68-
let mut str_size: pyo3::ffi::Py_ssize_t = unsafe { std::mem::uninitialized() };
68+
let mut str_size: pyo3::ffi::Py_ssize_t =
69+
unsafe { std::mem::MaybeUninit::uninit().assume_init() };
6970
let uni =
7071
unsafe { pyo3::ffi::PyUnicode_AsUTF8AndSize(self.ptr, &mut str_size) as *const u8 };
7172
if unsafe { std::intrinsics::unlikely(uni.is_null()) } {
@@ -95,9 +96,12 @@ impl<'p> Serialize for SerializePyObject {
9596
} else if unsafe { obj_ptr == DICT_PTR } {
9697
let mut map = serializer.serialize_map(None).unwrap();
9798
let mut pos = 0isize;
98-
let mut str_size: pyo3::ffi::Py_ssize_t = unsafe { std::mem::uninitialized() };
99-
let mut key: *mut pyo3::ffi::PyObject = unsafe { std::mem::uninitialized() };
100-
let mut value: *mut pyo3::ffi::PyObject = unsafe { std::mem::uninitialized() };
99+
let mut str_size: pyo3::ffi::Py_ssize_t =
100+
unsafe { std::mem::MaybeUninit::uninit().assume_init() };
101+
let mut key: *mut pyo3::ffi::PyObject =
102+
unsafe { std::mem::MaybeUninit::uninit().assume_init() };
103+
let mut value: *mut pyo3::ffi::PyObject =
104+
unsafe { std::mem::MaybeUninit::uninit().assume_init() };
101105
while unsafe { pyo3::ffi::PyDict_Next(self.ptr, &mut pos, &mut key, &mut value) != 0 } {
102106
if unsafe { std::intrinsics::unlikely((*key).ob_type != STR_PTR) } {
103107
return Err(ser::Error::custom("Dict key must be str"));

0 commit comments

Comments
 (0)