mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.
mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998.
This commit is contained in:
@@ -305,12 +305,12 @@ mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg,
|
||||
return o;
|
||||
}
|
||||
|
||||
mp_int_t mp_obj_int_get(mp_const_obj_t self_in) {
|
||||
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in) {
|
||||
if (MP_OBJ_IS_SMALL_INT(self_in)) {
|
||||
return MP_OBJ_SMALL_INT_VALUE(self_in);
|
||||
} else {
|
||||
const mp_obj_int_t *self = self_in;
|
||||
// TODO this is a hack until we remove mp_obj_int_get function entirely
|
||||
// hash returns actual int value if it fits in mp_int_t
|
||||
return mpz_hash(&self->mpz);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user