1 | use crate::methodobject::PyMethodDef; |
2 | use crate::moduleobject::PyModuleDef; |
3 | use crate::object::PyObject; |
4 | use crate::pyport::Py_ssize_t; |
5 | use std::os::raw::{c_char, c_int, c_long}; |
6 | |
7 | extern "C" { |
8 | #[cfg_attr (PyPy, link_name = "PyPyArg_Parse" )] |
9 | pub fn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; |
10 | #[cfg_attr (PyPy, link_name = "PyPyArg_ParseTuple" )] |
11 | pub fn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; |
12 | #[cfg_attr (PyPy, link_name = "PyPyArg_ParseTupleAndKeywords" )] |
13 | pub fn PyArg_ParseTupleAndKeywords( |
14 | arg1: *mut PyObject, |
15 | arg2: *mut PyObject, |
16 | arg3: *const c_char, |
17 | arg4: *mut *mut c_char, |
18 | ... |
19 | ) -> c_int; |
20 | pub fn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int; |
21 | #[cfg_attr (PyPy, link_name = "PyPyArg_UnpackTuple" )] |
22 | pub fn PyArg_UnpackTuple( |
23 | arg1: *mut PyObject, |
24 | arg2: *const c_char, |
25 | arg3: Py_ssize_t, |
26 | arg4: Py_ssize_t, |
27 | ... |
28 | ) -> c_int; |
29 | #[cfg_attr (PyPy, link_name = "PyPy_BuildValue" )] |
30 | pub fn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject; |
31 | // #[cfg_attr(PyPy, link_name = "_PyPy_BuildValue_SizeT")] |
32 | //pub fn _Py_BuildValue_SizeT(arg1: *const c_char, ...) |
33 | // -> *mut PyObject; |
34 | // #[cfg_attr(PyPy, link_name = "PyPy_VaBuildValue")] |
35 | |
36 | // skipped non-limited _PyArg_UnpackStack |
37 | // skipped non-limited _PyArg_NoKeywords |
38 | // skipped non-limited _PyArg_NoKwnames |
39 | // skipped non-limited _PyArg_NoPositional |
40 | // skipped non-limited _PyArg_BadArgument |
41 | // skipped non-limited _PyArg_CheckPositional |
42 | |
43 | //pub fn Py_VaBuildValue(arg1: *const c_char, arg2: va_list) |
44 | // -> *mut PyObject; |
45 | |
46 | // skipped non-limited _Py_VaBuildStack |
47 | // skipped non-limited _PyArg_Parser |
48 | |
49 | // skipped non-limited _PyArg_ParseTupleAndKeywordsFast |
50 | // skipped non-limited _PyArg_ParseStack |
51 | // skipped non-limited _PyArg_ParseStackAndKeywords |
52 | // skipped non-limited _PyArg_VaParseTupleAndKeywordsFast |
53 | // skipped non-limited _PyArg_UnpackKeywords |
54 | // skipped non-limited _PyArg_Fini |
55 | |
56 | #[cfg (Py_3_10)] |
57 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddObjectRef" )] |
58 | pub fn PyModule_AddObjectRef( |
59 | module: *mut PyObject, |
60 | name: *const c_char, |
61 | value: *mut PyObject, |
62 | ) -> c_int; |
63 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddObject" )] |
64 | pub fn PyModule_AddObject( |
65 | module: *mut PyObject, |
66 | name: *const c_char, |
67 | value: *mut PyObject, |
68 | ) -> c_int; |
69 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddIntConstant" )] |
70 | pub fn PyModule_AddIntConstant( |
71 | module: *mut PyObject, |
72 | name: *const c_char, |
73 | value: c_long, |
74 | ) -> c_int; |
75 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddStringConstant" )] |
76 | pub fn PyModule_AddStringConstant( |
77 | module: *mut PyObject, |
78 | name: *const c_char, |
79 | value: *const c_char, |
80 | ) -> c_int; |
81 | #[cfg (any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] |
82 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddType" )] |
83 | pub fn PyModule_AddType( |
84 | module: *mut PyObject, |
85 | type_: *mut crate::object::PyTypeObject, |
86 | ) -> c_int; |
87 | // skipped PyModule_AddIntMacro |
88 | // skipped PyModule_AddStringMacro |
89 | pub fn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; |
90 | pub fn PyModule_AddFunctions(arg1: *mut PyObject, arg2: *mut PyMethodDef) -> c_int; |
91 | pub fn PyModule_ExecDef(module: *mut PyObject, def: *mut PyModuleDef) -> c_int; |
92 | } |
93 | |
94 | pub const Py_CLEANUP_SUPPORTED: i32 = 0x2_0000; |
95 | |
96 | pub const PYTHON_API_VERSION: i32 = 1013; |
97 | pub const PYTHON_ABI_VERSION: i32 = 3; |
98 | |
99 | extern "C" { |
100 | #[cfg (not(py_sys_config = "Py_TRACE_REFS" ))] |
101 | #[cfg_attr (PyPy, link_name = "PyPyModule_Create2" )] |
102 | pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; |
103 | |
104 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
105 | fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; |
106 | |
107 | #[cfg (not(py_sys_config = "Py_TRACE_REFS" ))] |
108 | pub fn PyModule_FromDefAndSpec2( |
109 | def: *mut PyModuleDef, |
110 | spec: *mut PyObject, |
111 | module_api_version: c_int, |
112 | ) -> *mut PyObject; |
113 | |
114 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
115 | fn PyModule_FromDefAndSpec2TraceRefs( |
116 | def: *mut PyModuleDef, |
117 | spec: *mut PyObject, |
118 | module_api_version: c_int, |
119 | ) -> *mut PyObject; |
120 | } |
121 | |
122 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
123 | #[inline ] |
124 | pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { |
125 | PyModule_Create2TraceRefs(module, apiver) |
126 | } |
127 | |
128 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
129 | #[inline ] |
130 | pub unsafe fn PyModule_FromDefAndSpec2( |
131 | def: *mut PyModuleDef, |
132 | spec: *mut PyObject, |
133 | module_api_version: c_int, |
134 | ) -> *mut PyObject { |
135 | PyModule_FromDefAndSpec2TraceRefs(def, spec, module_api_version) |
136 | } |
137 | |
138 | #[inline ] |
139 | pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject { |
140 | PyModule_Create2( |
141 | module, |
142 | apiver:if cfg!(Py_LIMITED_API) { |
143 | PYTHON_ABI_VERSION |
144 | } else { |
145 | PYTHON_API_VERSION |
146 | }, |
147 | ) |
148 | } |
149 | |
150 | #[inline ] |
151 | pub unsafe fn PyModule_FromDefAndSpec(def: *mut PyModuleDef, spec: *mut PyObject) -> *mut PyObject { |
152 | PyModule_FromDefAndSpec2( |
153 | def, |
154 | spec, |
155 | module_api_version:if cfg!(Py_LIMITED_API) { |
156 | PYTHON_ABI_VERSION |
157 | } else { |
158 | PYTHON_API_VERSION |
159 | }, |
160 | ) |
161 | } |
162 | |
163 | #[cfg (not(Py_LIMITED_API))] |
164 | #[cfg_attr (windows, link(name = "pythonXY" ))] |
165 | extern "C" { |
166 | pub static mut _Py_PackageContext: *const c_char; |
167 | } |
168 | |