Skip to content

Commit 5a666ec

Browse files
Icxoludavidhewitt
authored andcommitted
fix nightly ci (#4816)
1 parent 393eafb commit 5a666ec

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

pyo3-build-config/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ pub fn print_feature_cfgs() {
156156
if rustc_minor_version >= 79 {
157157
println!("cargo:rustc-cfg=diagnostic_namespace");
158158
}
159+
160+
if rustc_minor_version >= 85 {
161+
println!("cargo:rustc-cfg=fn_ptr_eq");
162+
}
159163
}
160164

161165
/// Registers `pyo3`s config names as reachable cfg expressions
@@ -180,6 +184,7 @@ pub fn print_expected_cfgs() {
180184
println!("cargo:rustc-check-cfg=cfg(diagnostic_namespace)");
181185
println!("cargo:rustc-check-cfg=cfg(c_str_lit)");
182186
println!("cargo:rustc-check-cfg=cfg(rustc_has_once_lock)");
187+
println!("cargo:rustc-check-cfg=cfg(fn_ptr_eq)");
183188

184189
// allow `Py_3_*` cfgs from the minimum supported version up to the
185190
// maximum minor version (+1 for development for the next)

src/impl_/pymethods.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::panic::{catch_unwind, AssertUnwindSafe};
2121
use std::ptr::null_mut;
2222

2323
use super::trampoline;
24+
use crate::internal_tricks::{clear_eq, traverse_eq};
2425

2526
/// Python 3.8 and up - __ipow__ has modulo argument correctly populated.
2627
#[cfg(Py_3_8)]
@@ -364,7 +365,7 @@ unsafe fn call_super_traverse(
364365
// First find the current type by the current_traverse function
365366
loop {
366367
traverse = get_slot(ty, TP_TRAVERSE);
367-
if traverse == Some(current_traverse) {
368+
if traverse_eq(traverse, current_traverse) {
368369
break;
369370
}
370371
ty = get_slot(ty, TP_BASE);
@@ -375,7 +376,7 @@ unsafe fn call_super_traverse(
375376
}
376377

377378
// Get first base which has a different traverse function
378-
while traverse == Some(current_traverse) {
379+
while traverse_eq(traverse, current_traverse) {
379380
ty = get_slot(ty, TP_BASE);
380381
if ty.is_null() {
381382
break;
@@ -429,7 +430,7 @@ unsafe fn call_super_clear(
429430
// First find the current type by the current_clear function
430431
loop {
431432
clear = ty.get_slot(TP_CLEAR);
432-
if clear == Some(current_clear) {
433+
if clear_eq(clear, current_clear) {
433434
break;
434435
}
435436
let base = ty.get_slot(TP_BASE);
@@ -441,7 +442,7 @@ unsafe fn call_super_clear(
441442
}
442443

443444
// Get first base which has a different clear function
444-
while clear == Some(current_clear) {
445+
while clear_eq(clear, current_clear) {
445446
let base = ty.get_slot(TP_BASE);
446447
if base.is_null() {
447448
break;

src/internal_tricks.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ffi::{Py_ssize_t, PY_SSIZE_T_MAX};
1+
use crate::ffi::{self, Py_ssize_t, PY_SSIZE_T_MAX};
22
pub struct PrivateMarker;
33

44
macro_rules! private_decl {
@@ -47,3 +47,31 @@ pub(crate) const fn ptr_from_ref<T>(t: &T) -> *const T {
4747
pub(crate) fn ptr_from_mut<T>(t: &mut T) -> *mut T {
4848
t as *mut T
4949
}
50+
51+
// TODO: use ptr::fn_addr_eq on MSRV 1.85
52+
pub(crate) fn clear_eq(f: Option<ffi::inquiry>, g: ffi::inquiry) -> bool {
53+
#[cfg(fn_ptr_eq)]
54+
{
55+
let Some(f) = f else { return false };
56+
std::ptr::fn_addr_eq(f, g)
57+
}
58+
59+
#[cfg(not(fn_ptr_eq))]
60+
{
61+
f == Some(g)
62+
}
63+
}
64+
65+
// TODO: use ptr::fn_addr_eq on MSRV 1.85
66+
pub(crate) fn traverse_eq(f: Option<ffi::traverseproc>, g: ffi::traverseproc) -> bool {
67+
#[cfg(fn_ptr_eq)]
68+
{
69+
let Some(f) = f else { return false };
70+
std::ptr::fn_addr_eq(f, g)
71+
}
72+
73+
#[cfg(not(fn_ptr_eq))]
74+
{
75+
f == Some(g)
76+
}
77+
}

0 commit comments

Comments
 (0)