Debian Codegraph @

src/weakrefobject.rs

raw symbols SCIP
1 use crate::object::*;
2 use std::ffi::c_int;
3 #[cfg(not(PyPy))]
4 use std::ptr::addr_of_mut;
5
6 #[cfg(all(not(PyPy), Py_LIMITED_API, not(GraalPy)))]
7 opaque_struct!(pub PyWeakReference);
8
9 #[cfg(all(not(PyPy), not(Py_LIMITED_API), not(GraalPy)))]
10 pub use crate::_PyWeakReference as PyWeakReference;
11
12 #[cfg_attr(windows, link(name = "pythonXY"))]
13 extern "C" {
14 // TODO: PyO3 is depending on this symbol in `reference.rs`, we should change this and
15 // remove the export as this is a private symbol.
16 pub static mut _PyWeakref_RefType: PyTypeObject;
17 static mut _PyWeakref_ProxyType: PyTypeObject;
18 static mut _PyWeakref_CallableProxyType: PyTypeObject;
19
20 #[cfg(PyPy)]
21 #[link_name = "PyPyWeakref_CheckRef"]
22 pub fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int;
23
24 #[cfg(PyPy)]
25 #[link_name = "PyPyWeakref_CheckRefExact"]
26 pub fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int;
27
28 #[cfg(PyPy)]
29 #[link_name = "PyPyWeakref_CheckProxy"]
30 pub fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int;
31 }
32
33 #[inline]
34 #[cfg(not(PyPy))]
35 pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
36 PyObject_TypeCheck(op, addr_of_mut!(_PyWeakref_RefType))
37 }
38
39 #[inline]
40 #[cfg(not(PyPy))]
41 pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
42 (Py_TYPE(op) == addr_of_mut!(_PyWeakref_RefType)) as c_int
43 }
44
45 #[inline]
46 #[cfg(not(PyPy))]
47 pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
48 ((Py_TYPE(op) == addr_of_mut!(_PyWeakref_ProxyType))
49 || (Py_TYPE(op) == addr_of_mut!(_PyWeakref_CallableProxyType))) as c_int
50 }
51
52 #[inline]
53 pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int {
54 (PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int
55 }
56
57 extern "C" {
58 #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")]
59 pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
60 #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")]
61 pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
62 #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")]
63 #[cfg_attr(
64 Py_3_13,
65 deprecated(note = "deprecated since Python 3.13. Use `PyWeakref_GetRef` instead.")
66 )]
67 pub fn PyWeakref_GetObject(reference: *mut PyObject) -> *mut PyObject;
68 #[cfg(Py_3_13)]
69 #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetRef")]
70 pub fn PyWeakref_GetRef(reference: *mut PyObject, pobj: *mut *mut PyObject) -> c_int;
71 }