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 #2083 from aviramha/magic_methods
verify py method args count
- Loading branch information
Showing
16 changed files
with
520 additions
and
18 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
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,33 @@ | ||
use crate::{ffi, FromPyObject, PyAny, PyResult, Python}; | ||
|
||
/// Python 3.8 and up - __ipow__ has modulo argument correctly populated. | ||
#[cfg(Py_3_8)] | ||
#[repr(transparent)] | ||
pub struct IPowModulo(*mut ffi::PyObject); | ||
|
||
/// Python 3.7 and older - __ipow__ does not have modulo argument correctly populated. | ||
#[cfg(not(Py_3_8))] | ||
#[repr(transparent)] | ||
pub struct IPowModulo(std::mem::MaybeUninit<*mut ffi::PyObject>); | ||
|
||
/// Helper to use as pymethod ffi definition | ||
#[allow(non_camel_case_types)] | ||
pub type ipowfunc = unsafe extern "C" fn( | ||
arg1: *mut ffi::PyObject, | ||
arg2: *mut ffi::PyObject, | ||
arg3: IPowModulo, | ||
) -> *mut ffi::PyObject; | ||
|
||
impl IPowModulo { | ||
#[cfg(Py_3_8)] | ||
#[inline] | ||
pub fn extract<'a, T: FromPyObject<'a>>(self, py: Python<'a>) -> PyResult<T> { | ||
unsafe { py.from_borrowed_ptr::<PyAny>(self.0) }.extract() | ||
} | ||
|
||
#[cfg(not(Py_3_8))] | ||
#[inline] | ||
pub fn extract<'a, T: FromPyObject<'a>>(self, py: Python<'a>) -> PyResult<T> { | ||
unsafe { py.from_borrowed_ptr::<PyAny>(ffi::Py_None()) }.extract() | ||
} | ||
} |
Oops, something went wrong.