Skip to content

Commit 9ff6389

Browse files
authored
sync FFI definitions for dictobject.h to 3.14 (#5659)
* sync FFI definitions for `dictobject.h` to 3.14 * newsfragments * fix unused imports on GraalPy
1 parent 24204e5 commit 9ff6389

File tree

4 files changed

+38
-62
lines changed

4 files changed

+38
-62
lines changed

newsfragments/5659.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add FFI definition `PyDict_GetItemStringRef` on Python 3.13 and up.

newsfragments/5659.removed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove private FFI definitions `_PyDict_SetItem_KnownHash`, `_PyDict_Next`, `_PyDict_NewPresized`, `_PyDict_Contains_KnownHash`, and `_PyDict_Contains`.

pyo3-ffi/src/cpython/dictobject.rs

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
#[cfg(not(GraalPy))]
12
use crate::object::*;
2-
#[cfg(not(PyPy))]
3+
#[cfg(not(any(PyPy, GraalPy)))]
34
use crate::pyport::Py_ssize_t;
4-
#[cfg(not(PyPy))]
5-
use std::ffi::c_int;
65

76
#[cfg(not(PyPy))]
87
opaque_struct!(pub PyDictKeysObject);
@@ -40,61 +39,29 @@ pub struct PyDictObject {
4039
_tmpkeys: *mut PyObject,
4140
}
4241

43-
extern "C" {
44-
// skipped _PyDict_GetItem_KnownHash
45-
// skipped _PyDict_GetItemIdWithError
46-
// skipped _PyDict_GetItemStringWithError
47-
// skipped PyDict_SetDefault
48-
#[cfg(not(PyPy))]
49-
pub fn _PyDict_SetItem_KnownHash(
50-
mp: *mut PyObject,
51-
key: *mut PyObject,
52-
item: *mut PyObject,
53-
hash: crate::Py_hash_t,
54-
) -> c_int;
55-
// skipped _PyDict_DelItem_KnownHash
56-
// skipped _PyDict_DelItemIf
57-
// skipped _PyDict_NewKeysForClass
58-
#[cfg(not(PyPy))]
59-
pub fn _PyDict_Next(
60-
mp: *mut PyObject,
61-
pos: *mut Py_ssize_t,
62-
key: *mut *mut PyObject,
63-
value: *mut *mut PyObject,
64-
hash: *mut crate::Py_hash_t,
65-
) -> c_int;
66-
// skipped PyDict_GET_SIZE
67-
// skipped _PyDict_ContainsId
68-
#[cfg(not(PyPy))]
69-
pub fn _PyDict_NewPresized(minused: Py_ssize_t) -> *mut PyObject;
70-
// skipped _PyDict_MaybeUntrack
71-
// skipped _PyDict_HasOnlyStringKeys
72-
// skipped _PyDict_KeysSize
73-
// skipped _PyDict_SizeOf
74-
// skipped _PyDict_Pop
75-
// skipped _PyDict_Pop_KnownHash
76-
// skipped _PyDict_FromKeys
77-
// skipped _PyDict_HasSplitTable
78-
// skipped _PyDict_MergeEx
79-
// skipped _PyDict_SetItemId
80-
// skipped _PyDict_DelItemId
81-
// skipped _PyDict_DebugMallocStats
82-
// skipped _PyObjectDict_SetItem
83-
// skipped _PyDict_LoadGlobal
84-
// skipped _PyDict_GetItemHint
85-
// skipped _PyDictViewObject
86-
// skipped _PyDictView_New
87-
// skipped _PyDictView_Intersect
42+
// skipped private _PyDict_GetItem_KnownHash
43+
// skipped private _PyDict_GetItemStringWithError
8844

89-
#[cfg(Py_3_10)]
90-
#[cfg(not(PyPy))]
91-
pub fn _PyDict_Contains_KnownHash(
92-
op: *mut PyObject,
93-
key: *mut PyObject,
94-
hash: crate::Py_hash_t,
95-
) -> c_int;
45+
// skipped PyDict_SetDefault
46+
// skipped PyDict_SetDefaultRef
9647

97-
#[cfg(not(Py_3_10))]
98-
#[cfg(not(PyPy))]
99-
pub fn _PyDict_Contains(mp: *mut PyObject, key: *mut PyObject, hash: Py_ssize_t) -> c_int;
100-
}
48+
// skipped PyDict_GET_SIZE
49+
// skipped PyDict_ContainsString
50+
51+
// skipped private _PyDict_NewPresized
52+
53+
// skipped PyDict_Pop
54+
// skipped PyDict_PopString
55+
56+
// skipped private _PyDict_Pop
57+
58+
// skipped PY_FOREACH_DICT_EVENT
59+
// skipped PyDict_WatchEvent
60+
61+
// skipped PyDict_WatchCallback
62+
63+
// skipped PyDict_AddWatcher
64+
// skipped PyDict_ClearWatcher
65+
66+
// skipped PyDict_Watch
67+
// skipped PyDict_Unwatch

pyo3-ffi/src/dictobject.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ extern "C" {
7373
key: *mut PyObject,
7474
result: *mut *mut PyObject,
7575
) -> c_int;
76+
#[cfg(Py_3_13)]
77+
#[cfg_attr(PyPy, link_name = "PyPyDict_GetItemStringRef")]
78+
pub fn PyDict_GetItemStringRef(
79+
dp: *mut PyObject,
80+
key: *const c_char,
81+
result: *mut *mut PyObject,
82+
) -> c_int;
7683
// skipped 3.10 / ex-non-limited PyObject_GenericGetDict
7784
}
7885

@@ -85,17 +92,17 @@ extern "C" {
8592

8693
#[inline]
8794
pub unsafe fn PyDictKeys_Check(op: *mut PyObject) -> c_int {
88-
(Py_TYPE(op) == addr_of_mut!(PyDictKeys_Type)) as c_int
95+
PyObject_TypeCheck(op, addr_of_mut!(PyDictKeys_Type))
8996
}
9097

9198
#[inline]
9299
pub unsafe fn PyDictValues_Check(op: *mut PyObject) -> c_int {
93-
(Py_TYPE(op) == addr_of_mut!(PyDictValues_Type)) as c_int
100+
PyObject_TypeCheck(op, addr_of_mut!(PyDictValues_Type))
94101
}
95102

96103
#[inline]
97104
pub unsafe fn PyDictItems_Check(op: *mut PyObject) -> c_int {
98-
(Py_TYPE(op) == addr_of_mut!(PyDictItems_Type)) as c_int
105+
PyObject_TypeCheck(op, addr_of_mut!(PyDictItems_Type))
99106
}
100107

101108
#[inline]

0 commit comments

Comments
 (0)