pyo3_ffi/cpython/
genobject.rs

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