@@ -98,19 +98,23 @@ public abstract static class MMapNode extends PythonBuiltinNode {
9898 private final BranchProfile invalidLengthProfile = BranchProfile .create ();
9999
100100 @ Specialization (guards = {"isAnonymous(fd)" , "isNoValue(access)" , "isNoValue(offset)" })
101- PMMap doAnonymous (Object clazz , @ SuppressWarnings ("unused" ) long fd , int length , @ SuppressWarnings ("unused" ) Object tagname , @ SuppressWarnings ("unused" ) PNone access ,
101+ PMMap doAnonymous (Object clazz , @ SuppressWarnings ("unused" ) long fd , long length , @ SuppressWarnings ("unused" ) Object tagname , @ SuppressWarnings ("unused" ) PNone access ,
102102 @ SuppressWarnings ("unused" ) PNone offset ) {
103103 checkLength (length );
104- return factory ().createMMap (clazz , new AnonymousMap (length ), length , 0 );
104+ if (length > Integer .MAX_VALUE ) {
105+ invalidLengthProfile .enter ();
106+ throw raise (PythonBuiltinClassType .OverflowError , ErrorMessages .PYTHON_INT_TOO_LARGE_TO_CONV_TO , "int" );
107+ }
108+ return factory ().createMMap (clazz , new AnonymousMap ((int ) length ), length , 0 );
105109 }
106110
107111 @ Specialization (guards = {"fd >= 0" , "isNoValue(access)" , "isNoValue(offset)" })
108- PMMap doFile (Object clazz , long fd , int length , Object tagname , @ SuppressWarnings ("unused" ) PNone access , @ SuppressWarnings ("unused" ) PNone offset ) {
112+ PMMap doFile (Object clazz , long fd , long length , Object tagname , @ SuppressWarnings ("unused" ) PNone access , @ SuppressWarnings ("unused" ) PNone offset ) {
109113 return doFile (clazz , fd , length , tagname , ACCESS_DEFAULT , 0 );
110114 }
111115
112116 @ Specialization (guards = {"fd >= 0" , "isNoValue(offset)" })
113- PMMap doFile (Object clazz , long fd , int length , Object tagname , int access , @ SuppressWarnings ("unused" ) PNone offset ) {
117+ PMMap doFile (Object clazz , long fd , long length , Object tagname , int access , @ SuppressWarnings ("unused" ) PNone offset ) {
114118 return doFile (clazz , fd , length , tagname , access , 0 );
115119 }
116120
@@ -200,30 +204,36 @@ public AnonymousMap(int cap) {
200204 this .data = new byte [cap ];
201205 }
202206
207+ @ Override
203208 public boolean isOpen () {
204209 return open ;
205210 }
206211
212+ @ Override
207213 public void close () throws IOException {
208214 open = false ;
209215 }
210216
217+ @ Override
211218 public int read (ByteBuffer dst ) throws IOException {
212219 int nread = Math .min (dst .remaining (), data .length - cur );
213220 dst .put (data , cur , nread );
214221 return nread ;
215222 }
216223
224+ @ Override
217225 public int write (ByteBuffer src ) throws IOException {
218226 int nwrite = Math .min (src .remaining (), data .length - cur );
219227 src .get (data , cur , nwrite );
220228 return nwrite ;
221229 }
222230
231+ @ Override
223232 public long position () throws IOException {
224233 return cur ;
225234 }
226235
236+ @ Override
227237 public SeekableByteChannel position (long newPosition ) throws IOException {
228238 if (newPosition < 0 ) {
229239 throw new IllegalArgumentException ();
@@ -232,10 +242,12 @@ public SeekableByteChannel position(long newPosition) throws IOException {
232242 return this ;
233243 }
234244
245+ @ Override
235246 public long size () throws IOException {
236247 return data .length ;
237248 }
238249
250+ @ Override
239251 public SeekableByteChannel truncate (long size ) throws IOException {
240252 for (int i = 0 ; i < size ; i ++) {
241253 data [i ] = 0 ;
0 commit comments