Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pymethods: __ipow__ always receive None on Python 3.7
- Loading branch information
1 parent
50659b6
commit c1c25d8
Showing
10 changed files
with
63 additions
and
288 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 was deleted.
Oops, something went wrong.
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::{Python, FromPyObject, PyResult, ffi, PyAny}; | ||
|
||
/// 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() | ||
} | ||
} |
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
Oops, something went wrong.