mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 13:10:21 +01:00
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.
This commit is contained in:
@@ -120,9 +120,17 @@ mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
|
||||
return o;
|
||||
}
|
||||
|
||||
machine_int_t mp_obj_int_get_int(mp_obj_t self_in) {
|
||||
machine_int_t mp_obj_int_get(mp_obj_t self_in) {
|
||||
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||
}
|
||||
mp_obj_int_t *self = self_in;
|
||||
return self->val;
|
||||
}
|
||||
|
||||
machine_int_t mp_obj_int_get_checked(mp_obj_t self_in) {
|
||||
// TODO: Check overflow
|
||||
return mp_obj_int_get(self_in);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user