Skip to content

Commit

Permalink
Make PyDict iterator compatible with free-threaded build (#4439)
Browse files Browse the repository at this point in the history
* Iterate over dict items in `DictIterator`

* Use python instead of C API to get dict items

* Use plain dict iterator when not on free-threaded & not a subclass

* Copy dict on free-threaded builds to prevent concurrent modifications

* Add test for dict subclass iters

* Implement `PyDict::locked_for_each`

* Lock `BoundDictIterator::next` on each iteration

* Implement locked `fold` & `try_fold`

* Implement `all`,`any`,`find`,`find_map`,`position` when not on nightly

* Add changelog

* Use critical section wrapper

* Make `dict::locked_for_each` available on all builds

* Remove item() iter

* Add tests for `PyDict::iter()` reducers

* Add more docs to locked_for_each

* Move iter implementation into inner struct
  • Loading branch information
bschoenmaeckers authored Oct 24, 2024
1 parent 96c31e7 commit 602fbba
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 57 deletions.
3 changes: 3 additions & 0 deletions newsfragments/4439.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Make `PyDict` iterator compatible with free-threaded build
* Added `PyDict::locked_for_each` method to iterate on free-threaded builds to prevent the dict being mutated during iteration
* Iterate over `dict.items()` when dict is subclassed from `PyDict`
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![warn(missing_docs)]
#![cfg_attr(feature = "nightly", feature(auto_traits, negative_impls))]
#![cfg_attr(
feature = "nightly",
feature(auto_traits, negative_impls, try_trait_v2)
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// Deny some lints in doctests.
// Use `#[allow(...)]` locally to override.
Expand Down
Loading

0 comments on commit 602fbba

Please sign in to comment.