Skip to content

Commit 3786d9b

Browse files
committed
Fix regressions
1 parent 1a98b1d commit 3786d9b

File tree

11 files changed

+78
-61
lines changed

11 files changed

+78
-61
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIONodes.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@
6161
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
6262
import com.oracle.graal.python.builtins.modules.ThreadModuleBuiltins;
6363
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
64-
import com.oracle.graal.python.lib.PyLongAsLongNode;
64+
import com.oracle.graal.python.lib.PyNumberIndexNode;
6565
import com.oracle.graal.python.nodes.PGuards;
6666
import com.oracle.graal.python.nodes.PNodeWithContext;
6767
import com.oracle.graal.python.nodes.PNodeWithRaise;
6868
import com.oracle.graal.python.nodes.PRaiseNode;
6969
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
7070
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
71+
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
7172
import com.oracle.graal.python.runtime.GilNode;
7273
import com.oracle.graal.python.runtime.PythonContext;
7374
import com.oracle.graal.python.runtime.exception.PException;
@@ -218,10 +219,11 @@ static long doInt(long number, @SuppressWarnings("unused") PythonBuiltinClassTyp
218219
@Specialization
219220
static long toLong(VirtualFrame frame, Object number, PythonBuiltinClassType err,
220221
@Cached PRaiseNode raiseNode,
221-
@Cached PyLongAsLongNode asLongNode,
222+
@Cached PyNumberIndexNode indexNode,
223+
@Cached CastToJavaLongExactNode cast,
222224
@Cached IsBuiltinClassProfile errorProfile) {
223225
try {
224-
return asLongNode.execute(frame, number);
226+
return cast.execute(indexNode.execute(frame, number));
225227
} catch (PException e) {
226228
e.expect(OverflowError, errorProfile);
227229
throw raiseNode.raise(err, CANNOT_FIT_P_IN_OFFSET_SIZE, number);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/FileIOBuiltins.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
import com.oracle.graal.python.builtins.objects.exception.OSErrorEnum;
117117
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
118118
import com.oracle.graal.python.lib.PyIndexCheckNode;
119-
import com.oracle.graal.python.lib.PyLongAsLongNode;
120119
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
121120
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
122121
import com.oracle.graal.python.nodes.PNodeWithRaise;
@@ -659,8 +658,9 @@ Object closedError(@SuppressWarnings("unused") PFileIO self, @SuppressWarnings("
659658
}
660659
}
661660

662-
@Builtin(name = SEEK, minNumOfPositionalArgs = 2, parameterNames = {"$self", "$pos", "whence"})
661+
@Builtin(name = SEEK, minNumOfPositionalArgs = 2, numOfPositionalOnlyArgs = 2, parameterNames = {"$self", "pos", "whence"})
663662
@ArgumentClinic(name = "whence", conversion = ArgumentClinic.ClinicConversion.Int, defaultValue = "BufferedIOUtil.SEEK_SET", useDefaultForNone = true)
663+
@ArgumentClinic(name = "pos", conversion = ArgumentClinic.ClinicConversion.Long)
664664
@GenerateNodeFactory
665665
abstract static class SeekNode extends PythonTernaryClinicBuiltinNode {
666666
@Override
@@ -669,11 +669,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
669669
}
670670

671671
@Specialization(guards = "!self.isClosed()")
672-
Object seek(VirtualFrame frame, PFileIO self, Object posobj, int whence,
673-
@Cached PyLongAsLongNode asLongNode,
672+
Object seek(VirtualFrame frame, PFileIO self, long pos, int whence,
674673
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
675674
@Cached BranchProfile exceptionProfile) {
676-
long pos = asLongNode.execute(frame, posobj);
677675
try {
678676
return internalSeek(self, pos, whence, getPosixSupport(), posixLib);
679677
} catch (PosixSupportLibrary.PosixException e) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMADecompressorBuiltins.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.EOFError;
4444
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
45+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
4546
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.ValueError;
4647
import static com.oracle.graal.python.builtins.modules.lzma.LZMAModuleBuiltins.CHECK_NONE;
4748
import static com.oracle.graal.python.builtins.modules.lzma.LZMAModuleBuiltins.CHECK_UNKNOWN;
@@ -62,7 +63,6 @@
6263
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
6364
import com.oracle.graal.python.builtins.PythonBuiltins;
6465
import com.oracle.graal.python.builtins.modules.lzma.LZMAObject.LZMADecompressor;
65-
import com.oracle.graal.python.builtins.modules.zlib.ZLibModuleBuiltins;
6666
import com.oracle.graal.python.builtins.objects.PNone;
6767
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
6868
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
@@ -76,6 +76,8 @@
7676
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
7777
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
7878
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
79+
import com.oracle.graal.python.nodes.util.CannotCastException;
80+
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
7981
import com.oracle.graal.python.runtime.PythonContext;
8082
import com.oracle.truffle.api.dsl.Cached;
8183
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -98,7 +100,6 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
98100
@ImportStatic(PGuards.class)
99101
@Builtin(name = __INIT__, minNumOfPositionalArgs = 1, parameterNames = {"$self", "format", "memlimit", "filters"})
100102
@ArgumentClinic(name = "format", conversion = ArgumentClinic.ClinicConversion.Int, defaultValue = "LZMAModuleBuiltins.FORMAT_AUTO", useDefaultForNone = true)
101-
@ArgumentClinic(name = "memlimit", conversionClass = ZLibModuleBuiltins.ExpectIntNode.class, defaultValue = "PNone.NO_VALUE")
102103
@GenerateNodeFactory
103104
@TypeSystemReference(PythonArithmeticTypes.class)
104105
public abstract static class InitNode extends PythonQuaternaryClinicBuiltinNode {
@@ -108,22 +109,34 @@ protected ArgumentClinicProvider getArgumentClinic() {
108109
return LZMADecompressorBuiltinsClinicProviders.InitNodeClinicProviderGen.INSTANCE;
109110
}
110111

112+
@Specialization(guards = {"!isRaw(format)", "validFormat(format)", "!isPNone(memlimitObj)"})
113+
PNone notRaw(VirtualFrame frame, LZMADecompressor self, int format, Object memlimitObj, @SuppressWarnings("unused") PNone filters,
114+
@Cached CastToJavaIntExactNode cast,
115+
@Shared("d") @Cached LZMANodes.LZMADecompressInit decompressInit) {
116+
int memlimit;
117+
try {
118+
memlimit = cast.execute(memlimitObj);
119+
} catch (CannotCastException e) {
120+
throw raise(TypeError, ErrorMessages.INTEGER_REQUIRED);
121+
}
122+
return doNotRaw(frame, self, format, memlimit, decompressInit);
123+
124+
}
125+
111126
@Specialization(guards = {"!isRaw(format)", "validFormat(format)"})
112-
PNone notRaw(VirtualFrame frame, LZMADecompressor self, int format, int memlimit, @SuppressWarnings("unused") PNone filters,
127+
PNone notRaw(VirtualFrame frame, LZMADecompressor self, int format, @SuppressWarnings("unused") PNone memlimit, @SuppressWarnings("unused") PNone filters,
113128
@Shared("d") @Cached LZMANodes.LZMADecompressInit decompressInit) {
129+
return doNotRaw(frame, self, format, Integer.MAX_VALUE, decompressInit);
130+
}
131+
132+
private static PNone doNotRaw(VirtualFrame frame, LZMADecompressor self, int format, int memlimit, LZMANodes.LZMADecompressInit decompressInit) {
114133
self.setCheck(format == FORMAT_ALONE ? CHECK_NONE : CHECK_UNKNOWN);
115134
self.setFormat(format);
116135
self.setMemlimit(memlimit);
117136
decompressInit.execute(frame, self, format, memlimit);
118137
return PNone.NONE;
119138
}
120139

121-
@Specialization(guards = {"!isRaw(format)", "validFormat(format)"})
122-
PNone notRaw(VirtualFrame frame, LZMADecompressor self, int format, @SuppressWarnings("unused") PNone memlimit, PNone filters,
123-
@Shared("d") @Cached LZMANodes.LZMADecompressInit decompressInit) {
124-
return notRaw(frame, self, format, Integer.MAX_VALUE, filters, decompressInit);
125-
}
126-
127140
@SuppressWarnings("unused")
128141
@Specialization(guards = {"isRaw(format)", "!isPNone(filters)"})
129142
PNone raw(VirtualFrame frame, LZMADecompressor self, int format, PNone memlimit, Object filters,
@@ -135,8 +148,8 @@ PNone raw(VirtualFrame frame, LZMADecompressor self, int format, PNone memlimit,
135148
}
136149

137150
@SuppressWarnings("unused")
138-
@Specialization(guards = "isRaw(format)")
139-
PNone rawError(LZMADecompressor self, int format, int memlimit, Object filters) {
151+
@Specialization(guards = {"isRaw(format)", "!isPNone(memlimit)"})
152+
PNone rawError(LZMADecompressor self, int format, Object memlimit, Object filters) {
140153
throw raise(ValueError, ErrorMessages.CANNOT_SPECIFY_MEM_LIMIT);
141154
}
142155

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,30 @@ public abstract static class RemoveNode extends PythonBinaryBuiltinNode {
411411

412412
@Specialization
413413
PNone remove(VirtualFrame frame, PByteArray self, Object value,
414+
@Cached("createCast()") CastToByteNode cast,
415+
@Cached SequenceStorageNodes.GetInternalByteArrayNode getBytes,
414416
@Cached BytesNodes.FindNode findNode,
415417
@Cached SequenceStorageNodes.DeleteNode deleteNode,
416418
@Cached SequenceStorageNodes.LenNode lenNode) {
417419
self.checkCanResize(this);
418420
SequenceStorage storage = self.getSequenceStorage();
419421
int len = lenNode.execute(storage);
420-
int pos = findNode.execute(self.getSequenceStorage(), len, value, 0, len);
422+
int pos = findNode.execute(getBytes.execute(self.getSequenceStorage()), len, cast.execute(frame, value), 0, len);
421423
if (pos != -1) {
422424
deleteNode.execute(frame, storage, pos);
423425
return PNone.NONE;
424426
}
425427
throw raise(ValueError, NOT_IN_BYTEARRAY);
426428
}
427429

430+
protected CastToByteNode createCast() {
431+
return CastToByteNode.create(val -> {
432+
throw raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
433+
}, val -> {
434+
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
435+
});
436+
}
437+
428438
@Fallback
429439
public Object doError(@SuppressWarnings("unused") Object self, Object arg) {
430440
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, arg);
@@ -505,9 +515,9 @@ public PNone append(VirtualFrame frame, PByteArray byteArray, Object arg,
505515

506516
protected CastToByteNode createCast() {
507517
return CastToByteNode.create(val -> {
508-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
509-
}, val -> {
510518
throw raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
519+
}, val -> {
520+
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
511521
});
512522
}
513523
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import static com.oracle.graal.python.nodes.ErrorMessages.READ_WRITE_BYTELIKE_OBJ;
5252
import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
5353
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
54-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
5554

5655
import java.util.ArrayList;
5756
import java.util.Arrays;
@@ -256,7 +255,11 @@ public static ToBytesNode create(PythonBuiltinClassType errorType, String errorM
256255

257256
public abstract static class FindNode extends PNodeWithRaise {
258257

259-
public abstract int execute(Object self, int len1, Object sub, int start, int end);
258+
public abstract int execute(byte[] self, int len1, byte[] sub, int start, int end);
259+
260+
public abstract int execute(byte[] self, int len1, byte sub, int start, int end);
261+
262+
public abstract int execute(SequenceStorage self, int len1, Object sub, int start, int end);
260263

261264
@Specialization
262265
int find(byte[] haystack, int len1, byte needle, int start, int end,
@@ -766,7 +769,7 @@ public static byte[] bytearray(VirtualFrame frame, Object iterable, int len,
766769
@SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheckNode,
767770
@Cached GetNextNode getNextNode,
768771
@Cached IsBuiltinClassProfile stopIterationProfile,
769-
@Cached("createCast()") CastToByteNode castToByteNode,
772+
@Cached CastToByteNode castToByteNode,
770773
@CachedLibrary(limit = "3") PythonObjectLibrary lib) {
771774
Object it = lib.getIteratorWithFrame(iterable, frame);
772775
byte[] arr = new byte[len < 16 && len > 0 ? len : 16];
@@ -795,14 +798,6 @@ public static IterableToByteNode create(Function<Object, Object> typeErrorHandle
795798
return IterableToByteNodeGen.create(typeErrorHandler);
796799
}
797800

798-
protected CastToByteNode createCast() {
799-
return CastToByteNode.create(val -> {
800-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "bytes");
801-
}, val -> {
802-
throw raise(ValueError, ErrorMessages.BYTE_MUST_BE_IN_RANGE);
803-
});
804-
}
805-
806801
@TruffleBoundary(transferToInterpreterOnException = false)
807802
private static byte[] resize(byte[] arr, int len) {
808803
return Arrays.copyOf(arr, len);

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@
5555
import com.oracle.graal.python.builtins.objects.str.PString;
5656
import com.oracle.graal.python.builtins.objects.str.StringNodes;
5757
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
58-
import com.oracle.graal.python.lib.PyLongAsLongNode;
58+
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
5959
import com.oracle.graal.python.lib.PyNumberIndexNode;
6060
import com.oracle.graal.python.nodes.ErrorMessages;
6161
import com.oracle.graal.python.nodes.PGuards;
6262
import com.oracle.graal.python.nodes.PRaiseNode;
63+
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
6364
import com.oracle.graal.python.nodes.util.CastToJavaUnsignedLongNode;
6465
import com.oracle.graal.python.runtime.exception.PException;
6566
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
@@ -185,8 +186,8 @@ void packUnsignedByteInt(@SuppressWarnings("unused") BufferFormat format, int va
185186

186187
@Specialization(guards = "format == UINT_8", replaces = "packUnsignedByteInt")
187188
void packUnsignedByteGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
188-
@Cached PyLongAsLongNode asLongNode) {
189-
long value = asLongNode.execute(frame, object);
189+
@Cached PyNumberAsSizeNode asSizeNode) {
190+
int value = asSizeNode.executeExact(frame, object);
190191
if (value < 0 || value > 0xFF) {
191192
throw raise(OverflowError);
192193
}
@@ -195,8 +196,8 @@ void packUnsignedByteGeneric(VirtualFrame frame, @SuppressWarnings("unused") Buf
195196

196197
@Specialization(guards = "format == INT_8", replaces = "packUnsignedByteInt")
197198
void packSignedByteGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
198-
@Cached PyLongAsLongNode asLongNode) {
199-
long value = asLongNode.execute(frame, object);
199+
@Cached PyNumberAsSizeNode asSizeNode) {
200+
int value = asSizeNode.executeExact(frame, object);
200201
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
201202
throw raise(OverflowError);
202203
}
@@ -205,8 +206,8 @@ void packSignedByteGeneric(VirtualFrame frame, @SuppressWarnings("unused") Buffe
205206

206207
@Specialization(guards = "format == INT_16")
207208
void packSignedShortGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
208-
@Cached PyLongAsLongNode asLongNode) {
209-
long value = asLongNode.execute(frame, object);
209+
@Cached PyNumberAsSizeNode asSizeNode) {
210+
int value = asSizeNode.executeExact(frame, object);
210211
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
211212
throw raise(OverflowError);
212213
}
@@ -215,8 +216,8 @@ void packSignedShortGeneric(VirtualFrame frame, @SuppressWarnings("unused") Buff
215216

216217
@Specialization(guards = "format == UINT_16")
217218
void packUnsignedShortGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
218-
@Cached PyLongAsLongNode asLongNode) {
219-
long value = asLongNode.execute(frame, object);
219+
@Cached PyNumberAsSizeNode asSizeNode) {
220+
int value = asSizeNode.executeExact(frame, object);
220221
if (value < 0 || value > (Short.MAX_VALUE << 1) + 1) {
221222
throw raise(OverflowError);
222223
}
@@ -230,18 +231,15 @@ static void packSignedIntInt(@SuppressWarnings("unused") BufferFormat format, in
230231

231232
@Specialization(guards = "format == INT_32", replaces = "packSignedIntInt")
232233
void packSignedIntGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
233-
@Cached PyLongAsLongNode asLongNode) {
234-
long value = asLongNode.execute(frame, object);
235-
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
236-
throw raise(OverflowError);
237-
}
238-
PythonUtils.arrayAccessor.putInt(bytes, offset, (int) value);
234+
@Cached PyNumberAsSizeNode asSizeNode) {
235+
PythonUtils.arrayAccessor.putInt(bytes, offset, asSizeNode.executeExact(frame, object));
239236
}
240237

241238
@Specialization(guards = "format == UINT_32", replaces = "packSignedIntInt")
242239
void packUnsignedIntGeneric(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
243-
@Cached PyLongAsLongNode asLongNode) {
244-
long value = asLongNode.execute(frame, object);
240+
@Cached PyNumberIndexNode indexNode,
241+
@Cached CastToJavaLongExactNode cast) {
242+
long value = cast.execute(indexNode.execute(frame, object));
245243
if (value < 0 || value > ((long) (Integer.MAX_VALUE) << 1L) + 1L) {
246244
throw raise(OverflowError);
247245
}
@@ -250,8 +248,9 @@ void packUnsignedIntGeneric(VirtualFrame frame, @SuppressWarnings("unused") Buff
250248

251249
@Specialization(guards = "format == INT_64")
252250
static void packSignedLong(VirtualFrame frame, @SuppressWarnings("unused") BufferFormat format, Object object, byte[] bytes, int offset,
253-
@Cached PyLongAsLongNode asLongNode) {
254-
PythonUtils.arrayAccessor.putLong(bytes, offset, asLongNode.execute(frame, object));
251+
@Cached PyNumberIndexNode indexNode,
252+
@Cached CastToJavaLongExactNode cast) {
253+
PythonUtils.arrayAccessor.putLong(bytes, offset, cast.execute(indexNode.execute(frame, object)));
255254
}
256255

257256
@Specialization(guards = "format == UINT_64")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,8 +2849,8 @@ static double doLong(long self) {
28492849
}
28502850

28512851
@Specialization
2852-
static double doPInt(PInt self) {
2853-
return self.doubleValue();
2852+
double doPInt(PInt self) {
2853+
return self.doubleValueWithOverflow(getRaiseNode());
28542854
}
28552855

28562856
@Fallback

0 commit comments

Comments
 (0)