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