1 /// We speed up compilation by using the expanded output and then deselecting the macro feature
2 /// of pyo3, removing syn and proc macros from the dependencies
3 use pyo3::prelude::*;
4 
add(x: usize, y: usize) -> usize5 fn add(x: usize, y: usize) -> usize {
6     let sum = some_path_dep::add(x, y);
7     debug_assert!(some_path_dep::is_sum(x, y, sum));
8     sum
9 }
10 
__pyo3_raw_add( _slf: *mut pyo3::ffi::PyObject, _args: *mut pyo3::ffi::PyObject, _kwargs: *mut pyo3::ffi::PyObject, ) -> *mut pyo3::ffi::PyObject11 unsafe extern "C" fn __pyo3_raw_add(
12     _slf: *mut pyo3::ffi::PyObject,
13     _args: *mut pyo3::ffi::PyObject,
14     _kwargs: *mut pyo3::ffi::PyObject,
15 ) -> *mut pyo3::ffi::PyObject {
16     const _LOCATION: &'static str = "add()";
17 
18     let pool = ::pyo3::GILPool::new();
19     let unwind_safe_py = std::panic::AssertUnwindSafe(pool.python());
20     let result = match std::panic::catch_unwind(move || -> ::pyo3::PyResult<_> {
21         let _py = *unwind_safe_py;
22         ::pyo3::callback::convert(_py, {
23             let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
24             let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);
25             {
26                 const PARAMS: &'static [pyo3::derive_utils::ParamDescription] = &[
27                     pyo3::derive_utils::ParamDescription {
28                         name: "x",
29                         is_optional: false,
30                         kw_only: false,
31                     },
32                     pyo3::derive_utils::ParamDescription {
33                         name: "y",
34                         is_optional: false,
35                         kw_only: false,
36                     },
37                 ];
38                 let mut output = [None; 2usize];
39                 let mut _args = _args;
40                 let mut _kwargs = _kwargs;
41                 let (_args, _kwargs) = pyo3::derive_utils::parse_fn_args(
42                     Some(_LOCATION),
43                     PARAMS,
44                     _args,
45                     _kwargs,
46                     false,
47                     false,
48                     &mut output,
49                 )?;
50                 let arg0 = match output[0usize] {
51                     Some(_obj) => _obj
52                         .extract()
53                         .map_err(|e| pyo3::derive_utils::argument_extraction_error(_py, "x", e))?,
54                     None => {
55                         panic!("Failed to extract required method argument")
56                     }
57                 };
58                 let arg1 = match output[1usize] {
59                     Some(_obj) => _obj
60                         .extract()
61                         .map_err(|e| pyo3::derive_utils::argument_extraction_error(_py, "y", e))?,
62                     None => {
63                         panic!("Failed to extract required method argument")
64                     }
65                 };
66                 add(arg0, arg1)
67             }
68         })
69     }) {
70         Ok(result) => result,
71         Err(e) => {
72             if let Some(string) = e.downcast_ref::<String>() {
73                 Err(::pyo3::panic::PanicException::new_err((string.clone(),)))
74             } else if let Some(s) = e.downcast_ref::<&str>() {
75                 Err(::pyo3::panic::PanicException::new_err((s.to_string(),)))
76             } else {
77                 Err(::pyo3::panic::PanicException::new_err((
78                     "panic from Rust code",
79                 )))
80             }
81         }
82     };
83     result.unwrap_or_else(|e| {
84         e.restore(pool.python());
85         ::pyo3::callback::callback_error()
86     })
87 }
__pyo3_get_function_add<'a>( args: impl Into<pyo3::derive_utils::PyFunctionArguments<'a>>, ) -> pyo3::PyResult<&'a pyo3::types::PyCFunction>88 pub(crate) fn __pyo3_get_function_add<'a>(
89     args: impl Into<pyo3::derive_utils::PyFunctionArguments<'a>>,
90 ) -> pyo3::PyResult<&'a pyo3::types::PyCFunction> {
91     let name = "add\u{0}";
92     let name = std::ffi::CStr::from_bytes_with_nul(name.as_bytes()).unwrap();
93     let doc = std::ffi::CStr::from_bytes_with_nul(b"\x00").unwrap();
94     pyo3::types::PyCFunction::internal_new(
95         name,
96         doc,
97         pyo3::class::PyMethodType::PyCFunctionWithKeywords(__pyo3_raw_add),
98         pyo3::ffi::METH_VARARGS | pyo3::ffi::METH_KEYWORDS,
99         args.into(),
100     )
101 }
102 
pyo3_pure(_py: Python, m: &PyModule) -> PyResult<()>103 fn pyo3_pure(_py: Python, m: &PyModule) -> PyResult<()> {
104     m.add_wrapped(&__pyo3_get_function_add)?;
105     Ok(())
106 }
107 
108 #[no_mangle]
109 #[allow(non_snake_case)]
110 #[doc = r" This autogenerated function is called by the python interpreter when importing"]
111 #[doc = r" the module."]
PyInit_lib_with_path_dep() -> *mut pyo3::ffi::PyObject112 pub unsafe extern "C" fn PyInit_lib_with_path_dep() -> *mut pyo3::ffi::PyObject {
113     use pyo3::derive_utils::ModuleDef;
114     const NAME: &'static str = "pyo3_pure\u{0}";
115     static MODULE_DEF: ModuleDef = unsafe { ModuleDef::new(NAME) };
116     let pool = ::pyo3::GILPool::new();
117     let unwind_safe_py = std::panic::AssertUnwindSafe(pool.python());
118     let result = match std::panic::catch_unwind(move || -> ::pyo3::PyResult<_> {
119         let _py = *unwind_safe_py;
120         ::pyo3::callback::convert(_py, MODULE_DEF.make_module("", pyo3_pure))
121     }) {
122         Ok(result) => result,
123         Err(e) => {
124             if let Some(string) = e.downcast_ref::<String>() {
125                 Err(::pyo3::panic::PanicException::new_err((string.clone(),)))
126             } else if let Some(s) = e.downcast_ref::<&str>() {
127                 Err(::pyo3::panic::PanicException::new_err((s.to_string(),)))
128             } else {
129                 Err(::pyo3::panic::PanicException::new_err((
130                     "panic from Rust code",
131                 )))
132             }
133         }
134     };
135     result.unwrap_or_else(|e| {
136         e.restore(pool.python());
137         ::pyo3::callback::callback_error()
138     })
139 }
140