1use std::os::raw::c_int;
2#[cfg(not(all(PyPy, not(Py_3_8))))]
3use std::ptr::addr_of_mut;
4
5use crate::PyObject;
6
7#[cfg(all(not(PyPy), not(Py_3_10)))]
8#[repr(C)]
9pub struct PyFunctionObject {
10 pub ob_base: PyObject,
11 pub func_code: *mut PyObject,
12 pub func_globals: *mut PyObject,
13 pub func_defaults: *mut PyObject,
14 pub func_kwdefaults: *mut PyObject,
15 pub func_closure: *mut PyObject,
16 pub func_doc: *mut PyObject,
17 pub func_name: *mut PyObject,
18 pub func_dict: *mut PyObject,
19 pub func_weakreflist: *mut PyObject,
20 pub func_module: *mut PyObject,
21 pub func_annotations: *mut PyObject,
22 pub func_qualname: *mut PyObject,
23 #[cfg(Py_3_8)]
24 pub vectorcall: Option<crate::vectorcallfunc>,
25}
26
27#[cfg(all(not(PyPy), Py_3_10))]
28#[repr(C)]
29pub struct PyFunctionObject {
30 pub ob_base: PyObject,
31 pub func_globals: *mut PyObject,
32 pub func_builtins: *mut PyObject,
33 pub func_name: *mut PyObject,
34 pub func_qualname: *mut PyObject,
35 pub func_code: *mut PyObject,
36 pub func_defaults: *mut PyObject,
37 pub func_kwdefaults: *mut PyObject,
38 pub func_closure: *mut PyObject,
39 pub func_doc: *mut PyObject,
40 pub func_dict: *mut PyObject,
41 pub func_weakreflist: *mut PyObject,
42 pub func_module: *mut PyObject,
43 pub func_annotations: *mut PyObject,
44 #[cfg(Py_3_12)]
45 pub func_typeparams: *mut PyObject,
46 pub vectorcall: Option<crate::vectorcallfunc>,
47 #[cfg(Py_3_11)]
48 pub func_version: u32,
49}
50
51#[cfg(PyPy)]
52#[repr(C)]
53pub struct PyFunctionObject {
54 pub ob_base: PyObject,
55 pub func_name: *mut PyObject,
56}
57
58#[cfg_attr(windows, link(name = "pythonXY"))]
59extern "C" {
60 #[cfg(not(all(PyPy, not(Py_3_8))))]
61 #[cfg_attr(PyPy, link_name = "PyPyFunction_Type")]
62 pub static mut PyFunction_Type: crate::PyTypeObject;
63}
64
65#[cfg(not(all(PyPy, not(Py_3_8))))]
66#[inline]
67pub unsafe fn PyFunction_Check(op: *mut PyObject) -> c_int {
68 (crate::Py_TYPE(ob:op) == addr_of_mut!(PyFunction_Type)) as c_int
69}
70
71extern "C" {
72 pub fn PyFunction_New(code: *mut PyObject, globals: *mut PyObject) -> *mut PyObject;
73 pub fn PyFunction_NewWithQualName(
74 code: *mut PyObject,
75 globals: *mut PyObject,
76 qualname: *mut PyObject,
77 ) -> *mut PyObject;
78 pub fn PyFunction_GetCode(op: *mut PyObject) -> *mut PyObject;
79 pub fn PyFunction_GetGlobals(op: *mut PyObject) -> *mut PyObject;
80 pub fn PyFunction_GetModule(op: *mut PyObject) -> *mut PyObject;
81 pub fn PyFunction_GetDefaults(op: *mut PyObject) -> *mut PyObject;
82 pub fn PyFunction_SetDefaults(op: *mut PyObject, defaults: *mut PyObject) -> c_int;
83 pub fn PyFunction_GetKwDefaults(op: *mut PyObject) -> *mut PyObject;
84 pub fn PyFunction_SetKwDefaults(op: *mut PyObject, defaults: *mut PyObject) -> c_int;
85 pub fn PyFunction_GetClosure(op: *mut PyObject) -> *mut PyObject;
86 pub fn PyFunction_SetClosure(op: *mut PyObject, closure: *mut PyObject) -> c_int;
87 pub fn PyFunction_GetAnnotations(op: *mut PyObject) -> *mut PyObject;
88 pub fn PyFunction_SetAnnotations(op: *mut PyObject, annotations: *mut PyObject) -> c_int;
89}
90
91// skipped _PyFunction_Vectorcall
92// skipped PyFunction_GET_CODE
93// skipped PyFunction_GET_GLOBALS
94// skipped PyFunction_GET_MODULE
95// skipped PyFunction_GET_DEFAULTS
96// skipped PyFunction_GET_KW_DEFAULTS
97// skipped PyFunction_GET_CLOSURE
98// skipped PyFunction_GET_ANNOTATIONS
99
100// skipped PyClassMethod_Type
101// skipped PyStaticMethod_Type
102// skipped PyClassMethod_New
103// skipped PyStaticMethod_New
104