@@ -98,19 +98,23 @@ public abstract static class MMapNode extends PythonBuiltinNode {
98
98
private final BranchProfile invalidLengthProfile = BranchProfile .create ();
99
99
100
100
@ 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 ,
102
102
@ SuppressWarnings ("unused" ) PNone offset ) {
103
103
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 );
105
109
}
106
110
107
111
@ 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 ) {
109
113
return doFile (clazz , fd , length , tagname , ACCESS_DEFAULT , 0 );
110
114
}
111
115
112
116
@ 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 ) {
114
118
return doFile (clazz , fd , length , tagname , access , 0 );
115
119
}
116
120
@@ -200,30 +204,36 @@ public AnonymousMap(int cap) {
200
204
this .data = new byte [cap ];
201
205
}
202
206
207
+ @ Override
203
208
public boolean isOpen () {
204
209
return open ;
205
210
}
206
211
212
+ @ Override
207
213
public void close () throws IOException {
208
214
open = false ;
209
215
}
210
216
217
+ @ Override
211
218
public int read (ByteBuffer dst ) throws IOException {
212
219
int nread = Math .min (dst .remaining (), data .length - cur );
213
220
dst .put (data , cur , nread );
214
221
return nread ;
215
222
}
216
223
224
+ @ Override
217
225
public int write (ByteBuffer src ) throws IOException {
218
226
int nwrite = Math .min (src .remaining (), data .length - cur );
219
227
src .get (data , cur , nwrite );
220
228
return nwrite ;
221
229
}
222
230
231
+ @ Override
223
232
public long position () throws IOException {
224
233
return cur ;
225
234
}
226
235
236
+ @ Override
227
237
public SeekableByteChannel position (long newPosition ) throws IOException {
228
238
if (newPosition < 0 ) {
229
239
throw new IllegalArgumentException ();
@@ -232,10 +242,12 @@ public SeekableByteChannel position(long newPosition) throws IOException {
232
242
return this ;
233
243
}
234
244
245
+ @ Override
235
246
public long size () throws IOException {
236
247
return data .length ;
237
248
}
238
249
250
+ @ Override
239
251
public SeekableByteChannel truncate (long size ) throws IOException {
240
252
for (int i = 0 ; i < size ; i ++) {
241
253
data [i ] = 0 ;
0 commit comments