| 1 | use crate::object::PyObject; |
| 2 | use std::ffi::{c_char, c_int, c_long}; |
| 3 | |
| 4 | extern "C" { |
| 5 | pub fn PyImport_GetMagicNumber() -> c_long; |
| 6 | pub fn PyImport_GetMagicTag() -> *const c_char; |
| 7 | #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModule")] |
| 8 | pub fn PyImport_ExecCodeModule(name: *const c_char, co: *mut PyObject) -> *mut PyObject; |
| 9 | #[cfg_attr(PyPy, link_name = "PyPyImport_ExecCodeModuleEx")] |
| 10 | pub fn PyImport_ExecCodeModuleEx( |
| 11 | name: *const c_char, |
| 12 | co: *mut PyObject, |
| 13 | pathname: *const c_char, |
| 14 | ) -> *mut PyObject; |
| 15 | pub fn PyImport_ExecCodeModuleWithPathnames( |
| 16 | name: *const c_char, |
| 17 | co: *mut PyObject, |
| 18 | pathname: *const c_char, |
| 19 | cpathname: *const c_char, |
| 20 | ) -> *mut PyObject; |
| 21 | pub fn PyImport_ExecCodeModuleObject( |
| 22 | name: *mut PyObject, |
| 23 | co: *mut PyObject, |
| 24 | pathname: *mut PyObject, |
| 25 | cpathname: *mut PyObject, |
| 26 | ) -> *mut PyObject; |
| 27 | #[cfg_attr(PyPy, link_name = "PyPyImport_GetModuleDict")] |
| 28 | pub fn PyImport_GetModuleDict() -> *mut PyObject; |
| 29 | #[cfg_attr(PyPy, link_name = "PyPyImport_GetModule")] |
| 30 | pub fn PyImport_GetModule(name: *mut PyObject) -> *mut PyObject; |
| 31 | pub fn PyImport_AddModuleObject(name: *mut PyObject) -> *mut PyObject; |
| 32 | #[cfg_attr(PyPy, link_name = "PyPyImport_AddModule")] |
| 33 | pub fn PyImport_AddModule(name: *const c_char) -> *mut PyObject; |
| 34 | #[cfg(Py_3_13)] |
| 35 | #[cfg_attr(PyPy, link_name = "PyPyImport_AddModuleRef")] |
| 36 | pub fn PyImport_AddModuleRef(name: *const c_char) -> *mut PyObject; |
| 37 | #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModule")] |
| 38 | pub fn PyImport_ImportModule(name: *const c_char) -> *mut PyObject; |
| 39 | #[deprecated(note = "Python 3.13")] |
| 40 | #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleNoBlock")] |
| 41 | pub fn PyImport_ImportModuleNoBlock(name: *const c_char) -> *mut PyObject; |
| 42 | #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevel")] |
| 43 | pub fn PyImport_ImportModuleLevel( |
| 44 | name: *const c_char, |
| 45 | globals: *mut PyObject, |
| 46 | locals: *mut PyObject, |
| 47 | fromlist: *mut PyObject, |
| 48 | level: c_int, |
| 49 | ) -> *mut PyObject; |
| 50 | #[cfg_attr(PyPy, link_name = "PyPyImport_ImportModuleLevelObject")] |
| 51 | pub fn PyImport_ImportModuleLevelObject( |
| 52 | name: *mut PyObject, |
| 53 | globals: *mut PyObject, |
| 54 | locals: *mut PyObject, |
| 55 | fromlist: *mut PyObject, |
| 56 | level: c_int, |
| 57 | ) -> *mut PyObject; |
| 58 | } |
| 59 | |
| 60 | #[inline] |
| 61 | pub unsafe fn PyImport_ImportModuleEx( |
| 62 | name: *const c_char, |
| 63 | globals: *mut PyObject, |
| 64 | locals: *mut PyObject, |
| 65 | fromlist: *mut PyObject, |
| 66 | ) -> *mut PyObject { |
| 67 | PyImport_ImportModuleLevel(name, globals, locals, fromlist, 0) |
| 68 | } |
| 69 | |
| 70 | extern "C" { |
| 71 | pub fn PyImport_GetImporter(path: *mut PyObject) -> *mut PyObject; |
| 72 | #[cfg_attr(PyPy, link_name = "PyPyImport_Import")] |
| 73 | pub fn PyImport_Import(name: *mut PyObject) -> *mut PyObject; |
| 74 | #[cfg_attr(PyPy, link_name = "PyPyImport_ReloadModule")] |
| 75 | pub fn PyImport_ReloadModule(m: *mut PyObject) -> *mut PyObject; |
| 76 | #[cfg(not(Py_3_9))] |
| 77 | #[deprecated(note = "Removed in Python 3.9 as it was \"For internal use only\".")] |
| 78 | pub fn PyImport_Cleanup(); |
| 79 | pub fn PyImport_ImportFrozenModuleObject(name: *mut PyObject) -> c_int; |
| 80 | pub fn PyImport_ImportFrozenModule(name: *const c_char) -> c_int; |
| 81 | |
| 82 | pub fn PyImport_AppendInittab( |
| 83 | name: *const c_char, |
| 84 | initfunc: Option<unsafe extern "C" fn() -> *mut PyObject>, |
| 85 | ) -> c_int; |
| 86 | } |