py/objstrunicode: str_index_to_ptr: Should handle bytes too.

There's single str_index_to_ptr() function, called for both bytes and
unicode objects, so should handle each properly.
pull/2262/head
Paul Sokolovsky 2016-07-25 14:43:04 +03:00
rodzic 16f324641f
commit 6af90b2972
2 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -116,7 +116,14 @@ STATIC mp_obj_t uni_unary_op(mp_uint_t op, mp_obj_t self_in) {
// be capped to the first/last character of the string, depending on is_slice.
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len,
mp_obj_t index, bool is_slice) {
(void)type;
// All str functions also handle bytes objects, and they call str_index_to_ptr(),
// so it must handle bytes.
if (type == &mp_type_bytes) {
// Taken from objstr.c:str_index_to_ptr()
mp_uint_t index_val = mp_get_index(type, self_len, index, is_slice);
return self_data + index_val;
}
mp_int_t i;
// Copied from mp_get_index; I don't want bounds checking, just give me
// the integer as-is. (I can't bounds-check without scanning the whole

Wyświetl plik

@ -21,3 +21,6 @@ print(b"0000".find(b'-1', 3))
print(b"0000".find(b'1', 3))
print(b"0000".find(b'1', 4))
print(b"0000".find(b'1', 5))
# Non-ascii values (make sure not treated as unicode-like)
print(b"\x80abc".find(b"a", 1))