diff options
author | Damien George <damien.p.george@gmail.com> | 2014-02-08 18:17:23 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-02-08 18:17:23 +0000 |
commit | 698ec21e46564ff0c2c71bf11d7eb4ef349c88d9 (patch) | |
tree | 3d0eac21ec784f970f9f5586dfbd28c66f0774e5 | |
parent | 23177088d255bec6c0bf93470aeac77194aa8258 (diff) | |
download | micropython-698ec21e46564ff0c2c71bf11d7eb4ef349c88d9.tar.gz micropython-698ec21e46564ff0c2c71bf11d7eb4ef349c88d9.zip |
Make mp_obj_str_get_data return char* instead of byte*.
Can't decide which is better for string type, char or byte pointer.
Changing to char removes a few casts. Really need to do proper unicode.
-rw-r--r-- | py/builtin.c | 6 | ||||
-rw-r--r-- | py/builtinevex.c | 4 | ||||
-rw-r--r-- | py/builtinimport.c | 4 | ||||
-rw-r--r-- | py/obj.h | 2 | ||||
-rw-r--r-- | py/objarray.c | 2 | ||||
-rw-r--r-- | py/objint.c | 8 | ||||
-rw-r--r-- | py/objstr.c | 4 | ||||
-rw-r--r-- | py/stream.c | 2 | ||||
-rw-r--r-- | stm/file.c | 2 | ||||
-rw-r--r-- | stm/lcd.c | 4 | ||||
-rw-r--r-- | stm/usart.c | 4 | ||||
-rw-r--r-- | unix/socket.c | 2 |
12 files changed, 23 insertions, 21 deletions
diff --git a/py/builtin.c b/py/builtin.c index ff248f87c3..b0599bc4b5 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -288,9 +288,11 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next); static mp_obj_t mp_builtin_ord(mp_obj_t o_in) { uint len; - const byte *str = mp_obj_str_get_data(o_in, &len); + const char *str = mp_obj_str_get_data(o_in, &len); if (len == 1) { - return mp_obj_new_int(str[0]); + // don't sign extend when converting to ord + // TODO unicode + return mp_obj_new_int(((const byte*)str)[0]); } else { nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "ord() expected a character, but string of length %d found", len)); } diff --git a/py/builtinevex.c b/py/builtinevex.c index 03db862738..54c3f743e3 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -21,10 +21,10 @@ static mp_obj_t parse_compile_execute(mp_obj_t o_in, mp_parse_input_kind_t parse_input_kind) { uint str_len; - const byte *str = mp_obj_str_get_data(o_in, &str_len); + const char *str = mp_obj_str_get_data(o_in, &str_len); // create the lexer - mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, (const char*)str, str_len, 0); + mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, str, str_len, 0); qstr source_name = mp_lexer_source_name(lex); // parse the string diff --git a/py/builtinimport.c b/py/builtinimport.c index 1ef7be8702..0e44676c3b 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -54,9 +54,9 @@ mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *dest) { for (int i = 0; i < path_num; i++) { vstr_reset(dest); uint p_len; - const byte *p = mp_obj_str_get_data(path_items[i], &p_len); + const char *p = mp_obj_str_get_data(path_items[i], &p_len); if (p_len > 0) { - vstr_add_strn(dest, (const char*)p, p_len); + vstr_add_strn(dest, p, p_len); vstr_add_char(dest, PATH_SEP_CHAR); } vstr_add_strn(dest, file_str, file_len); @@ -290,7 +290,7 @@ uint mp_obj_str_get_hash(mp_obj_t self_in); uint mp_obj_str_get_len(mp_obj_t self_in); qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated -const byte *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); void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len); // bytes diff --git a/py/objarray.c b/py/objarray.c index c595d217c1..75ed399d20 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -174,7 +174,7 @@ static mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m } // TODO check args uint l; - const byte *typecode = mp_obj_str_get_data(args[0], &l); + const char *typecode = mp_obj_str_get_data(args[0], &l); if (n_args == 1) { return array_new(*typecode, 0); } diff --git a/py/objint.c b/py/objint.c index 1a04408afd..fdcc43807a 100644 --- a/py/objint.c +++ b/py/objint.c @@ -23,8 +23,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ if (MP_OBJ_IS_STR(args[0])) { // a string, parse it uint l; - const byte *s = mp_obj_str_get_data(args[0], &l); - return MP_OBJ_NEW_SMALL_INT(strtonum((const char*)s, 0)); + const char *s = mp_obj_str_get_data(args[0], &l); + return MP_OBJ_NEW_SMALL_INT(strtonum(s, 0)); } else { return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0])); } @@ -34,8 +34,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_ // should be a string, parse it // TODO proper error checking of argument types uint l; - const byte *s = mp_obj_str_get_data(args[0], &l); - return MP_OBJ_NEW_SMALL_INT(strtonum((const char*)s, mp_obj_get_int(args[1]))); + const char *s = mp_obj_str_get_data(args[0], &l); + return MP_OBJ_NEW_SMALL_INT(strtonum(s, mp_obj_get_int(args[1]))); } default: diff --git a/py/objstr.c b/py/objstr.c index 03602b6ec7..81e0d65b3b 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -635,11 +635,11 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) { } } -const byte *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)) { GET_STR_DATA_LEN(self_in, s, l); *len = l; - return s; + return (const char*)s; } else { bad_implicit_conversion(self_in); } diff --git a/py/stream.c b/py/stream.c index c97c711f0f..10c7d88c0d 100644 --- a/py/stream.c +++ b/py/stream.c @@ -43,7 +43,7 @@ static mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) { } uint sz; - const byte *buf = mp_obj_str_get_data(arg, &sz); + const char *buf = mp_obj_str_get_data(arg, &sz); int error; machine_int_t out_sz = o->type->stream_p.write(self_in, buf, sz, &error); if (out_sz == -1) { diff --git a/stm/file.c b/stm/file.c index 84f7251fec..36658e7a69 100644 --- a/stm/file.c +++ b/stm/file.c @@ -29,7 +29,7 @@ mp_obj_t file_obj_read(mp_obj_t self_in, mp_obj_t arg) { mp_obj_t file_obj_write(mp_obj_t self_in, mp_obj_t arg) { pyb_file_obj_t *self = self_in; uint l; - const byte *s = mp_obj_str_get_data(arg, &l); + const char *s = mp_obj_str_get_data(arg, &l); UINT n_out; FRESULT res = f_write(&self->fp, s, l, &n_out); if (res != FR_OK) { @@ -202,8 +202,8 @@ mp_obj_t lcd_pix_show(void) { mp_obj_t lcd_print(mp_obj_t text) { uint len; - const byte *data = mp_obj_str_get_data(text, &len); - lcd_print_strn((const char*)data, len); + const char *data = mp_obj_str_get_data(text, &len); + lcd_print_strn(data, len); return mp_const_none; } diff --git a/stm/usart.c b/stm/usart.c index d9de599c46..306284d5a9 100644 --- a/stm/usart.c +++ b/stm/usart.c @@ -159,7 +159,7 @@ void usart_tx_str(pyb_usart_t usart_id, const char *str) { } } -void usart_tx_bytes(pyb_usart_t usart_id, const byte *data, uint len) { +void usart_tx_bytes(pyb_usart_t usart_id, const char *data, uint len) { for (; len > 0; data++, len--) { usart_tx_char(usart_id, *data); } @@ -216,7 +216,7 @@ static mp_obj_t usart_obj_tx_str(mp_obj_t self_in, mp_obj_t s) { if (self->is_enabled) { if (MP_OBJ_IS_STR(s)) { uint len; - const byte *data = mp_obj_str_get_data(s, &len); + const char *data = mp_obj_str_get_data(s, &len); usart_tx_bytes(self->usart_id, data, len); } } diff --git a/unix/socket.c b/unix/socket.c index 6f7954522b..28749f3bef 100644 --- a/unix/socket.c +++ b/unix/socket.c @@ -154,7 +154,7 @@ static mp_obj_t socket_send(uint n_args, const mp_obj_t *args) { } uint sz; - const byte *buf = mp_obj_str_get_data(args[1], &sz); + const char *buf = mp_obj_str_get_data(args[1], &sz); int out_sz = send(self->fd, buf, sz, flags); RAISE_ERRNO(out_sz, errno); |