pyo3_ffi/cpython/
dictobject.rs1#[cfg(not(GraalPy))]
2use crate::object::*;
3#[cfg(not(any(PyPy, GraalPy)))]
4use crate::pyport::Py_ssize_t;
5#[cfg(all(GraalPy, Py_3_13))]
6use crate::PyObject;
7
8#[cfg(Py_3_15)]
9use crate::{dictobject::PyDict_Check, PyDict_CheckExact};
10
11#[cfg(all(not(PyPy), Py_3_13))]
12use core::ffi::c_char;
13#[cfg(all(not(PyPy), Py_3_12))]
14use core::ffi::c_int;
15
16#[cfg(not(PyPy))]
17opaque_struct!(pub PyDictKeysObject);
18
19#[cfg(Py_3_11)]
20#[cfg(not(PyPy))]
21opaque_struct!(pub PyDictValues);
22
23#[cfg(not(any(GraalPy, PyPy)))]
24#[repr(C)]
25#[derive(Debug)]
26pub struct PyDictObject {
27 pub ob_base: PyObject,
28 pub ma_used: Py_ssize_t,
29 #[cfg_attr(
30 Py_3_12,
31 deprecated(note = "Deprecated in Python 3.12 and will be removed in the future.")
32 )]
33 #[cfg(not(Py_3_14))]
34 pub ma_version_tag: u64,
35 #[cfg(Py_3_14)]
36 _ma_watcher_tag: u64,
37 pub ma_keys: *mut PyDictKeysObject,
38 #[cfg(not(Py_3_11))]
39 pub ma_values: *mut *mut PyObject,
40 #[cfg(Py_3_11)]
41 pub ma_values: *mut PyDictValues,
42}
43
44#[cfg(PyPy)]
45#[repr(C)]
46#[derive(Debug)]
47pub struct PyDictObject {
48 pub ob_base: PyObject,
49 _tmpkeys: *mut PyObject,
50}
51
52extern_libpython! {
53 #[cfg(Py_3_15)]
54 pub static mut PyFrozenDict_Type: PyTypeObject;
55}
56
57#[inline]
58#[cfg(Py_3_15)]
59pub unsafe fn PyFrozenDict_CheckExact(op: *mut PyObject) -> c_int {
60 Py_IS_TYPE(op, &raw mut PyFrozenDict_Type)
61}
62
63#[inline]
64#[cfg(Py_3_15)]
65pub unsafe fn PyFrozenDict_Check(op: *mut PyObject) -> c_int {
66 PyObject_TypeCheck(op, &raw mut PyFrozenDict_Type)
67}
68
69#[inline]
70#[cfg(Py_3_15)]
71pub unsafe fn PyAnyDict_Check(op: *mut PyObject) -> c_int {
72 (PyDict_Check(op) != 0 || PyFrozenDict_Check(op) != 0) as c_int
73}
74
75#[inline]
76#[cfg(Py_3_15)]
77pub unsafe fn PyAnyDict_CheckExact(op: *mut PyObject) -> c_int {
78 (PyDict_CheckExact(op) != 0 || PyFrozenDict_CheckExact(op) != 0) as c_int
79}
80
81extern_libpython! {
85 #[cfg(not(GraalPy))]
86 pub fn PyDict_SetDefault(
87 mp: *mut PyObject,
88 key: *mut PyObject,
89 default_obj: *mut PyObject,
90 ) -> *mut PyObject;
91 }
101
102extern_libpython! {
105 #[cfg(Py_3_13)]
106 pub fn PyDict_ContainsString(mp: *mut PyObject, key: *const c_char) -> c_int;
107}
108
109extern_libpython! {
112 #[cfg(Py_3_13)]
113 pub fn PyDict_Pop(dict: *mut PyObject, key: *mut PyObject, result: *mut *mut PyObject)
114 -> c_int;
115 #[cfg(Py_3_13)]
116 pub fn PyDict_PopString(
117 dict: *mut PyObject,
118 key: *const c_char,
119 result: *mut *mut PyObject,
120 ) -> c_int;
121}
122
123extern_libpython! {
133 #[cfg(Py_3_12)]
134 pub fn PyDict_ClearWatcher(watcher_id: c_int) -> c_int;
135 #[cfg(Py_3_12)]
136 #[cfg(not(GraalPy))]
137 pub fn PyDict_Watch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
138 #[cfg(Py_3_12)]
139 #[cfg(not(GraalPy))]
140 pub fn PyDict_Unwatch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
141}
142
143extern_libpython! {
144 #[cfg(Py_3_15)]
145 pub fn PyFrozenDict_New(iterable: *mut PyObject) -> *mut PyObject;
146}