From c5fd226e8b331db42fb6ff24b272662cb73d4b1c Mon Sep 17 00:00:00 2001 From: ijl Date: Thu, 7 Sep 2023 22:36:44 +0000 Subject: [PATCH] python3.13 FFI removals --- src/deserialize/yyjson.rs | 3 +++ src/ffi/dict.rs | 15 +++++++++++++++ src/util.rs | 9 ++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/deserialize/yyjson.rs b/src/deserialize/yyjson.rs index 862da0b6..20e4005c 100644 --- a/src/deserialize/yyjson.rs +++ b/src/deserialize/yyjson.rs @@ -175,7 +175,10 @@ fn parse_yy_object(elem: *mut yyjson_val) -> NonNull { return nonnull!(ffi!(PyDict_New())); } let mut key = unsafe_yyjson_get_first(elem); + #[cfg(not(Py_3_13))] let dict = ffi!(_PyDict_NewPresized(len as isize)); + #[cfg(Py_3_13)] + let dict = ffi!(PyDict_New()); for _ in 0..=len - 1 { let val = key.add(1); let key_str = str_from_slice!((*key).uni.str_ as *const u8, unsafe_yyjson_get_len(key)); diff --git a/src/ffi/dict.rs b/src/ffi/dict.rs index 304be8b6..21cc3a70 100644 --- a/src/ffi/dict.rs +++ b/src/ffi/dict.rs @@ -22,6 +22,21 @@ impl PyDictIter { impl Iterator for PyDictIter { type Item = (NonNull, NonNull); + #[cfg(Py_3_13)] + #[inline] + fn next(&mut self) -> Option { + let mut key: *mut pyo3_ffi::PyObject = std::ptr::null_mut(); + let mut value: *mut pyo3_ffi::PyObject = std::ptr::null_mut(); + unsafe { + if pyo3_ffi::PyDict_Next(self.dict_ptr, &mut self.pos, &mut key, &mut value) == 1 { + Some((nonnull!(key), nonnull!(value))) + } else { + None + } + } + } + + #[cfg(not(Py_3_13))] #[inline] fn next(&mut self) -> Option { let mut key: *mut pyo3_ffi::PyObject = std::ptr::null_mut(); diff --git a/src/util.rs b/src/util.rs index fc6cd21a..fa3b7e1d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -139,7 +139,14 @@ macro_rules! str_hash { }; } -#[cfg(Py_3_12)] +#[cfg(Py_3_13)] +macro_rules! pydict_contains { + ($obj1:expr, $obj2:expr) => { + unsafe { pyo3_ffi::PyDict_Contains((*$obj1).tp_dict, $obj2) == 1 } + }; +} + +#[cfg(all(Py_3_12, not(Py_3_13)))] macro_rules! pydict_contains { ($obj1:expr, $obj2:expr) => { unsafe {