diff options
author | Damien George <damien.p.george@gmail.com> | 2015-05-12 23:05:53 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-05-12 23:05:53 +0100 |
commit | c50772d19fe2804a6d0258f89dd9967d3b516fd3 (patch) | |
tree | 9db781cc50f27fd4d07f9ef1db9a862a29690d53 /py/obj.c | |
parent | c2a4e4effc81d8ab21bb014e34355643e5ca0da2 (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.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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 |