Skip to content

Commit c2c4bb0

Browse files
committed
provide a default impl of asSizeWithState
1 parent 3acab65 commit c2c4bb0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObjectLibrary.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
4848
import com.oracle.graal.python.nodes.IndirectCallNode;
4949
import com.oracle.graal.python.nodes.PRaiseNode;
50+
import com.oracle.graal.python.nodes.util.CastToJavaLongNode;
5051
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
5152
import com.oracle.graal.python.runtime.PythonContext;
5253
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
@@ -262,8 +263,16 @@ public Object asIndex(Object receiver) {
262263
*/
263264
public int asSizeWithState(Object receiver, LazyPythonClass errorType, ThreadState threadState) {
264265
if (threadState == null) {
265-
asIndexWithState(receiver, threadState);
266-
assert false : "should not reach here";
266+
// this will very likely always raise an integer interpretation error in asIndexWithState
267+
long result = CastToJavaLongNode.getUncached().execute(asIndexWithState(receiver, null));
268+
int intResult = (int) result;
269+
if (intResult == result) {
270+
return intResult;
271+
} else if (errorType == null) {
272+
return result < 0 ? Integer.MIN_VALUE : Integer.MAX_VALUE;
273+
} else {
274+
throw PRaiseNode.getUncached().raiseNumberTooLarge(errorType, result);
275+
}
267276
}
268277
return asSize(receiver, errorType);
269278
}

0 commit comments

Comments
 (0)