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