@@ -2577,6 +2577,7 @@ unsafe_tuple_compare(PyObject *v, PyObject *w, MergeState *ms)
2577
2577
* duplicated).
2578
2578
*/
2579
2579
/*[clinic input]
2580
+ @critical_section
2580
2581
list.sort
2581
2582
2582
2583
*
@@ -2596,7 +2597,7 @@ The reverse flag can be set to sort in descending order.
2596
2597
2597
2598
static PyObject *
2598
2599
list_sort_impl (PyListObject * self , PyObject * keyfunc , int reverse )
2599
- /*[clinic end generated code: output=57b9f9c5e23fbe42 input=a74c4cd3ec6b5c08 ]*/
2600
+ /*[clinic end generated code: output=57b9f9c5e23fbe42 input=667bf25d0e3a3676 ]*/
2600
2601
{
2601
2602
MergeState ms ;
2602
2603
Py_ssize_t nremaining ;
@@ -2623,7 +2624,7 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
2623
2624
saved_ob_item = self -> ob_item ;
2624
2625
saved_allocated = self -> allocated ;
2625
2626
Py_SET_SIZE (self , 0 );
2626
- self -> ob_item = NULL ;
2627
+ FT_ATOMIC_STORE_PTR_RELEASE ( self -> ob_item , NULL ) ;
2627
2628
self -> allocated = -1 ; /* any operation will reset it to >= 0 */
2628
2629
2629
2630
if (keyfunc == NULL ) {
@@ -2843,8 +2844,8 @@ list_sort_impl(PyListObject *self, PyObject *keyfunc, int reverse)
2843
2844
final_ob_item = self -> ob_item ;
2844
2845
i = Py_SIZE (self );
2845
2846
Py_SET_SIZE (self , saved_ob_size );
2846
- self -> ob_item = saved_ob_item ;
2847
- self -> allocated = saved_allocated ;
2847
+ FT_ATOMIC_STORE_PTR_RELEASE ( self -> ob_item , saved_ob_item ) ;
2848
+ FT_ATOMIC_STORE_SSIZE_RELAXED ( self -> allocated , saved_allocated ) ;
2848
2849
if (final_ob_item != NULL ) {
2849
2850
/* we cannot use list_clear() for this because it does not
2850
2851
guarantee that the list is really empty when it returns */
@@ -2870,7 +2871,9 @@ PyList_Sort(PyObject *v)
2870
2871
PyErr_BadInternalCall ();
2871
2872
return -1 ;
2872
2873
}
2874
+ Py_BEGIN_CRITICAL_SECTION (v );
2873
2875
v = list_sort_impl ((PyListObject * )v , NULL , 0 );
2876
+ Py_END_CRITICAL_SECTION ();
2874
2877
if (v == NULL )
2875
2878
return -1 ;
2876
2879
Py_DECREF (v );
0 commit comments