diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-18 16:07:16 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-01-18 16:12:12 +0200 |
commit | d26b379eec155ddd7a4aa64057c3d0507eee79f5 (patch) | |
tree | 33bc4d1857cf37f6150ad473fefdcc3354607b49 /py/objint.c | |
parent | 166bb40fb22b9c43209ce9792b6a8d48276ef7fa (diff) | |
download | micropython-d26b379eec155ddd7a4aa64057c3d0507eee79f5.tar.gz micropython-d26b379eec155ddd7a4aa64057c3d0507eee79f5.zip |
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.
Diffstat (limited to 'py/objint.c')
-rw-r--r-- | py/objint.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/py/objint.c b/py/objint.c index 59181eaf6d..905944d372 100644 --- a/py/objint.c +++ b/py/objint.c @@ -77,4 +77,13 @@ mp_obj_t mp_obj_new_int(machine_int_t value) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_OverflowError, "small int overflow")); return mp_const_none; } + +machine_int_t mp_obj_int_get(mp_obj_t self_in) { + return MP_OBJ_SMALL_INT_VALUE(self_in); +} + +machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) { + return MP_OBJ_SMALL_INT_VALUE(self_in); +} + #endif |