Commit db9a1c2
pythongh-127582: Make object resurrection thread-safe for free threading. (pythonGH-127612)
Objects may be temporarily "resurrected" in destructors when calling
finalizers or watcher callbacks. We previously undid the resurrection
by decrementing the reference count using `Py_SET_REFCNT`. This was not
thread-safe because other threads might be accessing the object
(modifying its reference count) if it was exposed by the finalizer,
watcher callback, or temporarily accessed by a racy dictionary or list
access.
This adds internal-only thread-safe functions for temporary object
resurrection during destructors.1 parent 3fb5161 commit db9a1c2
File tree
6 files changed
+87
-20
lines changed- Include/internal
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
6 files changed
+87
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
| 700 | + | |
700 | 701 | | |
701 | 702 | | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
702 | 746 | | |
703 | 747 | | |
704 | 748 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1867 | 1867 | | |
1868 | 1868 | | |
1869 | 1869 | | |
1870 | | - | |
1871 | | - | |
| 1870 | + | |
1872 | 1871 | | |
1873 | | - | |
1874 | | - | |
| 1872 | + | |
1875 | 1873 | | |
1876 | 1874 | | |
1877 | | - | |
1878 | 1875 | | |
1879 | 1876 | | |
1880 | 1877 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3162 | 3162 | | |
3163 | 3163 | | |
3164 | 3164 | | |
3165 | | - | |
3166 | | - | |
| 3165 | + | |
3167 | 3166 | | |
3168 | | - | |
3169 | | - | |
| 3167 | + | |
3170 | 3168 | | |
3171 | 3169 | | |
3172 | | - | |
3173 | 3170 | | |
3174 | 3171 | | |
3175 | 3172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1092 | 1092 | | |
1093 | 1093 | | |
1094 | 1094 | | |
1095 | | - | |
1096 | | - | |
| 1095 | + | |
1097 | 1096 | | |
1098 | | - | |
1099 | | - | |
| 1097 | + | |
1100 | 1098 | | |
1101 | 1099 | | |
1102 | | - | |
1103 | 1100 | | |
1104 | 1101 | | |
1105 | 1102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
366 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
| |||
404 | 406 | | |
405 | 407 | | |
406 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
407 | 418 | | |
408 | 419 | | |
409 | 420 | | |
| |||
472 | 483 | | |
473 | 484 | | |
474 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
475 | 506 | | |
476 | 507 | | |
477 | 508 | | |
| |||
550 | 581 | | |
551 | 582 | | |
552 | 583 | | |
553 | | - | |
| 584 | + | |
554 | 585 | | |
555 | 586 | | |
556 | 587 | | |
| |||
560 | 591 | | |
561 | 592 | | |
562 | 593 | | |
563 | | - | |
564 | | - | |
| 594 | + | |
565 | 595 | | |
566 | 596 | | |
567 | 597 | | |
| |||
0 commit comments