py: Add mp_obj_get_int_truncated and use it where appropriate.
mp_obj_get_int_truncated will raise a TypeError if the argument is not
an integral type. Use mp_obj_int_get_truncated only when you know the
argument is a small or big int.
diff --git a/py/obj.c b/py/obj.c
index 2b5585b..555a4a8 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -231,6 +231,14 @@
}
}
+mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg) {
+ if (MP_OBJ_IS_INT(arg)) {
+ return mp_obj_int_get_truncated(arg);
+ } else {
+ return mp_obj_get_int(arg);
+ }
+}
+
// returns false if arg is not of integral type
// returns true and sets *value if it is of integral type
// can throw OverflowError if arg is of integral type, but doesn't fit in a mp_int_t