pyo3_ffi/cpython/
genobject.rs

1use crate::object::*;
2use crate::PyFrameObject;
3#[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))]
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)))]
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_attr(windows, link(name = "pythonXY"))]
37extern "C" {
38    pub static mut PyGen_Type: PyTypeObject;
39}
40
41#[inline]
42pub unsafe fn PyGen_Check(op: *mut PyObject) -> c_int {
43    PyObject_TypeCheck(op, addr_of_mut!(PyGen_Type))
44}
45
46#[inline]
47pub unsafe fn PyGen_CheckExact(op: *mut PyObject) -> c_int {
48    (Py_TYPE(op) == addr_of_mut!(PyGen_Type)) as c_int
49}
50
51extern "C" {
52    pub fn PyGen_New(frame: *mut PyFrameObject) -> *mut PyObject;
53    // skipped PyGen_NewWithQualName
54    // skipped _PyGen_SetStopIterationValue
55    // skipped _PyGen_FetchStopIterationValue
56    // skipped _PyGen_yf
57    // skipped _PyGen_Finalize
58    #[cfg(not(any(Py_3_9, PyPy)))]
59    #[deprecated(note = "This function was never documented in the Python API.")]
60    pub fn PyGen_NeedsFinalizing(op: *mut PyGenObject) -> c_int;
61}
62
63// skipped PyCoroObject
64
65#[cfg_attr(windows, link(name = "pythonXY"))]
66extern "C" {
67    pub static mut PyCoro_Type: PyTypeObject;
68    pub static mut _PyCoroWrapper_Type: PyTypeObject;
69}
70
71#[inline]
72pub unsafe fn PyCoro_CheckExact(op: *mut PyObject) -> c_int {
73    PyObject_TypeCheck(op, addr_of_mut!(PyCoro_Type))
74}
75
76// skipped _PyCoro_GetAwaitableIter
77// skipped PyCoro_New
78
79// skipped PyAsyncGenObject
80
81#[cfg_attr(windows, link(name = "pythonXY"))]
82extern "C" {
83    pub static mut PyAsyncGen_Type: PyTypeObject;
84    // skipped _PyAsyncGenASend_Type
85    // skipped _PyAsyncGenWrappedValue_Type
86    // skipped _PyAsyncGenAThrow_Type
87}
88
89// skipped PyAsyncGen_New
90
91#[inline]
92pub unsafe fn PyAsyncGen_CheckExact(op: *mut PyObject) -> c_int {
93    PyObject_TypeCheck(op, addr_of_mut!(PyAsyncGen_Type))
94}
95
96// skipped _PyAsyncGenValueWrapperNew
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here