Skip to content

Commit

Permalink
fix build on GIL-enabled and limited API builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Jan 6, 2025
1 parent 2967b21 commit 994bc49
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/types/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl<'py> BoundListIterator<'py> {
}
}

#[cfg(not(Py_LIMITED_API))]
fn with_critical_section<R>(
&mut self,
f: impl FnOnce(&mut Index, &mut Length, &Bound<'py, PyList>) -> R,
Expand All @@ -605,20 +606,21 @@ impl<'py> Iterator for BoundListIterator<'py> {

#[inline]
fn next(&mut self) -> Option<Self::Item> {
#[cfg(Py_GIL_DISABLED)]
#[cfg(not(Py_LIMITED_API))]
{
self.with_critical_section(|index, length, list| unsafe {
Self::next_unchecked(index, length, list)
})
}
#[cfg(Py_LIMITED_API)]
{
let Self {
index,
length,
list,
} = self;
Self::next(index, length, list)
}
#[cfg(all(not(Py_GIL_DISABLED), not(Py_LIMITED_API)))]
{
unsafe { Self::next_unchecked(index, length, list) }
}
}

#[inline]
Expand Down Expand Up @@ -751,20 +753,21 @@ impl<'py> Iterator for BoundListIterator<'py> {
impl DoubleEndedIterator for BoundListIterator<'_> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
#[cfg(Py_GIL_DISABLED)]
#[cfg(not(Py_LIMITED_API))]
{
self.with_critical_section(|index, length, list| unsafe {
Self::next_back_unchecked(index, length, list)
})
}
#[cfg(Py_LIMITED_API)]
{
let Self {
index,
length,
list,
} = self;
Self::next_back(index, length, list)
}
#[cfg(all(not(Py_GIL_DISABLED), not(Py_LIMITED_API)))]
{
unsafe { Self::next_back_unchecked(index, length, list) }
}
}

#[inline]
Expand Down

0 comments on commit 994bc49

Please sign in to comment.