Skip to content

Commit

Permalink
Add PyList_GetItemRef bindings and compat shim
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Aug 7, 2024
1 parent 0a185cd commit 6b249e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pyo3-ffi/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#[cfg(not(Py_3_13))]
use crate::object::PyObject;
#[cfg(not(Py_3_13))]
use crate::pyport::Py_ssize_t;
#[cfg(not(Py_3_13))]
use std::os::raw::c_int;

#[cfg_attr(docsrs, doc(cfg(all)))]
Expand Down Expand Up @@ -42,3 +44,16 @@ pub unsafe fn PyDict_GetItemRef(
-1
}
}

#[cfg_attr(docsrs, doc(cfg(all)))]
#[cfg(Py_3_13)]
pub use crate::PyList_GetItemRef;

#[cfg(not(Py_3_13))]
pub unsafe fn PyList_GetItemRef(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject {
use crate::{PyList_GetItem, Py_XINCREF};

let item: *mut PyObject = PyList_GetItem(arg1, arg2);
Py_XINCREF(item);
item
}
2 changes: 2 additions & 0 deletions pyo3-ffi/src/listobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern "C" {
pub fn PyList_Size(arg1: *mut PyObject) -> Py_ssize_t;
#[cfg_attr(PyPy, link_name = "PyPyList_GetItem")]
pub fn PyList_GetItem(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
#[cfg(Py_3_13)]
pub fn PyList_GetItemRef(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyList_SetItem")]
pub fn PyList_SetItem(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyList_Insert")]
Expand Down

0 comments on commit 6b249e9

Please sign in to comment.