pyo3_ffi/cpython/
genobject.rs

1use crate::object::*;
2use crate::PyFrameObject;
3#[cfg(all(Py_3_11, not(any(PyPy, GraalPy, Py_3_14))))]
4use std::os::raw::c_char;
5use std::os::raw::c_int;
6use std::ptr::addr_of_mut;
7
8#[cfg(not(any(PyPy, GraalPy, Py_3_14)))]
9#[repr(C)]
10pub struct PyGenObject {
11    pub ob_base: PyObject,
12    #[cfg(not(Py_3_11))]
13    pub gi_frame: *mut PyFrameObject,
14    #[cfg(not(Py_3_10))]
15    pub gi_running: c_int,
16    #[cfg(not(Py_3_12))]
17    pub gi_code: *mut PyObject,
18    pub gi_weakreflist: *mut PyObject,
19    pub gi_name: *mut PyObject,
20    pub gi_qualname: *mut PyObject,
21    pub gi_exc_state: crate::cpython::pystate::_PyErr_StackItem,
22    #[cfg(Py_3_11)]
23    pub gi_origin_or_finalizer: *mut PyObject,
24    #[cfg(Py_3_11)]
25    pub gi_hooks_inited: c_char,
26    #[cfg(Py_3_11)]
27    pub gi_closed: c_char,
28    #[cfg(Py_3_11)]
29    pub gi_running_async: c_char,
30    #[cfg(Py_3_11)]
31    pub gi_frame_state: i8,
32    #[cfg(Py_3_11)]
33    pub gi_iframe: [*mut PyObject; 1],
34}
35
36#[cfg(all(Py_3_14, not(any(PyPy, GraalPy))))]
37opaque_struct!(pub PyGenObject);
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}
72
73// skipped _PyCoroWrapper_Type
74
75#[inline]
76pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int {
77    PyObject_TypeCheck(op, addr_of_mut!(PyCoro_Type))
78}
79
80// skipped _PyCoro_GetAwaitableIter
81// skipped PyCoro_New
82
83// skipped PyAsyncGenObject
84
85#[cfg_attr(windows, link(name = "pythonXY"))]
86extern "C" {
87    pub static mut PyAsyncGen_Type: PyTypeObject;
88    // skipped _PyAsyncGenASend_Type
89    // skipped _PyAsyncGenWrappedValue_Type
90    // skipped _PyAsyncGenAThrow_Type
91}
92
93// skipped PyAsyncGen_New
94
95#[inline]
96pub unsafe fn PyAsyncGen_CheckExact(op: *mut PyObject) -> c_int {
97    PyObject_TypeCheck(op, addr_of_mut!(PyAsyncGen_Type))
98}
99
100// skipped _PyAsyncGenValueWrapperNew