Skip to content

Commit 5c0f38e

Browse files
committed
Use CastToJavaLongLossyNode
1 parent 57bae88 commit 5c0f38e

File tree

1 file changed

+8
-18
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting

1 file changed

+8
-18
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
import com.oracle.graal.python.nodes.call.CallNode;
3131
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
3232
import com.oracle.graal.python.nodes.classes.IsSubtypeNodeGen;
33+
import com.oracle.graal.python.nodes.util.CannotCastException;
34+
import com.oracle.graal.python.nodes.util.CastToJavaLongLossyNode;
3335
import com.oracle.graal.python.runtime.PythonCore;
3436
import com.oracle.graal.python.runtime.exception.PException;
3537
import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
36-
import com.oracle.graal.python.util.OverflowException;
3738
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3839

3940
/**
@@ -130,27 +131,16 @@ Object getArg() {
130131
int getNumber() {
131132
char c = pop();
132133
if (c == '*') {
133-
long value;
134134
Object o = getArg();
135-
if (o instanceof Integer) {
136-
return (int) o;
137-
} else if (o instanceof Long) {
138-
value = (long) o;
139-
} else if (o instanceof PInt) {
140-
try {
141-
return ((PInt) o).intValueExact();
142-
} catch (OverflowException e) {
143-
value = Long.MAX_VALUE;
135+
try {
136+
long value = CastToJavaLongLossyNode.getUncached().execute(o);
137+
if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
138+
throw raiseNode.raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "size");
144139
}
145-
} else if (o instanceof Boolean) {
146-
return (Boolean) o ? 1 : 0;
147-
} else {
140+
return (int) value;
141+
} catch (CannotCastException e) {
148142
throw raiseNode.raise(TypeError, ErrorMessages.STAR_WANTS_INT);
149143
}
150-
if (value > Integer.MAX_VALUE) {
151-
throw raiseNode.raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "size");
152-
}
153-
return (int) value;
154144
} else {
155145
if (Character.isDigit(c)) {
156146
int numStart = index - 1;

0 commit comments

Comments
 (0)