Commit dabcecf
authored
The CALL family of instructions were mostly thread-safe already and only required a small number of changes, which are documented below.
A few changes were needed to make CALL_ALLOC_AND_ENTER_INIT thread-safe:
Added _PyType_LookupRefAndVersion, which returns the type version corresponding to the returned ref.
Added _PyType_CacheInitForSpecialization, which takes an init method and the corresponding type version and only populates the specialization cache if the current type version matches the supplied version. This prevents potentially caching a stale value in free-threaded builds if we race with an update to __init__.
Only cache __init__ functions that are deferred in free-threaded builds. This ensures that the reference to __init__ that is stored in the specialization cache is valid if the type version guard in _CHECK_AND_ALLOCATE_OBJECT passes.
Fix a bug in _CREATE_INIT_FRAME where the frame is pushed to the stack on failure.
A few other miscellaneous changes were also needed:
Use {LOCK,UNLOCK}_OBJECT in LIST_APPEND. This ensures that the list's per-object lock is held while we are appending to it.
Add missing co_tlbc for _Py_InitCleanup.
Stop/start the world around setting the eval frame hook. This allows us to read interp->eval_frame non-atomically and preserves the behavior of _CHECK_PEP_523 documented below.
1 parent fc5a0dc commit dabcecf
File tree
11 files changed
+220
-92
lines changed- Include/internal
- Lib/test
- Objects
- Python
11 files changed
+220
-92
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
838 | 852 | | |
839 | 853 | | |
840 | 854 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
853 | 860 | | |
854 | 861 | | |
855 | 862 | | |
| |||
1045 | 1052 | | |
1046 | 1053 | | |
1047 | 1054 | | |
1048 | | - | |
| 1055 | + | |
1049 | 1056 | | |
1050 | 1057 | | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | 1058 | | |
1056 | 1059 | | |
1057 | | - | |
| 1060 | + | |
1058 | 1061 | | |
1059 | 1062 | | |
1060 | 1063 | | |
| |||
| 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 | + | |
496 | 508 | | |
497 | 509 | | |
498 | 510 | | |
| |||
522 | 534 | | |
523 | 535 | | |
524 | 536 | | |
525 | | - | |
| 537 | + | |
526 | 538 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | 539 | | |
532 | 540 | | |
533 | 541 | | |
| |||
544 | 552 | | |
545 | 553 | | |
546 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
547 | 569 | | |
548 | 570 | | |
549 | 571 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
| |||
140 | 139 | | |
141 | 140 | | |
142 | 141 | | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| |||
192 | 194 | | |
193 | 195 | | |
194 | 196 | | |
| 197 | + | |
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
| |||
211 | 214 | | |
212 | 215 | | |
213 | 216 | | |
| 217 | + | |
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| |||
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| 238 | + | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5528 | 5528 | | |
5529 | 5529 | | |
5530 | 5530 | | |
5531 | | - | |
| 5531 | + | |
| 5532 | + | |
| 5533 | + | |
| 5534 | + | |
5532 | 5535 | | |
5533 | | - | |
| 5536 | + | |
5534 | 5537 | | |
5535 | 5538 | | |
5536 | 5539 | | |
| |||
5553 | 5556 | | |
5554 | 5557 | | |
5555 | 5558 | | |
| 5559 | + | |
| 5560 | + | |
| 5561 | + | |
5556 | 5562 | | |
5557 | 5563 | | |
5558 | 5564 | | |
| |||
5574 | 5580 | | |
5575 | 5581 | | |
5576 | 5582 | | |
| 5583 | + | |
| 5584 | + | |
| 5585 | + | |
5577 | 5586 | | |
5578 | 5587 | | |
5579 | 5588 | | |
| |||
5587 | 5596 | | |
5588 | 5597 | | |
5589 | 5598 | | |
5590 | | - | |
| 5599 | + | |
5591 | 5600 | | |
5592 | 5601 | | |
5593 | 5602 | | |
5594 | 5603 | | |
5595 | | - | |
| 5604 | + | |
5596 | 5605 | | |
5597 | 5606 | | |
5598 | 5607 | | |
| |||
5609 | 5618 | | |
5610 | 5619 | | |
5611 | 5620 | | |
| 5621 | + | |
| 5622 | + | |
| 5623 | + | |
| 5624 | + | |
5612 | 5625 | | |
5613 | 5626 | | |
5614 | 5627 | | |
5615 | 5628 | | |
5616 | 5629 | | |
5617 | | - | |
| 5630 | + | |
5618 | 5631 | | |
5619 | | - | |
| 5632 | + | |
5620 | 5633 | | |
5621 | 5634 | | |
5622 | 5635 | | |
| 5636 | + | |
| 5637 | + | |
| 5638 | + | |
| 5639 | + | |
5623 | 5640 | | |
5624 | 5641 | | |
5625 | 5642 | | |
| 5643 | + | |
| 5644 | + | |
| 5645 | + | |
| 5646 | + | |
| 5647 | + | |
| 5648 | + | |
| 5649 | + | |
| 5650 | + | |
| 5651 | + | |
| 5652 | + | |
| 5653 | + | |
5626 | 5654 | | |
5627 | 5655 | | |
5628 | 5656 | | |
5629 | | - | |
| 5657 | + | |
5630 | 5658 | | |
5631 | 5659 | | |
5632 | 5660 | | |
5633 | 5661 | | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
5634 | 5682 | | |
5635 | 5683 | | |
5636 | 5684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3329 | 3329 | | |
3330 | 3330 | | |
3331 | 3331 | | |
3332 | | - | |
| 3332 | + | |
3333 | 3333 | | |
3334 | 3334 | | |
3335 | 3335 | | |
3336 | 3336 | | |
3337 | 3337 | | |
3338 | 3338 | | |
3339 | 3339 | | |
3340 | | - | |
| 3340 | + | |
3341 | 3341 | | |
3342 | 3342 | | |
3343 | 3343 | | |
| |||
3722 | 3722 | | |
3723 | 3723 | | |
3724 | 3724 | | |
3725 | | - | |
| 3725 | + | |
3726 | 3726 | | |
3727 | 3727 | | |
3728 | | - | |
| 3728 | + | |
3729 | 3729 | | |
3730 | 3730 | | |
3731 | 3731 | | |
| |||
3743 | 3743 | | |
3744 | 3744 | | |
3745 | 3745 | | |
| 3746 | + | |
3746 | 3747 | | |
3747 | 3748 | | |
3748 | 3749 | | |
3749 | 3750 | | |
3750 | | - | |
| 3751 | + | |
3751 | 3752 | | |
3752 | 3753 | | |
3753 | | - | |
| 3754 | + | |
3754 | 3755 | | |
3755 | 3756 | | |
3756 | 3757 | | |
| 3758 | + | |
3757 | 3759 | | |
3758 | 3760 | | |
3759 | 3761 | | |
| |||
4000 | 4002 | | |
4001 | 4003 | | |
4002 | 4004 | | |
| 4005 | + | |
4003 | 4006 | | |
4004 | 4007 | | |
| 4008 | + | |
4005 | 4009 | | |
4006 | 4010 | | |
4007 | 4011 | | |
| |||
0 commit comments