From ee01411036f10d78235cc0549bd4a0507cf7bfc6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 15 Apr 2014 23:10:00 +0100 Subject: [PATCH] py: Add len(bytes). --- py/obj.c | 2 +- py/objstr.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/py/obj.c b/py/obj.c index 078284f2a8..76350ed6d2 100644 --- a/py/obj.c +++ b/py/obj.c @@ -320,7 +320,7 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, // may return MP_OBJ_NULL mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { - if (MP_OBJ_IS_STR(o_in)) { + if (MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) { return MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_str_get_len(o_in)); } else { mp_obj_type_t *type = mp_obj_get_type(o_in); diff --git a/py/objstr.c b/py/objstr.c index 0edc49909e..7de42b6e9e 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1485,7 +1485,8 @@ uint mp_obj_str_get_hash(mp_obj_t self_in) { } uint mp_obj_str_get_len(mp_obj_t self_in) { - if (MP_OBJ_IS_STR(self_in)) { + // TODO This has a double check for the type, one in obj.c and one here + if (MP_OBJ_IS_STR(self_in) || MP_OBJ_IS_TYPE(self_in, &mp_type_bytes)) { GET_STR_LEN(self_in, l); return l; } else {