diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-15 20:58:40 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-15 20:58:40 +0300 |
commit | 70328e419a3f7d826699d466a1606e4296d538b6 (patch) | |
tree | e07ba4caa834af02f4827fbba1d71edca4efae85 /py/objstr.c | |
parent | ad3baec12f2d86cda58bc2a51173c76b6c335fa2 (diff) | |
download | micropython-70328e419a3f7d826699d466a1606e4296d538b6.tar.gz micropython-70328e419a3f7d826699d466a1606e4296d538b6.zip |
py: Implement more complete bytes comparison handling.
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index 1448f0b95f..a160338069 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -328,6 +328,17 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { GET_STR_DATA_LEN(rhs_in, rhs_data, rhs_len); return MP_BOOL(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len)); } + if (lhs_type == &mp_type_bytes) { + mp_buffer_info_t bufinfo; + if (!mp_get_buffer(rhs_in, &bufinfo, MP_BUFFER_READ)) { + goto uncomparable; + } + return MP_BOOL(mp_seq_cmp_bytes(op, lhs_data, lhs_len, bufinfo.buf, bufinfo.len)); + } +uncomparable: + if (op == MP_BINARY_OP_EQUAL) { + return mp_const_false; + } } return MP_OBJ_NOT_SUPPORTED; |