@@ -201,6 +201,9 @@ abstract static class IMulNode extends PythonBinaryClinicBuiltinNode {
201
201
Object concat (PArray self , int value ) {
202
202
try {
203
203
int newLength = Math .max (PythonUtils .multiplyExact (self .getLength (), value ), 0 );
204
+ if (newLength != self .getLength ()) {
205
+ self .checkCanResize (this );
206
+ }
204
207
int itemsize = self .getFormat ().bytesize ;
205
208
int segmentLength = self .getLength () * itemsize ;
206
209
self .resize (newLength );
@@ -533,6 +536,7 @@ Object setitem(PArray self, PSlice slice, PArray other,
533
536
}
534
537
if (simpleStepProfile .profile (step == 1 )) {
535
538
if (differentLengthProfile .profile (sliceLength != needed )) {
539
+ self .checkCanResize (this );
536
540
if (growProfile .profile (sliceLength < needed )) {
537
541
if (stop < start ) {
538
542
stop = start ;
@@ -579,19 +583,21 @@ abstract static class DelItemNode extends PythonBinaryBuiltinNode {
579
583
public abstract Object executeSlice (PArray self , PSlice slice );
580
584
581
585
@ Specialization (guards = "!isPSlice(idx)" , limit = "3" )
582
- static Object delitem (PArray self , Object idx ,
586
+ Object delitem (PArray self , Object idx ,
583
587
@ CachedLibrary ("idx" ) PythonObjectLibrary lib ,
584
588
@ Cached ("forArrayAssign()" ) NormalizeIndexNode normalizeIndexNode ) {
589
+ self .checkCanResize (this );
585
590
int index = normalizeIndexNode .execute (lib .asIndex (idx ), self .getLength ());
586
591
self .delSlice (index , 1 );
587
592
return PNone .NONE ;
588
593
}
589
594
590
595
@ Specialization
591
- static Object delitem (PArray self , PSlice slice ,
596
+ Object delitem (PArray self , PSlice slice ,
592
597
@ Cached ConditionProfile simpleStepProfile ,
593
598
@ Cached SliceLiteralNode .SliceUnpack sliceUnpack ,
594
599
@ Cached SliceLiteralNode .AdjustIndices adjustIndices ) {
600
+ self .checkCanResize (this );
595
601
int length = self .getLength ();
596
602
PSlice .SliceInfo sliceInfo = adjustIndices .execute (length , sliceUnpack .execute (slice ));
597
603
int start = sliceInfo .start ;
@@ -713,6 +719,7 @@ Object append(VirtualFrame frame, PArray self, Object value,
713
719
try {
714
720
int index = self .getLength ();
715
721
int newLength = PythonUtils .addExact (index , 1 );
722
+ self .checkCanResize (this );
716
723
self .resize (newLength );
717
724
putValueNode .execute (frame , self , index , value );
718
725
return PNone .NONE ;
@@ -730,6 +737,9 @@ abstract static class ExtendNode extends PythonBinaryBuiltinNode {
730
737
Object extend (PArray self , PArray value ) {
731
738
try {
732
739
int newLength = PythonUtils .addExact (self .getLength (), value .getLength ());
740
+ if (newLength != self .getLength ()) {
741
+ self .checkCanResize (this );
742
+ }
733
743
int itemsize = self .getFormat ().bytesize ;
734
744
self .resizeStorage (newLength );
735
745
PythonUtils .arraycopy (value .getBuffer (), 0 , self .getBuffer (), self .getLength () * itemsize , value .getLength () * itemsize );
@@ -750,7 +760,11 @@ Object extend(VirtualFrame frame, PArray self, PSequence value,
750
760
SequenceStorage storage = getSequenceStorageNode .execute (value );
751
761
int storageLength = lenNode .execute (storage );
752
762
try {
753
- self .resizeStorage (PythonUtils .addExact (self .getLength (), storageLength ));
763
+ int newLength = PythonUtils .addExact (self .getLength (), storageLength );
764
+ if (newLength != self .getLength ()) {
765
+ self .checkCanResize (this );
766
+ }
767
+ self .resizeStorage (newLength );
754
768
} catch (OverflowException e ) {
755
769
CompilerDirectives .transferToInterpreterAndInvalidate ();
756
770
throw raise (MemoryError );
@@ -786,6 +800,7 @@ Object extend(VirtualFrame frame, PArray self, Object value,
786
800
// in CPython
787
801
try {
788
802
length = PythonUtils .addExact (length , 1 );
803
+ self .checkCanResize (this );
789
804
self .resizeStorage (length );
790
805
} catch (OverflowException e ) {
791
806
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -825,6 +840,7 @@ Object insert(VirtualFrame frame, PArray self, int inputIndex, Object value,
825
840
// Need to check the validity of the value before moving the memory around to ensure the
826
841
// operation can fail atomically
827
842
checkValueNode .execute (frame , self , value );
843
+ self .checkCanResize (this );
828
844
try {
829
845
self .shift (index , 1 );
830
846
} catch (OverflowException e ) {
@@ -851,6 +867,7 @@ Object remove(VirtualFrame frame, PArray self, Object value,
851
867
for (int i = 0 ; i < self .getLength (); i ++) {
852
868
Object item = getValueNode .execute (self , i );
853
869
if (lib .equalsWithFrame (item , value , lib , frame )) {
870
+ self .checkCanResize (this );
854
871
self .delSlice (i , 1 );
855
872
return PNone .NONE ;
856
873
}
@@ -872,6 +889,7 @@ Object pop(PArray self, int inputIndex,
872
889
}
873
890
int index = normalizeIndexNode .execute (inputIndex , self .getLength ());
874
891
Object value = getValueNode .execute (self , index );
892
+ self .checkCanResize (this );
875
893
self .delSlice (index , 1 );
876
894
return value ;
877
895
}
@@ -898,6 +916,7 @@ Object frombytes(PArray self, Object buffer,
898
916
}
899
917
int newLength = PythonUtils .addExact (oldSize , bufferLength / itemsize );
900
918
byte [] bufferBytes = lib .getBufferBytes (buffer );
919
+ self .checkCanResize (this );
901
920
self .resize (newLength );
902
921
PythonUtils .arraycopy (bufferBytes , 0 , self .getBuffer (), oldSize * itemsize , bufferLength );
903
922
} catch (UnsupportedMessageException e ) {
@@ -965,6 +984,7 @@ Object fromlist(VirtualFrame frame, PArray self, PList list,
965
984
SequenceStorage storage = getSequenceStorageNode .execute (list );
966
985
int length = lenNode .execute (storage );
967
986
int newLength = PythonUtils .addExact (self .getLength (), length );
987
+ self .checkCanResize (this );
968
988
self .resizeStorage (newLength );
969
989
for (int i = 0 ; i < length ; i ++) {
970
990
putValueNode .execute (frame , self , self .getLength () + i , getItemScalarNode .execute (storage , i ));
@@ -1017,6 +1037,7 @@ Object fromunicode(VirtualFrame frame, PArray self, String str,
1017
1037
try {
1018
1038
int length = PString .codePointCount (str , 0 , str .length ());
1019
1039
int newLength = PythonUtils .addExact (self .getLength (), length );
1040
+ self .checkCanResize (this );
1020
1041
self .resizeStorage (newLength );
1021
1042
for (int i = 0 , index = 0 ; i < length ; index ++) {
1022
1043
int cpCount = PString .charCount (PString .codePointAt (str , i ));
0 commit comments