-
Notifications
You must be signed in to change notification settings - Fork 947
Expand file tree
/
Copy pathmoduleobject.rs
More file actions
174 lines (157 loc) · 5.37 KB
/
moduleobject.rs
File metadata and controls
174 lines (157 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
use crate::methodobject::PyMethodDef;
use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::{c_char, c_int, c_void};
use std::ptr::addr_of_mut;
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyModule_Type")]
pub static mut PyModule_Type: PyTypeObject;
}
#[inline]
pub unsafe fn PyModule_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, addr_of_mut!(PyModule_Type))
}
#[inline]
pub unsafe fn PyModule_CheckExact(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == addr_of_mut!(PyModule_Type)) as c_int
}
extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyModule_NewObject")]
pub fn PyModule_NewObject(name: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyModule_New")]
pub fn PyModule_New(name: *const c_char) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyModule_GetDict")]
pub fn PyModule_GetDict(arg1: *mut PyObject) -> *mut PyObject;
#[cfg(not(PyPy))]
pub fn PyModule_GetNameObject(arg1: *mut PyObject) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyModule_GetName")]
pub fn PyModule_GetName(arg1: *mut PyObject) -> *const c_char;
#[cfg(not(all(windows, PyPy)))]
#[deprecated(note = "Python 3.2")]
pub fn PyModule_GetFilename(arg1: *mut PyObject) -> *const c_char;
#[cfg(not(PyPy))]
pub fn PyModule_GetFilenameObject(arg1: *mut PyObject) -> *mut PyObject;
// skipped non-limited _PyModule_Clear
// skipped non-limited _PyModule_ClearDict
// skipped non-limited _PyModuleSpec_IsInitializing
#[cfg_attr(PyPy, link_name = "PyPyModule_GetDef")]
pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef;
#[cfg_attr(PyPy, link_name = "PyPyModule_GetState")]
pub fn PyModule_GetState(arg1: *mut PyObject) -> *mut c_void;
#[cfg_attr(PyPy, link_name = "PyPyModuleDef_Init")]
pub fn PyModuleDef_Init(arg1: *mut PyModuleDef) -> *mut PyObject;
}
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut PyModuleDef_Type: PyTypeObject;
}
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
#[repr(C)]
pub struct PyModuleDef_Base {
pub ob_base: PyObject,
// Rust function pointers are non-null so an Option is needed here.
pub m_init: Option<extern "C" fn() -> *mut PyObject>,
pub m_index: Py_ssize_t,
pub m_copy: *mut PyObject,
}
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
#[allow(
clippy::declare_interior_mutable_const,
reason = "contains atomic refcount on free-threaded builds"
)]
pub const PyModuleDef_HEAD_INIT: PyModuleDef_Base = PyModuleDef_Base {
ob_base: PyObject_HEAD_INIT,
m_init: None,
m_index: 0,
m_copy: std::ptr::null_mut(),
};
#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct PyModuleDef_Slot {
pub slot: c_int,
pub value: *mut c_void,
}
impl Default for PyModuleDef_Slot {
fn default() -> PyModuleDef_Slot {
PyModuleDef_Slot {
slot: 0,
value: std::ptr::null_mut(),
}
}
}
pub const Py_mod_create: c_int = 1;
pub const Py_mod_exec: c_int = 2;
#[cfg(Py_3_12)]
pub const Py_mod_multiple_interpreters: c_int = 3;
#[cfg(Py_3_13)]
pub const Py_mod_gil: c_int = 4;
#[cfg(Py_3_15)]
pub const Py_mod_abi: c_int = 5;
#[cfg(Py_3_15)]
pub const Py_mod_name: c_int = 6;
#[cfg(Py_3_15)]
pub const Py_mod_doc: c_int = 7;
#[cfg(Py_3_15)]
pub const Py_mod_state_size: c_int = 8;
#[cfg(Py_3_15)]
pub const Py_mod_methods: c_int = 9;
#[cfg(Py_3_15)]
pub const Py_mod_state_traverse: c_int = 10;
#[cfg(Py_3_15)]
pub const Py_mod_state_clear: c_int = 11;
#[cfg(Py_3_15)]
pub const Py_mod_state_free: c_int = 12;
#[cfg(Py_3_15)]
pub const Py_mod_token: c_int = 13;
// skipped private _Py_mod_LAST_SLOT
#[cfg(Py_3_12)]
#[allow(
clippy::zero_ptr,
reason = "matches the way that the rest of these constants are defined"
)]
pub const Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED: *mut c_void = 0 as *mut c_void;
#[cfg(Py_3_12)]
pub const Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED: *mut c_void = 1 as *mut c_void;
#[cfg(Py_3_12)]
pub const Py_MOD_PER_INTERPRETER_GIL_SUPPORTED: *mut c_void = 2 as *mut c_void;
#[cfg(Py_3_13)]
#[allow(
clippy::zero_ptr,
reason = "matches the way that the rest of these constants are defined"
)]
pub const Py_MOD_GIL_USED: *mut c_void = 0 as *mut c_void;
#[cfg(Py_3_13)]
pub const Py_MOD_GIL_NOT_USED: *mut c_void = 1 as *mut c_void;
#[cfg(all(not(Py_LIMITED_API), Py_GIL_DISABLED))]
extern "C" {
pub fn PyUnstable_Module_SetGIL(module: *mut PyObject, gil: *mut c_void) -> c_int;
}
#[cfg(Py_3_15)]
extern "C" {
pub fn PyModule_FromSlotsAndSpec(
slots: *const PyModuleDef_Slot,
spec: *mut PyObject,
) -> *mut PyObject;
pub fn PyModule_Exec(_mod: *mut PyObject) -> c_int;
pub fn PyModule_GetStateSize(_mod: *mut PyObject, result: *mut Py_ssize_t) -> c_int;
pub fn PyModule_GetToken(module: *mut PyObject, result: *mut *mut c_void) -> c_int;
}
#[cfg(not(_Py_OPAQUE_PYOBJECT))]
#[repr(C)]
pub struct PyModuleDef {
pub m_base: PyModuleDef_Base,
pub m_name: *const c_char,
pub m_doc: *const c_char,
pub m_size: Py_ssize_t,
pub m_methods: *mut PyMethodDef,
pub m_slots: *mut PyModuleDef_Slot,
// Rust function pointers are non-null so an Option is needed here.
pub m_traverse: Option<traverseproc>,
pub m_clear: Option<inquiry>,
pub m_free: Option<freefunc>,
}
// from pytypedefs.h
#[cfg(_Py_OPAQUE_PYOBJECT)]
opaque_struct!(pub PyModuleDef);