pyo3_ffi/compat/
py_3_13.rs1compat_function!(
2 originally_defined_for(Py_3_13);
3
4 #[inline]
5 pub unsafe fn PyDict_GetItemRef(
6 dp: *mut crate::PyObject,
7 key: *mut crate::PyObject,
8 result: *mut *mut crate::PyObject,
9 ) -> std::os::raw::c_int {
10 use crate::{compat::Py_NewRef, PyDict_GetItemWithError, PyErr_Occurred};
11
12 let item = PyDict_GetItemWithError(dp, key);
13 if !item.is_null() {
14 *result = Py_NewRef(item);
15 return 1; }
17 *result = std::ptr::null_mut();
18 if PyErr_Occurred().is_null() {
19 return 0; }
21 -1
22 }
23);
24
25compat_function!(
26 originally_defined_for(Py_3_13);
27
28 #[inline]
29 pub unsafe fn PyList_GetItemRef(
30 arg1: *mut crate::PyObject,
31 arg2: crate::Py_ssize_t,
32 ) -> *mut crate::PyObject {
33 use crate::{PyList_GetItem, Py_XINCREF};
34
35 let item = PyList_GetItem(arg1, arg2);
36 Py_XINCREF(item);
37 item
38 }
39);
40
41compat_function!(
42 originally_defined_for(Py_3_13);
43
44 #[inline]
45 pub unsafe fn PyWeakref_GetRef(
46 reference: *mut crate::PyObject,
47 pobj: *mut *mut crate::PyObject,
48 ) -> std::os::raw::c_int {
49 use crate::{
50 compat::Py_NewRef, PyErr_SetString, PyExc_TypeError, PyWeakref_Check,
51 PyWeakref_GetObject, Py_None,
52 };
53
54 if !reference.is_null() && PyWeakref_Check(reference) == 0 {
55 *pobj = std::ptr::null_mut();
56 PyErr_SetString(PyExc_TypeError, c_str!("expected a weakref").as_ptr());
57 return -1;
58 }
59 let obj = PyWeakref_GetObject(reference);
60 if obj.is_null() {
61 *pobj = std::ptr::null_mut();
63 return -1;
64 }
65 if obj == Py_None() {
66 *pobj = std::ptr::null_mut();
67 return 0;
68 }
69 *pobj = Py_NewRef(obj);
70 1
71 }
72);