Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2377 from herquan/herquan_cr1
Add macro append_to_inittab (issue #2359)
- Loading branch information
Showing
7 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![cfg(all(feature = "macros", not(PyPy)))] | ||
use pyo3::prelude::*; | ||
|
||
#[pyfunction] | ||
fn foo() -> usize { | ||
123 | ||
} | ||
|
||
#[pymodule] | ||
fn module_with_functions(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(foo, m)?).unwrap(); | ||
Ok(()) | ||
} | ||
|
||
#[cfg(not(PyPy))] | ||
#[test] | ||
fn test_module_append_to_inittab() { | ||
use pyo3::append_to_inittab; | ||
append_to_inittab!(module_with_functions); | ||
Python::with_gil(|py| { | ||
py.run( | ||
r#" | ||
import module_with_functions | ||
assert module_with_functions.foo() == 123 | ||
"#, | ||
None, | ||
None, | ||
) | ||
.map_err(|e| e.print(py)) | ||
.unwrap(); | ||
}) | ||
} |