py: Implement more complete bytes comparison handling.
This commit is contained in:
parent
ad3baec12f
commit
70328e419a
11
py/objstr.c
11
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;
|
||||
|
7
tests/basics/bytes_compare2.py
Normal file
7
tests/basics/bytes_compare2.py
Normal file
@ -0,0 +1,7 @@
|
||||
import array
|
||||
|
||||
print(b"1" == 1)
|
||||
print(b"123" == bytearray(b"123"))
|
||||
print(b"123" == "123")
|
||||
# CPyhon gives False here
|
||||
#print(b"\x01\x02\x03" == array.array("B", [1, 2, 3]))
|
Loading…
Reference in New Issue
Block a user