|
30 | 30 | import com.oracle.graal.python.nodes.call.CallNode;
|
31 | 31 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
32 | 32 | 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; |
33 | 35 | import com.oracle.graal.python.runtime.PythonCore;
|
34 | 36 | import com.oracle.graal.python.runtime.exception.PException;
|
35 | 37 | import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
|
36 |
| -import com.oracle.graal.python.util.OverflowException; |
37 | 38 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
38 | 39 |
|
39 | 40 | /**
|
@@ -130,27 +131,16 @@ Object getArg() {
|
130 | 131 | int getNumber() {
|
131 | 132 | char c = pop();
|
132 | 133 | if (c == '*') {
|
133 |
| - long value; |
134 | 134 | 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"); |
144 | 139 | }
|
145 |
| - } else if (o instanceof Boolean) { |
146 |
| - return (Boolean) o ? 1 : 0; |
147 |
| - } else { |
| 140 | + return (int) value; |
| 141 | + } catch (CannotCastException e) { |
148 | 142 | throw raiseNode.raise(TypeError, ErrorMessages.STAR_WANTS_INT);
|
149 | 143 | }
|
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; |
154 | 144 | } else {
|
155 | 145 | if (Character.isDigit(c)) {
|
156 | 146 | int numStart = index - 1;
|
|
0 commit comments