Skip to content

Commit 7da931a

Browse files
committed
Fix slow path fallbacks in MMap module and CExtParseArgumentsNode
1 parent b64c096 commit 7da931a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MMapModuleBuiltins.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/common/CExtParseArgumentsNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,13 @@ static Object doNoKeywords(ParserState state, Object kwds, Object kwdnames, bool
10351035
return out;
10361036
}
10371037

1038-
@Specialization(replaces = "doNoKeywords", limit = "1")
1038+
@Specialization(replaces = "doNoKeywords")
10391039
static Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean keywordsOnly,
10401040
@Shared("lenNode") @Cached SequenceNodes.LenNode lenNode,
10411041
@Shared("getSequenceStorageNode") @Cached GetSequenceStorageNode getSequenceStorageNode,
10421042
@Shared("getItemNode") @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
10431043
@Cached HashingCollectionNodes.GetDictStorageNode getDictStorageNode,
1044-
@CachedLibrary("kwdnames") InteropLibrary kwdnamesLib,
1044+
@CachedLibrary(limit = "1") InteropLibrary kwdnamesLib,
10451045
@CachedLibrary(limit = "1") HashingStorageLibrary lib,
10461046
@Cached PCallCExtFunction callCStringToString) throws InteropException {
10471047

0 commit comments

Comments
 (0)