2022-01-25 13:46:27 +00:00
|
|
|
use crate::object::*;
|
2018-07-30 21:01:46 +00:00
|
|
|
use std::os::raw::c_int;
|
2023-06-05 07:51:50 +00:00
|
|
|
#[cfg(not(PyPy))]
|
|
|
|
use std::ptr::addr_of_mut;
|
2015-04-26 08:32:58 +00:00
|
|
|
|
2022-06-04 17:22:18 +00:00
|
|
|
#[cfg(all(not(PyPy), Py_LIMITED_API))]
|
2020-12-12 08:40:40 +00:00
|
|
|
opaque_struct!(PyWeakReference);
|
2015-04-26 08:32:58 +00:00
|
|
|
|
2022-06-04 17:22:18 +00:00
|
|
|
#[cfg(all(not(PyPy), not(Py_LIMITED_API)))]
|
2022-08-16 06:57:15 +00:00
|
|
|
pub use crate::_PyWeakReference as PyWeakReference;
|
2022-06-04 17:22:18 +00:00
|
|
|
|
|
|
|
#[cfg_attr(windows, link(name = "pythonXY"))]
|
2018-07-30 21:01:46 +00:00
|
|
|
extern "C" {
|
2022-06-04 17:22:18 +00:00
|
|
|
pub static mut _PyWeakref_RefType: PyTypeObject;
|
|
|
|
pub static mut _PyWeakref_ProxyType: PyTypeObject;
|
|
|
|
pub static mut _PyWeakref_CallableProxyType: PyTypeObject;
|
2020-12-18 23:42:17 +00:00
|
|
|
|
|
|
|
#[cfg(PyPy)]
|
|
|
|
#[link_name = "PyPyWeakref_CheckRef"]
|
|
|
|
pub fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int;
|
|
|
|
|
|
|
|
#[cfg(PyPy)]
|
|
|
|
#[link_name = "PyPyWeakref_CheckRefExact"]
|
|
|
|
pub fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int;
|
|
|
|
|
|
|
|
#[cfg(PyPy)]
|
|
|
|
#[link_name = "PyPyWeakref_CheckProxy"]
|
|
|
|
pub fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int;
|
2015-04-26 08:32:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 19:07:07 +00:00
|
|
|
#[inline]
|
2020-12-18 23:42:17 +00:00
|
|
|
#[cfg(not(PyPy))]
|
2015-04-26 08:32:58 +00:00
|
|
|
pub unsafe fn PyWeakref_CheckRef(op: *mut PyObject) -> c_int {
|
2023-06-05 07:51:50 +00:00
|
|
|
PyObject_TypeCheck(op, addr_of_mut!(_PyWeakref_RefType))
|
2015-04-26 08:32:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 19:07:07 +00:00
|
|
|
#[inline]
|
2020-12-18 23:42:17 +00:00
|
|
|
#[cfg(not(PyPy))]
|
2015-04-26 08:32:58 +00:00
|
|
|
pub unsafe fn PyWeakref_CheckRefExact(op: *mut PyObject) -> c_int {
|
2023-06-05 07:51:50 +00:00
|
|
|
(Py_TYPE(op) == addr_of_mut!(_PyWeakref_RefType)) as c_int
|
2015-04-26 08:32:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 19:07:07 +00:00
|
|
|
#[inline]
|
2020-12-18 23:42:17 +00:00
|
|
|
#[cfg(not(PyPy))]
|
2015-04-26 08:32:58 +00:00
|
|
|
pub unsafe fn PyWeakref_CheckProxy(op: *mut PyObject) -> c_int {
|
2023-06-05 07:51:50 +00:00
|
|
|
((Py_TYPE(op) == addr_of_mut!(_PyWeakref_ProxyType))
|
|
|
|
|| (Py_TYPE(op) == addr_of_mut!(_PyWeakref_CallableProxyType))) as c_int
|
2015-04-26 08:32:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 19:07:07 +00:00
|
|
|
#[inline]
|
2015-04-26 08:32:58 +00:00
|
|
|
pub unsafe fn PyWeakref_Check(op: *mut PyObject) -> c_int {
|
|
|
|
(PyWeakref_CheckRef(op) != 0 || PyWeakref_CheckProxy(op) != 0) as c_int
|
|
|
|
}
|
|
|
|
|
2018-07-30 21:01:46 +00:00
|
|
|
extern "C" {
|
2019-04-23 11:18:42 +00:00
|
|
|
#[cfg_attr(PyPy, link_name = "PyPyWeakref_NewRef")]
|
2018-07-30 21:01:46 +00:00
|
|
|
pub fn PyWeakref_NewRef(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
|
2019-04-23 11:18:42 +00:00
|
|
|
#[cfg_attr(PyPy, link_name = "PyPyWeakref_NewProxy")]
|
2018-07-30 21:01:46 +00:00
|
|
|
pub fn PyWeakref_NewProxy(ob: *mut PyObject, callback: *mut PyObject) -> *mut PyObject;
|
2019-04-23 11:18:42 +00:00
|
|
|
#[cfg_attr(PyPy, link_name = "PyPyWeakref_GetObject")]
|
2015-04-26 08:32:58 +00:00
|
|
|
pub fn PyWeakref_GetObject(_ref: *mut PyObject) -> *mut PyObject;
|
|
|
|
}
|