From d26b379eec155ddd7a4aa64057c3d0507eee79f5 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 18 Jan 2014 16:07:16 +0200 Subject: int: Add value accessors: mp_obj_int_get() & mp_obj_int_get_checked(). mp_obj_int_get() can be used when just full resolution of C machine_int_t is required (returns truncated value of long int). mp_obj_int_get_checked() will throw exception if Python int value not representable in machine_int_t. --- py/obj.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'py/obj.c') diff --git a/py/obj.c b/py/obj.c index 9ca3d5d16b..4fe287d992 100644 --- a/py/obj.c +++ b/py/obj.c @@ -155,6 +155,8 @@ machine_int_t mp_obj_get_int(mp_obj_t arg) { return 1; } else if (MP_OBJ_IS_SMALL_INT(arg)) { return MP_OBJ_SMALL_INT_VALUE(arg); + } else if (MP_OBJ_IS_TYPE(arg, &int_type)) { + return mp_obj_int_get_checked(arg); #if MICROPY_ENABLE_FLOAT } else if (MP_OBJ_IS_TYPE(arg, &float_type)) { // TODO work out if this should be floor, ceil or trunc -- cgit v1.2.3