Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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;
50 changes: 39 additions & 11 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,20 +44,47 @@ pub struct PyDictObject {
_tmpkeys: *mut PyObject,
}

extern_libpython! {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, forgot to talk about about pypy and graalpy. Have you checked if these functions are defined there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use either PyPy or GraalPy, so I can't tell you if these functions are used by either

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please place these functions in the correct locations in the file (makes it easier to compare against upstream in the future).

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;
#[cfg(Py_3_13)]
pub fn PyDict_ContainsString(mp: *mut PyObject, key: *const c_char) -> c_int;
#[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;
#[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;
#[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
// skipped PyDict_SetDefaultRef

// skipped PyDict_GET_SIZE
// skipped PyDict_ContainsString

// skipped private _PyDict_NewPresized

// skipped PyDict_Pop
// skipped PyDict_PopString

// skipped private _PyDict_Pop

// skipped PY_FOREACH_DICT_EVENT
Expand All @@ -61,7 +93,3 @@ pub struct PyDictObject {
// skipped PyDict_WatchCallback

// skipped PyDict_AddWatcher
// skipped PyDict_ClearWatcher

// skipped PyDict_Watch
// skipped PyDict_Unwatch
7 changes: 7 additions & 0 deletions pyo3-ffi/src/dictobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub unsafe fn PyDict_CheckExact(op: *mut PyObject) -> c_int {
}

extern_libpython! {
#[cfg(all(Py_3_15, not(Py_LIMITED_API)))]
pub fn PyDict_SetDefaultRef(
Comment thread
clin1234 marked this conversation as resolved.
Outdated
mp: *mut PyObject,
key: *mut PyObject,
default_obj: *mut PyObject,
result: *mut *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
Loading