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
use crate::{PyInterpreterState, PyObject};
#[cfg(not(PyPy))]
use std::os::raw::c_uchar;
use std::os::raw::{c_char, c_int};

// skipped PyInit__imp

extern "C" {
    pub fn _PyImport_IsInitialized(state: *mut PyInterpreterState) -> c_int;
    // skipped _PyImport_GetModuleId
    pub fn _PyImport_SetModule(name: *mut PyObject, module: *mut PyObject) -> c_int;
    pub fn _PyImport_SetModuleString(name: *const c_char, module: *mut PyObject) -> c_int;
    pub fn _PyImport_AcquireLock();
    pub fn _PyImport_ReleaseLock() -> c_int;
    #[cfg(not(Py_3_9))]
    pub fn _PyImport_FindBuiltin(name: *const c_char, modules: *mut PyObject) -> *mut PyObject;
    #[cfg(not(Py_3_11))]
    pub fn _PyImport_FindExtensionObject(a: *mut PyObject, b: *mut PyObject) -> *mut PyObject;
    pub fn _PyImport_FixupBuiltin(
        module: *mut PyObject,
        name: *const c_char,
        modules: *mut PyObject,
    ) -> c_int;
    pub fn _PyImport_FixupExtensionObject(
        a: *mut PyObject,
        b: *mut PyObject,
        c: *mut PyObject,
        d: *mut PyObject,
    ) -> c_int;
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _inittab {
    pub name: *const c_char,
    pub initfunc: Option<unsafe extern "C" fn() -> *mut PyObject>,
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    #[cfg(not(PyPy))]
    pub static mut PyImport_Inittab: *mut _inittab;
}

extern "C" {
    #[cfg(not(PyPy))]
    pub fn PyImport_ExtendInittab(newtab: *mut _inittab) -> c_int;
}

#[cfg(not(PyPy))]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct _frozen {
    pub name: *const c_char,
    pub code: *const c_uchar,
    pub size: c_int,
    #[cfg(Py_3_11)]
    pub is_package: c_int,
    #[cfg(Py_3_11)]
    pub get_code: Option<unsafe extern "C" fn() -> *mut PyObject>,
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    #[cfg(not(PyPy))]
    pub static mut PyImport_FrozenModules: *const _frozen;
}