pyo3_ffi/compat/
py_3_10.rs

1compat_function!(
2    originally_defined_for(Py_3_10);
3
4    #[inline]
5    pub unsafe fn Py_NewRef(obj: *mut crate::PyObject) -> *mut crate::PyObject {
6        crate::Py_INCREF(obj);
7        obj
8    }
9);
10
11compat_function!(
12    originally_defined_for(Py_3_10);
13
14    #[inline]
15    pub unsafe fn Py_XNewRef(obj: *mut crate::PyObject) -> *mut crate::PyObject {
16        crate::Py_XINCREF(obj);
17        obj
18    }
19);
20
21compat_function!(
22    originally_defined_for(Py_3_10);
23
24    #[inline]
25    pub unsafe fn PyModule_AddObjectRef(
26        module: *mut crate::PyObject,
27        name: *const std::ffi::c_char,
28        value: *mut crate::PyObject,
29    ) -> std::ffi::c_int {
30        if value.is_null() && crate::PyErr_Occurred().is_null() {
31            crate::PyErr_SetString(
32                crate::PyExc_SystemError,
33                c_str!("PyModule_AddObjectRef() must be called with an exception raised if value is NULL").as_ptr(),
34            );
35            return -1;
36        }
37
38        crate::Py_XINCREF(value);
39        let result = crate::PyModule_AddObject(module, name, value);
40        if result < 0 {
41            crate::Py_XDECREF(value);
42        }
43        result
44    }
45);