diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-27 09:21:41 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-27 09:21:41 +0100 |
commit | a97e091d4e80bbdb05f4bb27f18b905b50daf018 (patch) | |
tree | a167161db4f7b57d23445314bd0f07bc139ac271 /py/objstr.c | |
parent | f3c3010ffccc6cee0795c0491e2a686994bd0b34 (diff) | |
parent | a75b02ea9be41c27b87fd80ad37e7c26b4583fad (diff) | |
download | micropython-a97e091d4e80bbdb05f4bb27f18b905b50daf018.tar.gz micropython-a97e091d4e80bbdb05f4bb27f18b905b50daf018.zip |
Merge branch 'dhylands-int-bytes'
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/py/objstr.c b/py/objstr.c index e884794591..366ba88163 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -49,10 +49,6 @@ STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str); STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in); STATIC NORETURN void arg_type_mixup(); -STATIC bool is_str_or_bytes(mp_obj_t o) { - return MP_OBJ_IS_STR(o) || MP_OBJ_IS_TYPE(o, &mp_type_bytes); -} - /******************************************************************************/ /* str */ @@ -251,6 +247,9 @@ STATIC const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byt return NULL; } +// Note: this function is used to check if an object is a str or bytes, which +// works because both those types use it as their binary_op method. Revisit +// MP_OBJ_IS_STR_OR_BYTES if this fact changes. mp_obj_t mp_obj_str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { GET_STR_DATA_LEN(lhs_in, lhs_data, lhs_len); mp_obj_type_t *lhs_type = mp_obj_get_type(lhs_in); @@ -388,7 +387,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { - assert(is_str_or_bytes(self_in)); + assert(MP_OBJ_IS_STR_OR_BYTES(self_in)); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); // get separation string @@ -660,7 +659,7 @@ enum { LSTRIP, RSTRIP, STRIP }; STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) { assert(1 <= n_args && n_args <= 2); - assert(is_str_or_bytes(args[0])); + assert(MP_OBJ_IS_STR_OR_BYTES(args[0])); const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); const byte *chars_to_del; @@ -1477,7 +1476,7 @@ STATIC mp_obj_t str_count(uint n_args, const mp_obj_t *args) { } STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, mp_int_t direction) { - if (!is_str_or_bytes(self_in)) { + if (!MP_OBJ_IS_STR_OR_BYTES(self_in)) { assert(0); } mp_obj_type_t *self_type = mp_obj_get_type(self_in); @@ -1877,7 +1876,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) { } const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len) { - if (is_str_or_bytes(self_in)) { + if (MP_OBJ_IS_STR_OR_BYTES(self_in)) { GET_STR_DATA_LEN(self_in, s, l); *len = l; return (const char*)s; |