Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/6174.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for `PyFrozenDict` on 3.15+
4 changes: 4 additions & 0 deletions pyo3-ffi-check/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ const MACRO_EXCLUSIONS: &[(&str, &str)] = &[
// FIXME: for many of these `not(PyPy)` cases,
// it seems that PyPy might actually offer symbols which PyO3
// should be using rather than implementing inline functions
("PyAnyDict_Check", ""),
("PyAnyDict_CheckExact", ""),
("PyAnySet_Check", "not(PyPy)"),
("PyAnySet_CheckExact", "not(PyPy)"),
("PyAsyncGen_CheckExact", ""),
Expand Down Expand Up @@ -324,6 +326,8 @@ const MACRO_EXCLUSIONS: &[(&str, &str)] = &[
("PyFloat_CheckExact", "not(PyPy)"),
("PyFrame_Check", ""),
("PyFrameLocalsProxy_Check", ""),
("PyFrozenDict_Check", ""),
("PyFrozenDict_CheckExact", ""),
("PyFrozenSet_Check", "not(PyPy)"),
("PyFrozenSet_CheckExact", "not(PyPy)"),
("PyFunction_Check", "not(PyPy)"),
Expand Down
34 changes: 33 additions & 1 deletion pyo3-ffi/src/cpython/dictobject.rs
Comment thread
Icxolu marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use crate::object::*;
#[cfg(not(any(PyPy, GraalPy)))]
use crate::pyport::Py_ssize_t;

#[cfg(Py_3_15)]
use crate::{dictobject::PyDict_Check, PyDict_CheckExact};

#[cfg(all(not(PyPy), Py_3_13))]
use core::ffi::c_char;
#[cfg(all(not(PyPy), Py_3_12))]
Expand Down Expand Up @@ -46,7 +49,31 @@ pub struct PyDictObject {

extern_libpython! {
#[cfg(Py_3_15)]
pub fn PyFrozenDict_New(iterable: *mut PyObject) -> *mut PyObject;
pub static mut PyFrozenDict_Type: PyTypeObject;
}

#[inline]
#[cfg(Py_3_15)]
pub unsafe fn PyFrozenDict_CheckExact(op: *mut PyObject) -> c_int {
Py_IS_TYPE(op, &raw mut PyFrozenDict_Type)
}

#[inline]
#[cfg(Py_3_15)]
pub unsafe fn PyFrozenDict_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, &raw mut PyFrozenDict_Type)
}

#[inline]
#[cfg(Py_3_15)]
pub unsafe fn PyAnyDict_Check(op: *mut PyObject) -> c_int {
(PyDict_Check(op) != 0 || PyFrozenDict_Check(op) != 0) as c_int
}

#[inline]
#[cfg(Py_3_15)]
pub unsafe fn PyAnyDict_CheckExact(op: *mut PyObject) -> c_int {
(PyDict_CheckExact(op) != 0 || PyFrozenDict_CheckExact(op) != 0) as c_int
}

// skipped private _PyDict_GetItem_KnownHash
Expand Down Expand Up @@ -110,3 +137,8 @@ extern_libpython! {
#[cfg(not(GraalPy))]
pub fn PyDict_Unwatch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
}

extern_libpython! {
#[cfg(Py_3_15)]
pub fn PyFrozenDict_New(iterable: *mut PyObject) -> *mut PyObject;
}
1 change: 0 additions & 1 deletion pyo3-ffi/src/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern_libpython! {
pub fn PyDict_Check(op: *mut PyObject) -> c_int;
#[cfg(RustPython)]
pub fn PyDict_CheckExact(op: *mut PyObject) -> c_int;

#[cfg_attr(PyPy, link_name = "PyPyDict_New")]
pub fn PyDict_New() -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")]
Expand Down
2 changes: 2 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub use crate::types::capsule::PyCapsuleMethods;
pub use crate::types::complex::PyComplexMethods;
pub use crate::types::dict::PyDictMethods;
pub use crate::types::float::PyFloatMethods;
#[cfg(Py_3_15)]
pub use crate::types::frozendict::PyFrozenDictMethods;
pub use crate::types::frozenset::PyFrozenSetMethods;
pub use crate::types::list::PyListMethods;
pub use crate::types::mapping::PyMappingMethods;
Expand Down
4 changes: 4 additions & 0 deletions src/sealed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::impl_::pyfunction::PyFunctionDef;
#[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
use crate::types::PyFrame;
#[cfg(Py_3_15)]
use crate::types::PyFrozenDict;
use crate::types::{
PyBool, PyByteArray, PyBytes, PyCapsule, PyComplex, PyDict, PyFloat, PyFrozenSet, PyList,
PyMapping, PyMappingProxy, PyModule, PyRange, PySequence, PySet, PySlice, PyString,
Expand Down Expand Up @@ -33,6 +35,8 @@ impl Sealed for Bound<'_, PyCapsule> {}
impl Sealed for Bound<'_, PyComplex> {}
impl Sealed for Bound<'_, PyDict> {}
impl Sealed for Bound<'_, PyFloat> {}
#[cfg(Py_3_15)]
impl Sealed for Bound<'_, PyFrozenDict> {}
impl Sealed for Bound<'_, PyFrozenSet> {}
impl Sealed for Bound<'_, PyList> {}
impl Sealed for Bound<'_, PyMapping> {}
Expand Down
Loading