pyo3_ffi/cpython/
genobject.rs

1use crate::object::*;
2use crate::PyFrameObject;
3#[cfg(not(any(PyPy, GraalPy)))]
4use crate::_PyErr_StackItem;
5#[cfg(Py_3_11)]
6use std::os::raw::c_char;
7use std::os::raw::c_int;
8use std::ptr::addr_of_mut;
9
10#[cfg(not(any(PyPy, GraalPy)))]
11#[repr(C)]
12#[derive(Copy, Clone)]
13pub struct PyGenObject {
14    pub ob_base: PyObject,
15    #[cfg(not(Py_3_11))]
16    pub gi_frame: *mut PyFrameObject,
17    #[cfg(not(Py_3_10))]
18    pub gi_running: c_int,
19    #[cfg(not(Py_3_12))]
20    pub gi_code: *mut PyObject,
21    pub gi_weakreflist: *mut PyObject,
22    pub gi_name: *mut PyObject,
23    pub gi_qualname: *mut PyObject,
24    pub gi_exc_state: _PyErr_StackItem,
25    #[cfg(Py_3_11)]
26    pub gi_origin_or_finalizer: *mut PyObject,
27    #[cfg(Py_3_11)]
28    pub gi_hooks_inited: c_char,
29    #[cfg(Py_3_11)]
30    pub gi_closed: c_char,
31    #[cfg(Py_3_11)]
32    pub gi_running_async: c_char,
33    #[cfg(Py_3_11)]
34    pub gi_frame_state: i8,
35    #[cfg(Py_3_11)]
36    pub gi_iframe: [*mut PyObject; 1],
37}
38
39#[cfg_attr(windows, link(name = "pythonXY"))]
40extern "C" {
41    pub static mut PyGen_Type: PyTypeObject;
42}
43
44#[inline]
45pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int {
46    PyObject_TypeCheck(op, addr_of_mut!(PyGen_Type))
47}
48
49#[inline]
50pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
51    (Py_TYPE(op) == addr_of_mut!(PyGen_Type)) as c_int
52}
53
54extern "C" {
55    pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
56    // skipped PyGen_NewWithQualName
57    // skipped _PyGen_SetStopIterationValue
58    // skipped _PyGen_FetchStopIterationValue
59    // skipped _PyGen_yf
60    // skipped _PyGen_Finalize
61    #[cfg(not(any(Py_3_9, PyPy)))]
62    #[deprecated(note = "This function was never documented in the Python API.")]
63    pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
64}
65
66// skipped PyCoroObject
67
68#[cfg_attr(windows, link(name = "pythonXY"))]
69extern "C" {
70    pub static mut PyCoro_Type: PyTypeObject;
71    pub static mut _PyCoroWrapper_Type: PyTypeObject;
72}
73
74#[inline]
75pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int {
76    PyObject_TypeCheck(op, addr_of_mut!(PyCoro_Type))
77}
78
79// skipped _PyCoro_GetAwaitableIter
80// skipped PyCoro_New
81
82// skipped PyAsyncGenObject
83
84#[cfg_attr(windows, link(name = "pythonXY"))]
85extern "C" {
86    pub static mut PyAsyncGen_Type: PyTypeObject;
87    // skipped _PyAsyncGenASend_Type
88    // skipped _PyAsyncGenWrappedValue_Type
89    // skipped _PyAsyncGenAThrow_Type
90}
91
92// skipped PyAsyncGen_New
93
94#[inline]
95pub unsafe fn PyAsyncGen_CheckExact(op: *mut PyObject) -> c_int {
96    PyObject_TypeCheck(op, addr_of_mut!(PyAsyncGen_Type))
97}
98
99// skipped _PyAsyncGenValueWrapperNew