Skip to content

Commit

Permalink
fix nightly ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Dec 23, 2024
1 parent ea8c461 commit 121b768
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
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)
}
}

0 comments on commit 121b768

Please sign in to comment.