pyo3_ffi/compat/
py_3_13.rs

1compat_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; // found
16        }
17        *result = std::ptr::null_mut();
18        if PyErr_Occurred().is_null() {
19            return 0; // not found
20        }
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 PyImport_AddModuleRef(
46        name: *const std::os::raw::c_char,
47    ) -> *mut crate::PyObject {
48        use crate::{compat::Py_XNewRef, PyImport_AddModule};
49
50        Py_XNewRef(PyImport_AddModule(name))
51    }
52);
53
54compat_function!(
55    originally_defined_for(Py_3_13);
56
57    #[inline]
58    pub unsafe fn PyWeakref_GetRef(
59        reference: *mut crate::PyObject,
60        pobj: *mut *mut crate::PyObject,
61    ) -> std::os::raw::c_int {
62        use crate::{
63            compat::Py_NewRef, PyErr_SetString, PyExc_TypeError, PyWeakref_Check,
64            PyWeakref_GetObject, Py_None,
65        };
66
67        if !reference.is_null() && PyWeakref_Check(reference) == 0 {
68            *pobj = std::ptr::null_mut();
69            PyErr_SetString(PyExc_TypeError, c_str!("expected a weakref").as_ptr());
70            return -1;
71        }
72        let obj = PyWeakref_GetObject(reference);
73        if obj.is_null() {
74            // SystemError if reference is NULL
75            *pobj = std::ptr::null_mut();
76            return -1;
77        }
78        if obj == Py_None() {
79            *pobj = std::ptr::null_mut();
80            return 0;
81        }
82        *pobj = Py_NewRef(obj);
83        1
84    }
85);
86
87compat_function!(
88    originally_defined_for(Py_3_13);
89
90    #[inline]
91    pub unsafe fn PyList_Extend(
92        list: *mut crate::PyObject,
93        iterable: *mut crate::PyObject,
94    ) -> std::os::raw::c_int {
95        crate::PyList_SetSlice(list, crate::PY_SSIZE_T_MAX, crate::PY_SSIZE_T_MAX, iterable)
96    }
97);
98
99compat_function!(
100    originally_defined_for(Py_3_13);
101
102    #[inline]
103    pub unsafe fn PyList_Clear(list: *mut crate::PyObject) -> std::os::raw::c_int {
104        crate::PyList_SetSlice(list, 0, crate::PY_SSIZE_T_MAX, std::ptr::null_mut())
105    }
106);