Skip to content

Commit d5a6547

Browse files
committed
Use exact conversion in PInt.asJavaLong
1 parent 469090a commit d5a6547

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
4444
import com.oracle.graal.python.nodes.util.CastToJavaDoubleNode;
4545
import com.oracle.graal.python.nodes.util.CastToJavaIntExactNode;
46-
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
46+
import com.oracle.graal.python.nodes.util.CastToJavaLongExactNode;
4747
import com.oracle.graal.python.runtime.PythonContext;
4848
import com.oracle.graal.python.runtime.exception.PException;
4949
import com.oracle.graal.python.util.OverflowException;
@@ -277,7 +277,7 @@ public boolean canBeJavaLong() {
277277

278278
@ExportMessage
279279
public long asJavaLongWithState(@SuppressWarnings("unused") ThreadState threadState,
280-
@Cached CastToJavaLongLossyNode castToLong) {
280+
@Cached CastToJavaLongExactNode castToLong) {
281281
return castToLong.execute(this);
282282
}
283283

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/builtins/clinic/JavaIntConversionNode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5151
import com.oracle.graal.python.nodes.ErrorMessages;
5252
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
53+
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
54+
import com.oracle.graal.python.runtime.exception.PException;
5355
import com.oracle.truffle.api.dsl.Cached;
5456
import com.oracle.truffle.api.dsl.Specialization;
5557
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -65,12 +67,19 @@ protected JavaIntConversionNode(int defaultValue, boolean useDefaultForNone) {
6567
int doOthers(VirtualFrame frame, Object value,
6668
@Cached IsSubtypeNode isSubtypeNode,
6769
@Cached BranchProfile isFloatProfile,
70+
@Cached IsBuiltinClassProfile exceptionProfle,
6871
@CachedLibrary("value") PythonObjectLibrary lib) {
6972
if (isSubtypeNode.execute(lib.getLazyPythonClass(value), PythonBuiltinClassType.PFloat)) {
7073
isFloatProfile.enter();
7174
throw raise(TypeError, ErrorMessages.INTEGER_EXPECTED_GOT_FLOAT);
7275
}
73-
long result = lib.asJavaLong(value, frame);
76+
long result;
77+
try {
78+
result = lib.asJavaLong(value, frame);
79+
} catch (PException e) {
80+
e.expect(TypeError, exceptionProfle);
81+
throw raise(TypeError, ErrorMessages.VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
82+
}
7483
if (!fitsInInt(result)) {
7584
throw raise(TypeError, ErrorMessages.VALUE_TOO_LARGE_TO_FIT_INTO_INDEX);
7685
}

0 commit comments

Comments
 (0)