@@ -263,15 +263,22 @@ PyList_SetItem(PyObject *op, Py_ssize_t i,
263
263
PyErr_BadInternalCall ();
264
264
return -1 ;
265
265
}
266
- if (!valid_index (i , Py_SIZE (op ))) {
266
+ int ret ;
267
+ PyListObject * self = ((PyListObject * )op );
268
+ Py_BEGIN_CRITICAL_SECTION (self );
269
+ if (!valid_index (i , Py_SIZE (self ))) {
267
270
Py_XDECREF (newitem );
268
271
PyErr_SetString (PyExc_IndexError ,
269
272
"list assignment index out of range" );
270
- return -1 ;
273
+ ret = -1 ;
274
+ goto end ;
271
275
}
272
- p = (( PyListObject * ) op ) -> ob_item + i ;
276
+ p = self -> ob_item + i ;
273
277
Py_XSETREF (* p , newitem );
274
- return 0 ;
278
+ ret = 0 ;
279
+ end :
280
+ Py_END_CRITICAL_SECTION ();
281
+ return ret ;
275
282
}
276
283
277
284
static int
@@ -309,7 +316,12 @@ PyList_Insert(PyObject *op, Py_ssize_t where, PyObject *newitem)
309
316
PyErr_BadInternalCall ();
310
317
return -1 ;
311
318
}
312
- return ins1 ((PyListObject * )op , where , newitem );
319
+ PyListObject * self = (PyListObject * )op ;
320
+ int err ;
321
+ Py_BEGIN_CRITICAL_SECTION (self );
322
+ err = ins1 (self , where , newitem );
323
+ Py_END_CRITICAL_SECTION ();
324
+ return err ;
313
325
}
314
326
315
327
/* internal, used by _PyList_AppendTakeRef */
@@ -804,9 +816,13 @@ static PyObject *
804
816
list_insert_impl (PyListObject * self , Py_ssize_t index , PyObject * object )
805
817
/*[clinic end generated code: output=7f35e32f60c8cb78 input=b1987ca998a4ae2d]*/
806
818
{
807
- if (ins1 (self , index , object ) == 0 )
808
- Py_RETURN_NONE ;
809
- return NULL ;
819
+ PyObject * ret = Py_None ;
820
+ Py_BEGIN_CRITICAL_SECTION (self );
821
+ if (ins1 (self , index , object ) < 0 ) {
822
+ ret = NULL ;
823
+ }
824
+ Py_END_CRITICAL_SECTION ();
825
+ return ret ;
810
826
}
811
827
812
828
/*[clinic input]
@@ -825,19 +841,21 @@ py_list_clear_impl(PyListObject *self)
825
841
}
826
842
827
843
/*[clinic input]
844
+ @critical_section
828
845
list.copy
829
846
830
847
Return a shallow copy of the list.
831
848
[clinic start generated code]*/
832
849
833
850
static PyObject *
834
851
list_copy_impl (PyListObject * self )
835
- /*[clinic end generated code: output=ec6b72d6209d418e input=6453ab159e84771f ]*/
852
+ /*[clinic end generated code: output=ec6b72d6209d418e input=81c54b0c7bb4f73d ]*/
836
853
{
837
854
return list_slice (self , 0 , Py_SIZE (self ));
838
855
}
839
856
840
857
/*[clinic input]
858
+ @critical_section
841
859
list.append
842
860
843
861
object: object
@@ -847,8 +865,8 @@ Append object to the end of the list.
847
865
[clinic start generated code]*/
848
866
849
867
static PyObject *
850
- list_append (PyListObject * self , PyObject * object )
851
- /*[clinic end generated code: output=7c096003a29c0eae input=43a3fe48a7066e91 ]*/
868
+ list_append_impl (PyListObject * self , PyObject * object )
869
+ /*[clinic end generated code: output=78423561d92ed405 input=122b0853de54004f ]*/
852
870
{
853
871
if (_PyList_AppendTakeRef (self , Py_NewRef (object )) < 0 ) {
854
872
return NULL ;
@@ -1006,6 +1024,7 @@ _PyList_Extend(PyListObject *self, PyObject *iterable)
1006
1024
1007
1025
1008
1026
/*[clinic input]
1027
+ @critical_section self iterable
1009
1028
list.extend as py_list_extend
1010
1029
1011
1030
iterable: object
@@ -1015,8 +1034,8 @@ Extend list by appending elements from the iterable.
1015
1034
[clinic start generated code]*/
1016
1035
1017
1036
static PyObject *
1018
- py_list_extend (PyListObject * self , PyObject * iterable )
1019
- /*[clinic end generated code: output=b8e0bff0ceae2abd input=9a8376a8633ed3ba ]*/
1037
+ py_list_extend_impl (PyListObject * self , PyObject * iterable )
1038
+ /*[clinic end generated code: output=a2f115ceace2c845 input=1d42175414e1a5f3 ]*/
1020
1039
{
1021
1040
return _PyList_Extend (self , iterable );
1022
1041
}
@@ -2612,8 +2631,11 @@ PyList_Reverse(PyObject *v)
2612
2631
PyErr_BadInternalCall ();
2613
2632
return -1 ;
2614
2633
}
2615
- if (Py_SIZE (self ) > 1 )
2634
+ Py_BEGIN_CRITICAL_SECTION (self );
2635
+ if (Py_SIZE (self ) > 1 ) {
2616
2636
reverse_slice (self -> ob_item , self -> ob_item + Py_SIZE (self ));
2637
+ }
2638
+ Py_END_CRITICAL_SECTION ()
2617
2639
return 0 ;
2618
2640
}
2619
2641
@@ -2624,7 +2646,12 @@ PyList_AsTuple(PyObject *v)
2624
2646
PyErr_BadInternalCall ();
2625
2647
return NULL ;
2626
2648
}
2627
- return _PyTuple_FromArray (((PyListObject * )v )-> ob_item , Py_SIZE (v ));
2649
+ PyObject * ret ;
2650
+ PyListObject * self = (PyListObject * )v ;
2651
+ Py_BEGIN_CRITICAL_SECTION (self );
2652
+ ret = _PyTuple_FromArray (self -> ob_item , Py_SIZE (v ));
2653
+ Py_END_CRITICAL_SECTION ();
2654
+ return ret ;
2628
2655
}
2629
2656
2630
2657
PyObject *
@@ -2773,7 +2800,7 @@ list_traverse(PyObject *self, visitproc visit, void *arg)
2773
2800
}
2774
2801
2775
2802
static PyObject *
2776
- list_richcompare (PyObject * v , PyObject * w , int op )
2803
+ list_richcompare_impl (PyObject * v , PyObject * w , int op )
2777
2804
{
2778
2805
PyListObject * vl , * wl ;
2779
2806
Py_ssize_t i ;
@@ -2828,6 +2855,16 @@ list_richcompare(PyObject *v, PyObject *w, int op)
2828
2855
return PyObject_RichCompare (vl -> ob_item [i ], wl -> ob_item [i ], op );
2829
2856
}
2830
2857
2858
+ static PyObject *
2859
+ list_richcompare (PyObject * v , PyObject * w , int op )
2860
+ {
2861
+ PyObject * ret ;
2862
+ Py_BEGIN_CRITICAL_SECTION2 (v , w );
2863
+ ret = list_richcompare_impl (v , w , op );
2864
+ Py_END_CRITICAL_SECTION2 ()
2865
+ return ret ;
2866
+ }
2867
+
2831
2868
/*[clinic input]
2832
2869
list.__init__
2833
2870
0 commit comments