Repository navigation
Commit 364cc82
committed
gh-154130: Fix double decref of the dict in shared dict iterators
In the free-threaded build, threads advancing the same dict iterator each
read `di_dict` as a borrowed reference, so concurrently exhausting it could run
`di->di_dict = NULL; Py_DECREF(d)` more than once and free the dict while
other threads were still using it. Reversed iterators were also affected:
they dropped the reference while holding the dict's critical section.
In the free-threaded build, keep the iterator's reference to the dict until
the iterator is deallocated (as list and tuple iterators do) and mark
exhaustion by setting `di_pos` to -1.1 parent f65e2a2 commit 364cc82
2 files changed
Lines changed: 86 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
496 | 541 | | |
497 | 542 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5705 | 5705 | | |
5706 | 5706 | | |
5707 | 5707 | | |
| 5708 | + | |
| 5709 | + | |
| 5710 | + | |
| 5711 | + | |
| 5712 | + | |
| 5713 | + | |
| 5714 | + | |
| 5715 | + | |
| 5716 | + | |
| 5717 | + | |
| 5718 | + | |
| 5719 | + | |
| 5720 | + | |
| 5721 | + | |
| 5722 | + | |
| 5723 | + | |
| 5724 | + | |
| 5725 | + | |
| 5726 | + | |
| 5727 | + | |
| 5728 | + | |
| 5729 | + | |
5708 | 5730 | | |
5709 | 5731 | | |
5710 | 5732 | | |
| |||
5970 | 5992 | | |
5971 | 5993 | | |
5972 | 5994 | | |
| 5995 | + | |
| 5996 | + | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
5973 | 6000 | | |
5974 | 6001 | | |
5975 | 6002 | | |
5976 | 6003 | | |
5977 | 6004 | | |
5978 | 6005 | | |
5979 | 6006 | | |
5980 | | - | |
5981 | | - | |
5982 | | - | |
5983 | 6007 | | |
5984 | 6008 | | |
5985 | 6009 | | |
| |||
6030 | 6054 | | |
6031 | 6055 | | |
6032 | 6056 | | |
6033 | | - | |
6034 | | - | |
| 6057 | + | |
6035 | 6058 | | |
6036 | 6059 | | |
6037 | 6060 | | |
| |||
6075 | 6098 | | |
6076 | 6099 | | |
6077 | 6100 | | |
| 6101 | + | |
| 6102 | + | |
| 6103 | + | |
| 6104 | + | |
| 6105 | + | |
6078 | 6106 | | |
6079 | 6107 | | |
6080 | 6108 | | |
| |||
6084 | 6112 | | |
6085 | 6113 | | |
6086 | 6114 | | |
6087 | | - | |
6088 | 6115 | | |
6089 | | - | |
6090 | 6116 | | |
6091 | 6117 | | |
6092 | 6118 | | |
| |||
6165 | 6191 | | |
6166 | 6192 | | |
6167 | 6193 | | |
6168 | | - | |
6169 | | - | |
| 6194 | + | |
6170 | 6195 | | |
6171 | 6196 | | |
6172 | 6197 | | |
| |||
6268 | 6293 | | |
6269 | 6294 | | |
6270 | 6295 | | |
| 6296 | + | |
| 6297 | + | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
6271 | 6302 | | |
6272 | 6303 | | |
6273 | 6304 | | |
| |||
6354 | 6385 | | |
6355 | 6386 | | |
6356 | 6387 | | |
6357 | | - | |
6358 | | - | |
| 6388 | + | |
6359 | 6389 | | |
6360 | 6390 | | |
6361 | 6391 | | |
| |||
0 commit comments