Browse Source

py: Give up and make mp_obj_str_get_data() deal with bytes too.

This is not fully correct re: error handling, because we should check that
that types are used consistently (only str's or only bytes), but magically
makes lot of functions support bytes.
pull/600/head
Paul Sokolovsky 11 years ago
parent
commit
eea0118654
  1. 2
      py/objstr.c
  2. 1
      tests/basics/int1.py

2
py/objstr.c

@ -1647,7 +1647,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) { const char *mp_obj_str_get_data(mp_obj_t self_in, uint *len) {
if (MP_OBJ_IS_STR(self_in)) { if (is_str_or_bytes(self_in)) {
GET_STR_DATA_LEN(self_in, s, l); GET_STR_DATA_LEN(self_in, s, l);
*len = l; *len = l;
return (const char*)s; return (const char*)s;

1
tests/basics/int1.py

@ -46,6 +46,7 @@ print(int('0B100', 2))
print(int('0100', 2)) print(int('0100', 2))
print(int(' \t 0o12', 8)) print(int(' \t 0o12', 8))
print(int('0o12 \t ', 8)) print(int('0o12 \t ', 8))
print(int(b"12", 10))
def test(value, base): def test(value, base):

Loading…
Cancel
Save