Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove internal APIs from pyo3-ffi #4201

Merged
merged 12 commits into from
Jun 5, 2024
23 changes: 13 additions & 10 deletions src/types/complex.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(any(Py_LIMITED_API, PyPy)))]
use crate::py_result_ext::PyResultExt;
#[cfg(feature = "gil-refs")]
use crate::PyNativeType;
use crate::{ffi, types::any::PyAnyMethods, Bound, PyAny, Python};
Expand Down Expand Up @@ -89,15 +91,16 @@ mod not_limited_impls {
}

macro_rules! bin_ops {
($trait:ident, $fn:ident, $op:tt, $ffi:path) => {
($trait:ident, $fn:ident, $op:tt) => {
impl<'py> $trait for Borrowed<'_, 'py, PyComplex> {
type Output = Bound<'py, PyComplex>;
fn $fn(self, other: Self) -> Self::Output {
unsafe {
complex_operation(self, other, $ffi)
.assume_owned(self.py())
.downcast_into_unchecked()
}
PyAnyMethods::$fn(self.as_any(), other)
.downcast_into().expect(
concat!("Complex method ",
stringify!($fn),
" failed.")
)
}
}

Expand Down Expand Up @@ -139,10 +142,10 @@ mod not_limited_impls {
};
}

bin_ops!(Add, add, +, ffi::_Py_c_sum);
bin_ops!(Sub, sub, -, ffi::_Py_c_diff);
bin_ops!(Mul, mul, *, ffi::_Py_c_prod);
bin_ops!(Div, div, /, ffi::_Py_c_quot);
bin_ops!(Add, add, +);
bin_ops!(Sub, sub, -);
bin_ops!(Mul, mul, *);
bin_ops!(Div, div, /);

#[cfg(feature = "gil-refs")]
impl<'py> Neg for &'py PyComplex {
Expand Down
Loading