py: Rename mp_builtin_id to mp_obj_id and make it public.
This commit is contained in:
18
py/obj.c
18
py/obj.c
@@ -352,6 +352,24 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index,
|
||||
return i;
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_id(mp_obj_t o_in) {
|
||||
mp_int_t id = (mp_int_t)o_in;
|
||||
if (!MP_OBJ_IS_OBJ(o_in)) {
|
||||
return mp_obj_new_int(id);
|
||||
} else if (id >= 0) {
|
||||
// Many OSes and CPUs have affinity for putting "user" memories
|
||||
// into low half of address space, and "system" into upper half.
|
||||
// We're going to take advantage of that and return small int
|
||||
// (signed) for such "user" addresses.
|
||||
return MP_OBJ_NEW_SMALL_INT(id);
|
||||
} else {
|
||||
// If that didn't work, well, let's return long int, just as
|
||||
// a (big) positve value, so it will never clash with the range
|
||||
// of small int returned in previous case.
|
||||
return mp_obj_new_int_from_uint((mp_uint_t)id);
|
||||
}
|
||||
}
|
||||
|
||||
// will raise a TypeError if object has no length
|
||||
mp_obj_t mp_obj_len(mp_obj_t o_in) {
|
||||
mp_obj_t len = mp_obj_len_maybe(o_in);
|
||||
|
||||
Reference in New Issue
Block a user