summaryrefslogtreecommitdiff
path: root/py/obj.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-05-12 23:05:53 +0100
committerDamien George <damien.p.george@gmail.com>2015-05-12 23:05:53 +0100
commitc50772d19fe2804a6d0258f89dd9967d3b516fd3 (patch)
tree9db781cc50f27fd4d07f9ef1db9a862a29690d53 /py/obj.c
parentc2a4e4effc81d8ab21bb014e34355643e5ca0da2 (diff)
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.
Diffstat (limited to 'py/obj.c')
-rw-r--r--py/obj.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/py/obj.c b/py/obj.c
index 2b5585be4..555a4a8b9 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -231,6 +231,14 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
}
}
+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