Skip to main content

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::ffi::c_char;
5use std::ffi::c_int;
6
7#[cfg(not(any(PyPy, GraalPy, Py_3_14)))]
8#[repr(C)]
9pub struct PyGenObject {
10    pub ob_base: PyObject,
11    #[cfg(not(Py_3_11))]
12    pub gi_frame: *mut PyFrameObject,
13    #[cfg(not(Py_3_10))]
14    pub gi_running: c_int,
15    #[cfg(not(Py_3_12))]
16    pub gi_code: *mut PyObject,
17    pub gi_weakreflist: *mut PyObject,
18    pub gi_name: *mut PyObject,
19    pub gi_qualname: *mut PyObject,
20    #[allow(
21        private_interfaces,
22        reason = "PyGenObject layout was public until 3.14"
23    )]
24    pub gi_exc_state: crate::cpython::pystate::_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(all(Py_3_14, not(any(PyPy, GraalPy))))]
40opaque_struct!(pub PyGenObject);
41
42extern_libpython! {
43    pub static mut PyGen_Type: PyTypeObject;
44}
45
46#[inline]
47pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int {
48    PyObject_TypeCheck(op, &raw mut PyGen_Type)
49}
50
51#[inline]
52pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
53    (Py_TYPE(op) == &raw mut PyGen_Type) as c_int
54}
55
56extern_libpython! {
57    pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
58    // skipped PyGen_NewWithQualName
59    // skipped _PyGen_SetStopIterationValue
60    // skipped _PyGen_FetchStopIterationValue
61    // skipped _PyGen_yf
62    // skipped _PyGen_Finalize
63    #[cfg(not(any(Py_3_9, PyPy)))]
64    #[deprecated(note = "This function was never documented in the Python API.")]
65    pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
66}
67
68// skipped PyCoroObject
69
70extern_libpython! {
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, &raw mut PyCoro_Type)
79}
80
81// skipped _PyCoro_GetAwaitableIter
82// skipped PyCoro_New
83
84// skipped PyAsyncGenObject
85
86extern_libpython! {
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, &raw mut PyAsyncGen_Type)
98}
99
100// skipped _PyAsyncGenValueWrapperNew
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here