1use crate::object::*;
2use crate::pyport::Py_ssize_t;
3use std::os::raw::{c_char, c_int};
4use std::ptr::addr_of_mut;
5
6#[cfg_attr(windows, link(name = "pythonXY"))]
7extern "C" {
8 #[cfg_attr(PyPy, link_name = "PyPyDict_Type")]
9 pub static mut PyDict_Type: PyTypeObject;
10}
11
12#[inline]
13pub unsafe fn PyDict_Check(op: *mut PyObject) -> c_int {
14 PyType_FastSubclass(t:Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
15}
16
17#[inline]
18pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int {
19 (Py_TYPE(ob:op) == addr_of_mut!(PyDict_Type)) as c_int
20}
21
22extern "C" {
23 #[cfg_attr(PyPy, link_name = "PyPyDict_New")]
24 pub fn PyDict_New() -> *mut PyObject;
25 #[cfg_attr(PyPy, link_name = "PyPyDict_GetItem")]
26 pub fn PyDict_GetItem(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
27 #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemWithError")]
28 pub fn PyDict_GetItemWithError(mp: *mut PyObject, key: *mut PyObject) -> *mut PyObject;
29 #[cfg_attr(PyPy, link_name = "PyPyDict_SetItem")]
30 pub fn PyDict_SetItem(mp: *mut PyObject, key: *mut PyObject, item: *mut PyObject) -> c_int;
31 #[cfg_attr(PyPy, link_name = "PyPyDict_DelItem")]
32 pub fn PyDict_DelItem(mp: *mut PyObject, key: *mut PyObject) -> c_int;
33 #[cfg_attr(PyPy, link_name = "PyPyDict_Clear")]
34 pub fn PyDict_Clear(mp: *mut PyObject);
35 #[cfg_attr(PyPy, link_name = "PyPyDict_Next")]
36 pub fn PyDict_Next(
37 mp: *mut PyObject,
38 pos: *mut Py_ssize_t,
39 key: *mut *mut PyObject,
40 value: *mut *mut PyObject,
41 ) -> c_int;
42 #[cfg_attr(PyPy, link_name = "PyPyDict_Keys")]
43 pub fn PyDict_Keys(mp: *mut PyObject) -> *mut PyObject;
44 #[cfg_attr(PyPy, link_name = "PyPyDict_Values")]
45 pub fn PyDict_Values(mp: *mut PyObject) -> *mut PyObject;
46 #[cfg_attr(PyPy, link_name = "PyPyDict_Items")]
47 pub fn PyDict_Items(mp: *mut PyObject) -> *mut PyObject;
48 #[cfg_attr(PyPy, link_name = "PyPyDict_Size")]
49 pub fn PyDict_Size(mp: *mut PyObject) -> Py_ssize_t;
50 #[cfg_attr(PyPy, link_name = "PyPyDict_Copy")]
51 pub fn PyDict_Copy(mp: *mut PyObject) -> *mut PyObject;
52 #[cfg_attr(PyPy, link_name = "PyPyDict_Contains")]
53 pub fn PyDict_Contains(mp: *mut PyObject, key: *mut PyObject) -> c_int;
54 #[cfg_attr(PyPy, link_name = "PyPyDict_Update")]
55 pub fn PyDict_Update(mp: *mut PyObject, other: *mut PyObject) -> c_int;
56 #[cfg_attr(PyPy, link_name = "PyPyDict_Merge")]
57 pub fn PyDict_Merge(mp: *mut PyObject, other: *mut PyObject, _override: c_int) -> c_int;
58 pub fn PyDict_MergeFromSeq2(d: *mut PyObject, seq2: *mut PyObject, _override: c_int) -> c_int;
59 #[cfg_attr(PyPy, link_name = "PyPyDict_GetItemString")]
60 pub fn PyDict_GetItemString(dp: *mut PyObject, key: *const c_char) -> *mut PyObject;
61 #[cfg_attr(PyPy, link_name = "PyPyDict_SetItemString")]
62 pub fn PyDict_SetItemString(
63 dp: *mut PyObject,
64 key: *const c_char,
65 item: *mut PyObject,
66 ) -> c_int;
67 #[cfg_attr(PyPy, link_name = "PyPyDict_DelItemString")]
68 pub fn PyDict_DelItemString(dp: *mut PyObject, key: *const c_char) -> c_int;
69 // skipped 3.10 / ex-non-limited PyObject_GenericGetDict
70}
71
72#[cfg_attr(windows, link(name = "pythonXY"))]
73extern "C" {
74 pub static mut PyDictKeys_Type: PyTypeObject;
75 pub static mut PyDictValues_Type: PyTypeObject;
76 pub static mut PyDictItems_Type: PyTypeObject;
77}
78
79#[inline]
80pub unsafe fn PyDictKeys_Check(op: *mut PyObject) -> c_int {
81 (Py_TYPE(ob:op) == addr_of_mut!(PyDictKeys_Type)) as c_int
82}
83
84#[inline]
85pub unsafe fn PyDictValues_Check(op: *mut PyObject) -> c_int {
86 (Py_TYPE(ob:op) == addr_of_mut!(PyDictValues_Type)) as c_int
87}
88
89#[inline]
90pub unsafe fn PyDictItems_Check(op: *mut PyObject) -> c_int {
91 (Py_TYPE(ob:op) == addr_of_mut!(PyDictItems_Type)) as c_int
92}
93
94#[inline]
95pub unsafe fn PyDictViewSet_Check(op: *mut PyObject) -> c_int {
96 (PyDictKeys_Check(op) != 0 || PyDictItems_Check(op) != 0) as c_int
97}
98
99#[cfg_attr(windows, link(name = "pythonXY"))]
100extern "C" {
101 pub static mut PyDictIterKey_Type: PyTypeObject;
102 pub static mut PyDictIterValue_Type: PyTypeObject;
103 pub static mut PyDictIterItem_Type: PyTypeObject;
104 #[cfg(Py_3_8)]
105 pub static mut PyDictRevIterKey_Type: PyTypeObject;
106 #[cfg(Py_3_8)]
107 pub static mut PyDictRevIterValue_Type: PyTypeObject;
108 #[cfg(Py_3_8)]
109 pub static mut PyDictRevIterItem_Type: PyTypeObject;
110}
111
112#[cfg(any(PyPy, Py_LIMITED_API))]
113// TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985)
114opaque_struct!(PyDictObject);
115