1use crate::object::*;
2use std::os::raw::c_int;
3#[cfg(not(PyPy))]
4use std::ptr::addr_of_mut;
5
6#[cfg(all(not(PyPy), Py_LIMITED_API))]
7opaque_struct!(PyWeakReference);
8
9#[cfg(all(not(PyPy), not(Py_LIMITED_API)))]
10pub use crate::_PyWeakReference as PyWeakReference;
11
12#[cfg_attr(windows, link(name = "pythonXY"))]
13extern "C" {
14 pub static mut _PyWeakref_RefType: PyTypeObject;
15 pub static mut _PyWeakref_ProxyType: PyTypeObject;
16 pub static mut _PyWeakref_CallableProxyType: PyTypeObject;
17
18 #[cfg(PyPy)]
19 #[link_name = "PyPyWeakref_CheckRef"]
20 pub fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int;
21
22 #[cfg(PyPy)]
23 #[link_name = "PyPyWeakref_CheckRefExact"]
24 pub fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int;
25
26 #[cfg(PyPy)]
27 #[link_name = "PyPyWeakref_CheckProxy"]
28 pub fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int;
29}
30
31#[inline]
32#[cfg(not(PyPy))]
33pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
34 PyObject_TypeCheck(ob:op, tp:addr_of_mut!(_PyWeakref_RefType))
35}
36
37#[inline]
38#[cfg(not(PyPy))]
39pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
40 (Py_TYPE(ob:op) == addr_of_mut!(_PyWeakref_RefType)) as c_int
41}
42
43#[inline]
44#[cfg(not(PyPy))]
45pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
46 ((Py_TYPE(ob:op) == addr_of_mut!(_PyWeakref_ProxyType))
47 || (Py_TYPE(ob:op) == addr_of_mut!(_PyWeakref_CallableProxyType))) as c_int
48}
49
50#[inline]
51pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int {
52 (PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int
53}
54
55extern "C" {
56 #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")]
57 pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
58 #[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")]
59 pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
60 #[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")]
61 pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject;
62}
63