summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-25 22:27:57 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-25 22:27:57 +0100
commit2617eebf2ff77e58f415162300747eaf1a5ab5d7 (patch)
tree7065586f59aa181b70b4721363ff7c7677f8e772
parentf88fc7bd23c7bab257a01857c6f4683ce491f78c (diff)
downloadmicropython-2617eebf2ff77e58f415162300747eaf1a5ab5d7.tar.gz
micropython-2617eebf2ff77e58f415162300747eaf1a5ab5d7.zip
Change const byte* to const char* where sensible.
This removes need for some casts (at least, more than it adds need for new casts!).
-rw-r--r--py/builtin.c4
-rw-r--r--py/builtinimport.c2
-rw-r--r--py/obj.h2
-rw-r--r--py/objexcept.c2
-rw-r--r--py/objstr.c18
-rw-r--r--py/parse.c2
-rw-r--r--py/qstr.c12
-rw-r--r--py/qstr.h3
-rw-r--r--stmhal/input.c2
-rw-r--r--unix/input.c2
-rw-r--r--unix/modffi.c2
-rw-r--r--unix/modsocket.c5
12 files changed, 25 insertions, 31 deletions
diff --git a/py/builtin.c b/py/builtin.c
index 7f0d2a4d9f..178a6835aa 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -172,7 +172,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
int ord = mp_obj_get_int(o_in);
if (0 <= ord && ord <= 0x10ffff) {
- byte str[1] = {ord};
+ char str[1] = {ord};
return mp_obj_new_str(str, 1, true);
} else {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)"));
@@ -391,7 +391,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print);
STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) {
vstr_t *vstr = vstr_new();
mp_obj_print_helper((void (*)(void *env, const char *fmt, ...))vstr_printf, vstr, o_in, PRINT_REPR);
- mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
+ mp_obj_t s = mp_obj_new_str(vstr->buf, vstr->len, false);
vstr_free(vstr);
return s;
}
diff --git a/py/builtinimport.c b/py/builtinimport.c
index fa1a8397e1..50780c01d6 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -318,7 +318,7 @@ mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) {
DEBUG_printf("%s is dir\n", vstr_str(&path));
// https://docs.python.org/3.3/reference/import.html
// "Specifically, any module that contains a __path__ attribute is considered a package."
- mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str((byte*)vstr_str(&path), vstr_len(&path), false));
+ mp_store_attr(module_obj, MP_QSTR___path__, mp_obj_new_str(vstr_str(&path), vstr_len(&path), false));
vstr_add_char(&path, PATH_SEP_CHAR);
vstr_add_str(&path, "__init__.py");
if (mp_import_stat(vstr_str(&path)) != MP_IMPORT_STAT_FILE) {
diff --git a/py/obj.h b/py/obj.h
index b1d9be2096..e4350b424f 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -373,7 +373,7 @@ mp_obj_t mp_obj_new_int(machine_int_t value);
mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value);
mp_obj_t mp_obj_new_int_from_qstr(qstr qst);
mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception)
-mp_obj_t mp_obj_new_str(const byte* data, uint len, bool make_qstr_if_not_already);
+mp_obj_t mp_obj_new_str(const char* data, uint len, bool make_qstr_if_not_already);
mp_obj_t mp_obj_new_bytes(const byte* data, uint len);
#if MICROPY_ENABLE_FLOAT
mp_obj_t mp_obj_new_float(mp_float_t val);
diff --git a/py/objexcept.c b/py/objexcept.c
index 7583d07431..b0ccb90fd6 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -283,7 +283,7 @@ mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char
va_start(ap, fmt);
vstr_vprintf(vstr, fmt, ap);
va_end(ap);
- o->args->items[0] = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
+ o->args->items[0] = mp_obj_new_str(vstr->buf, vstr->len, false);
vstr_free(vstr);
}
}
diff --git a/py/objstr.c b/py/objstr.c
index f5939d1b1f..48d824f07d 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -129,7 +129,7 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
{
vstr_t *vstr = vstr_new();
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, args[0], PRINT_STR);
- mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
+ mp_obj_t s = mp_obj_new_str(vstr->buf, vstr->len, false);
vstr_free(vstr);
return s;
}
@@ -363,7 +363,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (type == &mp_type_bytes) {
return MP_OBJ_NEW_SMALL_INT((mp_small_int_t)self_data[index_val]);
} else {
- return mp_obj_new_str(self_data + index_val, 1, true);
+ return mp_obj_new_str((char*)self_data + index_val, 1, true);
}
} else {
return MP_OBJ_NULL; // op not supported
@@ -873,7 +873,7 @@ mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args) {
}
vstr_t *arg_vstr = vstr_new();
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, arg_vstr, arg, print_kind);
- arg = mp_obj_new_str((const byte *)vstr_str(arg_vstr), vstr_len(arg_vstr), false);
+ arg = mp_obj_new_str(vstr_str(arg_vstr), vstr_len(arg_vstr), false);
vstr_free(arg_vstr);
}
@@ -1116,7 +1116,7 @@ mp_obj_t mp_obj_str_format(uint n_args, const mp_obj_t *args) {
}
}
- mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
+ mp_obj_t s = mp_obj_new_str(vstr->buf, vstr->len, false);
vstr_free(vstr);
return s;
}
@@ -1287,7 +1287,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "not all arguments converted during string formatting"));
}
- mp_obj_t s = mp_obj_new_str((byte*)vstr->buf, vstr->len, false);
+ mp_obj_t s = mp_obj_new_str(vstr->buf, vstr->len, false);
vstr_free(vstr);
return s;
}
@@ -1655,17 +1655,17 @@ mp_obj_t str_new(const mp_obj_type_t *type, const byte* data, uint len) {
return o;
}
-mp_obj_t mp_obj_new_str(const byte* data, uint len, bool make_qstr_if_not_already) {
+mp_obj_t mp_obj_new_str(const char* data, uint len, bool make_qstr_if_not_already) {
qstr q = qstr_find_strn(data, len);
if (q != MP_QSTR_NULL) {
// qstr with this data already exists
return MP_OBJ_NEW_QSTR(q);
} else if (make_qstr_if_not_already) {
// no existing qstr, make a new one
- return MP_OBJ_NEW_QSTR(qstr_from_strn((const char*)data, len));
+ return MP_OBJ_NEW_QSTR(qstr_from_strn(data, len));
} else {
// no existing qstr, don't make one
- return str_new(&mp_type_str, data, len);
+ return str_new(&mp_type_str, (const byte*)data, len);
}
}
@@ -1768,7 +1768,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) {
mp_obj_str_it_t *self = self_in;
GET_STR_DATA_LEN(self->str, str, len);
if (self->cur < len) {
- mp_obj_t o_out = mp_obj_new_str(str + self->cur, 1, true);
+ mp_obj_t o_out = mp_obj_new_str((const char*)str + self->cur, 1, true);
self->cur += 1;
return o_out;
} else {
diff --git a/py/parse.c b/py/parse.c
index b255ebd35c..93bced843b 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -349,7 +349,7 @@ STATIC void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
qst = qstr_from_strn(tok->str, tok->len);
} else {
// check if this string is already interned
- qst = qstr_find_strn((const byte*)tok->str, tok->len);
+ qst = qstr_find_strn(tok->str, tok->len);
}
if (qst != MP_QSTR_NULL) {
// qstr exists, make a leaf node
diff --git a/py/qstr.c b/py/qstr.c
index 79475777cc..a1ee7cafd0 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -130,7 +130,7 @@ STATIC qstr qstr_add(const byte *q_ptr) {
return last_pool->total_prev_len + last_pool->len - 1;
}
-qstr qstr_find_strn(const byte *str, uint str_len) {
+qstr qstr_find_strn(const char *str, uint str_len) {
// work out hash of str
machine_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len);
@@ -152,7 +152,7 @@ qstr qstr_from_str(const char *str) {
}
qstr qstr_from_strn(const char *str, uint len) {
- qstr q = qstr_find_strn((const byte*)str, len);
+ qstr q = qstr_find_strn(str, len);
if (q == 0) {
machine_uint_t hash = qstr_compute_hash((const byte*)str, len);
byte *q_ptr = m_new(byte, 4 + len + 1);
@@ -167,12 +167,6 @@ qstr qstr_from_strn(const char *str, uint len) {
return q;
}
-qstr qstr_from_strn_take(char *str, uint alloc_len, uint len) {
- qstr q = qstr_from_strn(str, len);
- m_del(char, str, alloc_len);
- return q;
-}
-
byte *qstr_build_start(uint len, byte **q_ptr) {
assert(len <= 65535);
*q_ptr = m_new(byte, 4 + len + 1);
@@ -182,7 +176,7 @@ byte *qstr_build_start(uint len, byte **q_ptr) {
}
qstr qstr_build_end(byte *q_ptr) {
- qstr q = qstr_find_strn(Q_GET_DATA(q_ptr), Q_GET_LENGTH(q_ptr));
+ qstr q = qstr_find_strn((const char*)Q_GET_DATA(q_ptr), Q_GET_LENGTH(q_ptr));
if (q == 0) {
machine_uint_t len = Q_GET_LENGTH(q_ptr);
machine_uint_t hash = qstr_compute_hash(Q_GET_DATA(q_ptr), len);
diff --git a/py/qstr.h b/py/qstr.h
index 8c0a195631..fc93fe2c2a 100644
--- a/py/qstr.h
+++ b/py/qstr.h
@@ -46,12 +46,11 @@ typedef machine_uint_t qstr;
void qstr_init(void);
machine_uint_t qstr_compute_hash(const byte *data, uint len);
-qstr qstr_find_strn(const byte *str, uint str_len); // returns MP_QSTR_NULL if not found
+qstr qstr_find_strn(const char *str, uint str_len); // returns MP_QSTR_NULL if not found
qstr qstr_from_str(const char *str);
qstr qstr_from_strn(const char *str, uint len);
//qstr qstr_from_str_static(const char *str);
-qstr qstr_from_strn_take(char *str, uint alloc_len, uint len);
//qstr qstr_from_strn_copy(const char *str, int len);
byte* qstr_build_start(uint len, byte **q_ptr);
diff --git a/stmhal/input.c b/stmhal/input.c
index 94f66b97f1..7f3b17c6fe 100644
--- a/stmhal/input.c
+++ b/stmhal/input.c
@@ -44,7 +44,7 @@ STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) {
if (line.len == 0 && ret == VCP_CHAR_CTRL_D) {
nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
}
- mp_obj_t o = mp_obj_new_str((const byte*)line.buf, line.len, false);
+ mp_obj_t o = mp_obj_new_str(line.buf, line.len, false);
vstr_clear(&line);
return o;
}
diff --git a/unix/input.c b/unix/input.c
index 06190306ab..4d856f2ff8 100644
--- a/unix/input.c
+++ b/unix/input.c
@@ -77,7 +77,7 @@ STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) {
if (line == NULL) {
nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
}
- mp_obj_t o = mp_obj_new_str((const byte*)line, strlen(line), false);
+ mp_obj_t o = mp_obj_new_str(line, strlen(line), false);
free(line);
return o;
}
diff --git a/unix/modffi.c b/unix/modffi.c
index 4ac9fef5aa..bfc840ceff 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -134,7 +134,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
switch (type) {
case 's': {
const char *s = (const char *)val;
- return mp_obj_new_str((const byte *)s, strlen(s), false);
+ return mp_obj_new_str(s, strlen(s), false);
}
case 'v':
return mp_const_none;
diff --git a/unix/modsocket.c b/unix/modsocket.c
index c4e80d3d52..16039bd813 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -167,8 +167,9 @@ STATIC mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) {
int out_sz = recv(self->fd, buf, sz, flags);
RAISE_ERRNO(out_sz, errno);
- buf = m_realloc(buf, sz, out_sz);
- return MP_OBJ_NEW_QSTR(qstr_from_strn_take(buf, out_sz, out_sz));
+ mp_obj_t ret = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, out_sz));
+ m_del(char, buf, sz);
+ return ret;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_obj, 2, 3, socket_recv);