Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2bc751b
Add new dictionary functions and extern declarations
clin1234 Apr 4, 2026
607ecf2
Add PyDict_SetDefaultRef function declaration
clin1234 Apr 4, 2026
f093984
Create 5947.added.md
clin1234 Apr 4, 2026
6807fcc
Fix syntax errors in dictobject.rs configuration flags
clin1234 Apr 4, 2026
fb3a9a1
Reorder imports in dictobject.rs
clin1234 Apr 4, 2026
728a911
Update PyDict_SetDefaultRef and PyDict_Pop signatures
clin1234 Apr 4, 2026
59c92c4
Fix pointer type in PyDict_SetDefaultRef function
clin1234 Apr 4, 2026
81ec769
Fmt
clin1234 Apr 4, 2026
0c1b437
Fix conditional compilation directive for PyDict_SetDefaultRef
clin1234 Apr 4, 2026
73cb54b
Update conditional compilation for PyDict_SetDefaultRef
clin1234 Apr 4, 2026
8067d5c
Change key parameter type from char to c_char
clin1234 Apr 4, 2026
85df96f
Update imports for Python version compatibility
clin1234 Apr 4, 2026
30f89df
Fix typo in import statement for c_int
clin1234 Apr 4, 2026
614c268
Reintroduce PyDict_SetDefaultRef for Python 3.15
clin1234 Apr 11, 2026
87b4dd1
Fix cfg attribute syntax in dictobject.rs
clin1234 Apr 11, 2026
e493c64
Reorganize use statements in dictobject.rs
clin1234 Apr 11, 2026
3ac9a04
Remove PyObject_GenericGetDict declaration
clin1234 Apr 11, 2026
b268453
Remove unused c_void import in dictobject.rs
clin1234 Apr 11, 2026
bfdbe1b
Update PyDict_SetDefaultRef for Python 3.13 compatibility
clin1234 Apr 11, 2026
d8ff2f7
Comment out PyDict_SetDefaultRef function
clin1234 Apr 11, 2026
6f2e790
Merge branch 'main' into patch-2
clin1234 Apr 17, 2026
86ddff9
Member naming
clin1234 Apr 17, 2026
8833271
Mark function as part of Stable API as of 3.15
clin1234 Apr 17, 2026
56a3901
Reorder dictobject.rs to mirror upstream C header
clin1234 Apr 17, 2026
3d41d5f
Space
clin1234 Apr 17, 2026
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
11 changes: 11 additions & 0 deletions newsfragments/5947.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Added the following functions:

* pub fn PyDict_SetDefault(mp: *mut PyObject, key: *mut PyObject, default_obj: *mut PyObject) -> *mut PyObject;
* pub fn PyDict_SetDefaultRef(mp: *mut PyObject, key: *mut PyObject, default_obj: *mut PyObject, result: **mut PyObject) -> c_int;
* pub fn PyDict_ContainsString(mp: *mut PyObject, key: *const char) -> c_int;
* pub fn PyDict_Pop(dict: *mut PyObject, key: *mut PyObject, result: **mut PyObject) -> c_int;
* pub fn PyDict_PopString(dict: *mut PyObject, key: *const c_char, result: **mut PyObject) -> c_int;
* pub fn PyDict_ClearWatcher(watcher_id: c_int) -> c_int;
* pub fn PyDict_Watch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
* pub fn PyDict_Unwatch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
* pub fn PyFrozenDict_New(iterable: *mut PyObject) -> *mut PyObject;
57 changes: 50 additions & 7 deletions pyo3-ffi/src/cpython/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use crate::object::*;
#[cfg(not(any(PyPy, GraalPy)))]
use crate::pyport::Py_ssize_t;

#[cfg(all(not(PyPy), Py_3_13))]
use std::ffi::c_char;
#[cfg(all(not(PyPy), Py_3_12))]
use std::ffi::c_int;

#[cfg(not(PyPy))]
opaque_struct!(pub PyDictKeysObject);

Expand Down Expand Up @@ -39,18 +44,51 @@ pub struct PyDictObject {
_tmpkeys: *mut PyObject,
}

extern_libpython! {
Comment thread
Tpt marked this conversation as resolved.
Comment thread
Tpt marked this conversation as resolved.
#[cfg(Py_3_15)]
pub fn PyFrozenDict_New(iterable: *mut PyObject) -> *mut PyObject;
}

// skipped private _PyDict_GetItem_KnownHash
// skipped private _PyDict_GetItemStringWithError

// skipped PyDict_SetDefault
extern_libpython! {
pub fn PyDict_SetDefault(
mp: *mut PyObject,
key: *mut PyObject,
default_obj: *mut PyObject,
) -> *mut PyObject;
/*
#[cfg(all(Py_3_13, not(Py_3_15)))]
pub fn PyDict_SetDefaultRef(
mp: *mut PyObject,
key: *mut PyObject,
default_obj: *mut PyObject,
result: *mut *mut PyObject,
) -> c_int;
*/
}

// skipped PyDict_GET_SIZE
// skipped PyDict_ContainsString

extern_libpython! {
#[cfg(Py_3_13)]
pub fn PyDict_ContainsString(mp: *mut PyObject, key: *const c_char) -> c_int;
}

// skipped private _PyDict_NewPresized

// skipped PyDict_Pop
// skipped PyDict_PopString
extern_libpython! {
#[cfg(Py_3_13)]
pub fn PyDict_Pop(dict: *mut PyObject, key: *mut PyObject, result: *mut *mut PyObject)
-> c_int;
#[cfg(Py_3_13)]
pub fn PyDict_PopString(
dict: *mut PyObject,
key: *const c_char,
result: *mut *mut PyObject,
) -> c_int;
}

// skipped private _PyDict_Pop

Expand All @@ -60,7 +98,12 @@ pub struct PyDictObject {
// skipped PyDict_WatchCallback

// skipped PyDict_AddWatcher
// skipped PyDict_ClearWatcher

// skipped PyDict_Watch
// skipped PyDict_Unwatch
extern_libpython! {
#[cfg(Py_3_12)]
pub fn PyDict_ClearWatcher(watcher_id: c_int) -> c_int;
#[cfg(Py_3_12)]
pub fn PyDict_Watch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
#[cfg(Py_3_12)]
pub fn PyDict_Unwatch(watcher_id: c_int, dict: *mut PyObject) -> c_int;
}
Loading