|
9 | 9 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__INDEX__;
|
10 | 10 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__INT__;
|
11 | 11 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
|
| 12 | +import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError; |
12 | 13 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
13 | 14 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
|
14 | 15 |
|
|
18 | 19 |
|
19 | 20 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
20 | 21 | import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
|
21 |
| -import com.oracle.graal.python.builtins.objects.floats.PFloat; |
22 | 22 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
23 | 23 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
24 | 24 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
|
32 | 32 | import com.oracle.graal.python.runtime.PythonCore;
|
33 | 33 | import com.oracle.graal.python.runtime.exception.PException;
|
34 | 34 | import com.oracle.graal.python.runtime.formatting.InternalFormat.Spec;
|
| 35 | +import com.oracle.graal.python.util.OverflowException; |
35 | 36 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
36 | 37 |
|
37 | 38 | /**
|
@@ -126,21 +127,25 @@ Object getArg() {
|
126 | 127 | int getNumber() {
|
127 | 128 | char c = pop();
|
128 | 129 | if (c == '*') {
|
| 130 | + long value; |
129 | 131 | Object o = getArg();
|
130 |
| - if (o instanceof Long) { |
131 |
| - return ((Long) o).intValue(); |
132 |
| - } else if (o instanceof Integer) { |
| 132 | + if (o instanceof Integer) { |
133 | 133 | return (int) o;
|
| 134 | + } else if (o instanceof Long) { |
| 135 | + value = (long) o; |
134 | 136 | } else if (o instanceof PInt) {
|
135 |
| - return ((PInt) o).intValue(); |
136 |
| - } else if (o instanceof Double) { |
137 |
| - return ((Double) o).intValue(); |
138 |
| - } else if (o instanceof Boolean) { |
139 |
| - return (Boolean) o ? 1 : 0; |
140 |
| - } else if (o instanceof PFloat) { |
141 |
| - return (int) ((PFloat) o).getValue(); |
| 137 | + try { |
| 138 | + return ((PInt) o).intValueExact(); |
| 139 | + } catch (OverflowException e) { |
| 140 | + value = Long.MAX_VALUE; |
| 141 | + } |
| 142 | + } else { |
| 143 | + throw core.raise(TypeError, ErrorMessages.STAR_WANTS_INT); |
| 144 | + } |
| 145 | + if (value > Integer.MAX_VALUE) { |
| 146 | + throw core.raise(OverflowError, ErrorMessages.PYTHON_INT_TOO_LARGE_TO_CONV_TO, "size"); |
142 | 147 | }
|
143 |
| - throw core.raise(TypeError, ErrorMessages.STAR_WANTS_INT); |
| 148 | + return (int) value; |
144 | 149 | } else {
|
145 | 150 | if (Character.isDigit(c)) {
|
146 | 151 | int numStart = index - 1;
|
|
0 commit comments