1 | use crate::methodobject::PyMethodDef; |
2 | use crate::object::*; |
3 | use crate::pyport::Py_ssize_t; |
4 | use std::os::raw::{c_char, c_int, c_void}; |
5 | use std::ptr::addr_of_mut; |
6 | |
7 | #[cfg_attr (windows, link(name = "pythonXY" ))] |
8 | unsafeextern "C" { |
9 | #[cfg_attr (PyPy, link_name = "PyPyModule_Type" )] |
10 | pub unsafestatic mut PyModule_Type: PyTypeObject; |
11 | } |
12 | |
13 | #[inline ] |
14 | pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int { |
15 | PyObject_TypeCheck(ob:op, tp:addr_of_mut!(PyModule_Type)) |
16 | } |
17 | |
18 | #[inline ] |
19 | pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int { |
20 | (Py_TYPE(ob:op) == addr_of_mut!(PyModule_Type)) as c_int |
21 | } |
22 | |
23 | unsafeextern "C" { |
24 | #[cfg_attr (PyPy, link_name = "PyPyModule_NewObject" )] |
25 | pub unsafefn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject; |
26 | #[cfg_attr (PyPy, link_name = "PyPyModule_New" )] |
27 | pub unsafefn PyModule_New(name: *const c_char) -> *mut PyObject; |
28 | #[cfg_attr (PyPy, link_name = "PyPyModule_GetDict" )] |
29 | pub unsafefn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject; |
30 | #[cfg (not(PyPy))] |
31 | pub unsafefn PyModule_GetNameObject(arg1: *mut PyObject) -> *mut PyObject; |
32 | #[cfg_attr (PyPy, link_name = "PyPyModule_GetName" )] |
33 | pub unsafefn PyModule_GetName(arg1: *mut PyObject) -> *const c_char; |
34 | #[cfg (not(all(windows, PyPy)))] |
35 | #[deprecated (note = "Python 3.2" )] |
36 | pub unsafefn PyModule_GetFilename(arg1: *mut PyObject) -> *const c_char; |
37 | #[cfg (not(PyPy))] |
38 | pub unsafefn PyModule_GetFilenameObject(arg1: *mut PyObject) -> *mut PyObject; |
39 | // skipped non-limited _PyModule_Clear |
40 | // skipped non-limited _PyModule_ClearDict |
41 | // skipped non-limited _PyModuleSpec_IsInitializing |
42 | #[cfg_attr (PyPy, link_name = "PyPyModule_GetDef" )] |
43 | pub unsafefn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef; |
44 | #[cfg_attr (PyPy, link_name = "PyPyModule_GetState" )] |
45 | pub unsafefn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void; |
46 | #[cfg_attr (PyPy, link_name = "PyPyModuleDef_Init" )] |
47 | pub unsafefn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject; |
48 | } |
49 | |
50 | #[cfg_attr (windows, link(name = "pythonXY" ))] |
51 | unsafeextern "C" { |
52 | pub unsafestatic mut PyModuleDef_Type: PyTypeObject; |
53 | } |
54 | |
55 | #[repr (C)] |
56 | pub struct PyModuleDef_Base { |
57 | pub ob_base: PyObject, |
58 | pub m_init: Option<extern "C" fn() -> *mut PyObject>, |
59 | pub m_index: Py_ssize_t, |
60 | pub m_copy: *mut PyObject, |
61 | } |
62 | |
63 | #[allow (clippy::declare_interior_mutable_const)] |
64 | pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base { |
65 | ob_base: PyObject_HEAD_INIT, |
66 | m_init: None, |
67 | m_index: 0, |
68 | m_copy: std::ptr::null_mut(), |
69 | }; |
70 | |
71 | #[repr (C)] |
72 | #[derive (Copy, Clone, Eq, PartialEq)] |
73 | pub struct PyModuleDef_Slot { |
74 | pub slot: c_int, |
75 | pub value: *mut c_void, |
76 | } |
77 | |
78 | impl Default for PyModuleDef_Slot { |
79 | fn default() -> PyModuleDef_Slot { |
80 | PyModuleDef_Slot { |
81 | slot: 0, |
82 | value: std::ptr::null_mut(), |
83 | } |
84 | } |
85 | } |
86 | |
87 | pub const Py_mod_create: c_int = 1; |
88 | pub const Py_mod_exec: c_int = 2; |
89 | #[cfg (Py_3_12)] |
90 | pub const Py_mod_multiple_interpreters: c_int = 3; |
91 | #[cfg (Py_3_13)] |
92 | pub const Py_mod_gil: c_int = 4; |
93 | |
94 | // skipped private _Py_mod_LAST_SLOT |
95 | |
96 | #[cfg (Py_3_12)] |
97 | pub const Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED: *mut c_void = 0 as *mut c_void; |
98 | #[cfg (Py_3_12)] |
99 | pub const Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED: *mut c_void = 1 as *mut c_void; |
100 | #[cfg (Py_3_12)] |
101 | pub const Py_MOD_PER_INTERPRETER_GIL_SUPPORTED: *mut c_void = 2 as *mut c_void; |
102 | |
103 | #[cfg (Py_3_13)] |
104 | pub const Py_MOD_GIL_USED: *mut c_void = 0 as *mut c_void; |
105 | #[cfg (Py_3_13)] |
106 | pub const Py_MOD_GIL_NOT_USED: *mut c_void = 1 as *mut c_void; |
107 | |
108 | #[cfg (all(not(Py_LIMITED_API), Py_GIL_DISABLED))] |
109 | extern "C" { |
110 | pub fn PyUnstable_Module_SetGIL(module: *mut PyObject, gil: *mut c_void) -> c_int; |
111 | } |
112 | |
113 | #[repr (C)] |
114 | pub struct PyModuleDef { |
115 | pub m_base: PyModuleDef_Base, |
116 | pub m_name: *const c_char, |
117 | pub m_doc: *const c_char, |
118 | pub m_size: Py_ssize_t, |
119 | pub m_methods: *mut PyMethodDef, |
120 | pub m_slots: *mut PyModuleDef_Slot, |
121 | pub m_traverse: Option<traverseproc>, |
122 | pub m_clear: Option<inquiry>, |
123 | pub m_free: Option<freefunc>, |
124 | } |
125 | |