Repository navigation
Make dict traversal safe on free-threaded Python - #144
divyanshu-iitian wants to merge 1 commit into
Conversation
|
Thanks @divyanshu-iitian for tracking this down and fixing it. I reported #143, and independently verified this PR at its current head Built and run on macOS arm64 across seven environments: CPython 3.12.11, 3.13.5, 3.13.5t, 3.14.6 and 3.14.0rc1t for the candidate, plus 3.14.6 and 3.14.0rc1t for the base. Concurrent arms, fresh subprocesses throughout:
Three arms drive the base row: the original value-replacement assertion race, key deletion and reinsertion, and the Across those seven build/environment runs I observed 495 unittest cases and 350 doctest examples in total, with 0 failures and 3 expected skips. After this lands, I'm happy to contribute additional concurrent regression coverage for the modified Scope: local macOS arm64 only. This does not establish Windows or Linux behaviour, other architectures, or concurrent semantics beyond the three named races. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The borrowed-reference hazard is fixed, but there is still a size/snapshot race: the sizes can match, then o1 can lose a key before PyDict_Keys(o1); every key in that smaller snapshot may still exist in o2, so this can report equal structures while o2 has an extra key. Could the snapshot length be rechecked against o2, or both key sets be snapshotted, so concurrent mutation fails rather than yielding a false equality?
Summary
PyDict_GetItemRefon Python 3.13+ and a compatible fallback on older versionsPyDict_Nextacross concurrent mutationFixes #143
Testing