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

fix nightly ci #4816

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pyo3-build-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ pub fn print_feature_cfgs() {
if rustc_minor_version >= 83 {
println!("cargo:rustc-cfg=io_error_more");
}

if rustc_minor_version >= 85 {
println!("cargo:rustc-cfg=fn_ptr_eq");
}
}

/// Registers `pyo3`s config names as reachable cfg expressions
Expand All @@ -185,6 +189,7 @@ pub fn print_expected_cfgs() {
println!("cargo:rustc-check-cfg=cfg(c_str_lit)");
println!("cargo:rustc-check-cfg=cfg(rustc_has_once_lock)");
println!("cargo:rustc-check-cfg=cfg(io_error_more)");
println!("cargo:rustc-check-cfg=cfg(fn_ptr_eq)");

// allow `Py_3_*` cfgs from the minimum supported version up to the
// maximum minor version (+1 for development for the next)
Expand Down
9 changes: 5 additions & 4 deletions src/impl_/pymethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
use std::ptr::null_mut;

use super::trampoline;
use crate::internal_tricks::{clear_eq, traverse_eq};

/// Python 3.8 and up - __ipow__ has modulo argument correctly populated.
#[cfg(Py_3_8)]
Expand Down Expand Up @@ -364,7 +365,7 @@ unsafe fn call_super_traverse(
// First find the current type by the current_traverse function
loop {
traverse = get_slot(ty, TP_TRAVERSE);
if traverse == Some(current_traverse) {
if traverse_eq(traverse, current_traverse) {
break;
}
ty = get_slot(ty, TP_BASE);
Expand All @@ -375,7 +376,7 @@ unsafe fn call_super_traverse(
}

// Get first base which has a different traverse function
while traverse == Some(current_traverse) {
while traverse_eq(traverse, current_traverse) {
ty = get_slot(ty, TP_BASE);
if ty.is_null() {
break;
Expand Down Expand Up @@ -429,7 +430,7 @@ unsafe fn call_super_clear(
// First find the current type by the current_clear function
loop {
clear = ty.get_slot(TP_CLEAR);
if clear == Some(current_clear) {
if clear_eq(clear, current_clear) {
break;
}
let base = ty.get_slot(TP_BASE);
Expand All @@ -441,7 +442,7 @@ unsafe fn call_super_clear(
}

// Get first base which has a different clear function
while clear == Some(current_clear) {
while clear_eq(clear, current_clear) {
let base = ty.get_slot(TP_BASE);
if base.is_null() {
break;
Expand Down
30 changes: 29 additions & 1 deletion src/internal_tricks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ffi::{Py_ssize_t, PY_SSIZE_T_MAX};
use crate::ffi::{self, Py_ssize_t, PY_SSIZE_T_MAX};
pub struct PrivateMarker;

macro_rules! private_decl {
Expand Down Expand Up @@ -47,3 +47,31 @@ pub(crate) const fn ptr_from_ref<T>(t: &T) -> *const T {
pub(crate) fn ptr_from_mut<T>(t: &mut T) -> *mut T {
t as *mut T
}

// TODO: use ptr::fn_addr_eq on MSRV 1.85
pub(crate) fn clear_eq(f: Option<ffi::inquiry>, g: ffi::inquiry) -> bool {
#[cfg(fn_ptr_eq)]
{
let Some(f) = f else { return false };
std::ptr::fn_addr_eq(f, g)
}

#[cfg(not(fn_ptr_eq))]
{
f == Some(g)
}
}

// TODO: use ptr::fn_addr_eq on MSRV 1.85
pub(crate) fn traverse_eq(f: Option<ffi::traverseproc>, g: ffi::traverseproc) -> bool {
#[cfg(fn_ptr_eq)]
{
let Some(f) = f else { return false };
std::ptr::fn_addr_eq(f, g)
}

#[cfg(not(fn_ptr_eq))]
{
f == Some(g)
}
}
Loading