| 1 | use crate::methodobject::PyMethodDef; |
| 2 | use crate::moduleobject::PyModuleDef; |
| 3 | use crate::object::PyObject; |
| 4 | use crate::pyport::Py_ssize_t; |
| 5 | use std::os::raw::{c_char, c_int, c_long}; |
| 6 | |
| 7 | unsafeextern "C" { |
| 8 | #[cfg_attr (PyPy, link_name = "PyPyArg_Parse" )] |
| 9 | pub unsafefn PyArg_Parse(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; |
| 10 | #[cfg_attr (PyPy, link_name = "PyPyArg_ParseTuple" )] |
| 11 | pub unsafefn PyArg_ParseTuple(arg1: *mut PyObject, arg2: *const c_char, ...) -> c_int; |
| 12 | #[cfg_attr (PyPy, link_name = "PyPyArg_ParseTupleAndKeywords" )] |
| 13 | pub unsafefn PyArg_ParseTupleAndKeywords( |
| 14 | arg1: *mut PyObject, |
| 15 | arg2: *mut PyObject, |
| 16 | arg3: *const c_char, |
| 17 | #[cfg (not(Py_3_13))] arg4: *mut *mut c_char, |
| 18 | #[cfg (Py_3_13)] arg4: *const *const c_char, |
| 19 | ... |
| 20 | ) -> c_int; |
| 21 | |
| 22 | // skipped PyArg_VaParse |
| 23 | // skipped PyArg_VaParseTupleAndKeywords |
| 24 | |
| 25 | pub unsafefn PyArg_ValidateKeywordArguments(arg1: *mut PyObject) -> c_int; |
| 26 | #[cfg_attr (PyPy, link_name = "PyPyArg_UnpackTuple" )] |
| 27 | pub unsafefn PyArg_UnpackTuple( |
| 28 | arg1: *mut PyObject, |
| 29 | arg2: *const c_char, |
| 30 | arg3: Py_ssize_t, |
| 31 | arg4: Py_ssize_t, |
| 32 | ... |
| 33 | ) -> c_int; |
| 34 | |
| 35 | #[cfg_attr (PyPy, link_name = "PyPy_BuildValue" )] |
| 36 | pub unsafefn Py_BuildValue(arg1: *const c_char, ...) -> *mut PyObject; |
| 37 | // skipped Py_VaBuildValue |
| 38 | |
| 39 | #[cfg (Py_3_10)] |
| 40 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddObjectRef" )] |
| 41 | pub unsafefn PyModule_AddObjectRef( |
| 42 | module: *mut PyObject, |
| 43 | name: *const c_char, |
| 44 | value: *mut PyObject, |
| 45 | ) -> c_int; |
| 46 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddObject" )] |
| 47 | pub unsafefn PyModule_AddObject( |
| 48 | module: *mut PyObject, |
| 49 | name: *const c_char, |
| 50 | value: *mut PyObject, |
| 51 | ) -> c_int; |
| 52 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddIntConstant" )] |
| 53 | pub unsafefn PyModule_AddIntConstant( |
| 54 | module: *mut PyObject, |
| 55 | name: *const c_char, |
| 56 | value: c_long, |
| 57 | ) -> c_int; |
| 58 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddStringConstant" )] |
| 59 | pub unsafefn PyModule_AddStringConstant( |
| 60 | module: *mut PyObject, |
| 61 | name: *const c_char, |
| 62 | value: *const c_char, |
| 63 | ) -> c_int; |
| 64 | #[cfg (any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] |
| 65 | #[cfg_attr (PyPy, link_name = "PyPyModule_AddType" )] |
| 66 | pub unsafefn PyModule_AddType( |
| 67 | module: *mut PyObject, |
| 68 | type_: *mut crate::object::PyTypeObject, |
| 69 | ) -> c_int; |
| 70 | // skipped PyModule_AddIntMacro |
| 71 | // skipped PyModule_AddStringMacro |
| 72 | pub unsafefn PyModule_SetDocString(arg1: *mut PyObject, arg2: *const c_char) -> c_int; |
| 73 | pub unsafefn PyModule_AddFunctions(arg1: *mut PyObject, arg2: *mut PyMethodDef) -> c_int; |
| 74 | pub unsafefn PyModule_ExecDef(module: *mut PyObject, def: *mut PyModuleDef) -> c_int; |
| 75 | } |
| 76 | |
| 77 | pub const Py_CLEANUP_SUPPORTED: i32 = 0x2_0000; |
| 78 | |
| 79 | pub const PYTHON_API_VERSION: i32 = 1013; |
| 80 | pub const PYTHON_ABI_VERSION: i32 = 3; |
| 81 | |
| 82 | unsafeextern "C" { |
| 83 | #[cfg (not(py_sys_config = "Py_TRACE_REFS" ))] |
| 84 | #[cfg_attr (PyPy, link_name = "PyPyModule_Create2" )] |
| 85 | pub unsafefn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; |
| 86 | |
| 87 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
| 88 | fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; |
| 89 | |
| 90 | #[cfg (not(py_sys_config = "Py_TRACE_REFS" ))] |
| 91 | pub unsafefn PyModule_FromDefAndSpec2( |
| 92 | def: *mut PyModuleDef, |
| 93 | spec: *mut PyObject, |
| 94 | module_api_version: c_int, |
| 95 | ) -> *mut PyObject; |
| 96 | |
| 97 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
| 98 | fn PyModule_FromDefAndSpec2TraceRefs( |
| 99 | def: *mut PyModuleDef, |
| 100 | spec: *mut PyObject, |
| 101 | module_api_version: c_int, |
| 102 | ) -> *mut PyObject; |
| 103 | } |
| 104 | |
| 105 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
| 106 | #[inline ] |
| 107 | pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { |
| 108 | PyModule_Create2TraceRefs(module, apiver) |
| 109 | } |
| 110 | |
| 111 | #[cfg (py_sys_config = "Py_TRACE_REFS" )] |
| 112 | #[inline ] |
| 113 | pub unsafe fn PyModule_FromDefAndSpec2( |
| 114 | def: *mut PyModuleDef, |
| 115 | spec: *mut PyObject, |
| 116 | module_api_version: c_int, |
| 117 | ) -> *mut PyObject { |
| 118 | PyModule_FromDefAndSpec2TraceRefs(def, spec, module_api_version) |
| 119 | } |
| 120 | |
| 121 | #[inline ] |
| 122 | pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject { |
| 123 | PyModule_Create2( |
| 124 | module, |
| 125 | apiver:if cfg!(Py_LIMITED_API) { |
| 126 | PYTHON_ABI_VERSION |
| 127 | } else { |
| 128 | PYTHON_API_VERSION |
| 129 | }, |
| 130 | ) |
| 131 | } |
| 132 | |
| 133 | #[inline ] |
| 134 | pub unsafe fn PyModule_FromDefAndSpec(def: *mut PyModuleDef, spec: *mut PyObject) -> *mut PyObject { |
| 135 | PyModule_FromDefAndSpec2( |
| 136 | def, |
| 137 | spec, |
| 138 | module_api_version:if cfg!(Py_LIMITED_API) { |
| 139 | PYTHON_ABI_VERSION |
| 140 | } else { |
| 141 | PYTHON_API_VERSION |
| 142 | }, |
| 143 | ) |
| 144 | } |
| 145 | |