summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/modgc.c6
-rw-r--r--py/modmicropython.c6
-rw-r--r--py/obj.c2
-rw-r--r--py/obj.h5
-rw-r--r--py/objbool.c2
-rw-r--r--py/objdict.c2
-rw-r--r--py/objint.c2
-rw-r--r--py/objset.c2
-rw-r--r--py/objstr.c14
-rw-r--r--py/objstrunicode.c2
10 files changed, 27 insertions, 16 deletions
diff --git a/py/modgc.c b/py/modgc.c
index 045563cd98..5fed2d8861 100644
--- a/py/modgc.c
+++ b/py/modgc.c
@@ -42,7 +42,7 @@ extern uint gc_collected;
STATIC mp_obj_t py_gc_collect(void) {
gc_collect();
#if MICROPY_PY_GC_COLLECT_RETVAL
- return MP_OBJ_NEW_SMALL_INT((mp_uint_t)gc_collected);
+ return MP_OBJ_NEW_SMALL_INT(gc_collected);
#else
return mp_const_none;
#endif
@@ -64,14 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
STATIC mp_obj_t gc_mem_free(void) {
gc_info_t info;
gc_info(&info);
- return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.free);
+ return MP_OBJ_NEW_SMALL_INT(info.free);
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
STATIC mp_obj_t gc_mem_alloc(void) {
gc_info_t info;
gc_info(&info);
- return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.used);
+ return MP_OBJ_NEW_SMALL_INT(info.used);
}
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc);
diff --git a/py/modmicropython.c b/py/modmicropython.c
index 78beb88afa..87bab0a33e 100644
--- a/py/modmicropython.c
+++ b/py/modmicropython.c
@@ -35,15 +35,15 @@
#if MICROPY_MEM_STATS
STATIC mp_obj_t mp_micropython_mem_total() {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_total_bytes_allocated());
+ return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated());
}
STATIC mp_obj_t mp_micropython_mem_current() {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_current_bytes_allocated());
+ return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated());
}
STATIC mp_obj_t mp_micropython_mem_peak() {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_peak_bytes_allocated());
+ return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total);
diff --git a/py/obj.c b/py/obj.c
index 755da02750..ae20db4354 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -368,7 +368,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
MP_OBJ_IS_STR(o_in) ||
#endif
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_str_get_len(o_in));
+ return MP_OBJ_NEW_SMALL_INT(mp_obj_str_get_len(o_in));
} else {
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->unary_op != NULL) {
diff --git a/py/obj.h b/py/obj.h
index c391611c10..fa42428fad 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -76,10 +76,10 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
-#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1))
+#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
#define MP_OBJ_QSTR_VALUE(o) (((mp_int_t)(o)) >> 2)
-#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)qstr) << 2) | 2))
+#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)(qstr)) << 2) | 2))
// These macros are used to declare and define constant function objects
// You can put "static" in front of the definitions to make them local
@@ -460,6 +460,7 @@ void mp_init_emergency_exception_buf(void);
// str
mp_obj_t mp_obj_str_builder_start(const mp_obj_type_t *type, uint len, byte **data);
mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in);
+mp_obj_t mp_obj_str_builder_end_with_len(mp_obj_t o_in, mp_uint_t len);
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
uint mp_obj_str_get_hash(mp_obj_t self_in);
uint mp_obj_str_get_len(mp_obj_t self_in);
diff --git a/py/objbool.c b/py/objbool.c
index 9bf30d4236..72535b2972 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -74,7 +74,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
- return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_is_true(lhs_in)), rhs_in);
+ return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(mp_obj_is_true(lhs_in)), rhs_in);
}
return MP_OBJ_NULL; // op not supported
}
diff --git a/py/objdict.c b/py/objdict.c
index 9b4133f83b..f09065b102 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -75,7 +75,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
mp_obj_dict_t *self = self_in;
switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
- case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->map.used);
+ case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
default: return MP_OBJ_NULL; // op not supported
}
}
diff --git a/py/objint.c b/py/objint.c
index e351c3f394..c08bf7da6c 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -64,7 +64,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
return mp_parse_num_integer(s, l, 0);
#if MICROPY_PY_BUILTINS_FLOAT
} else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
+ return MP_OBJ_NEW_SMALL_INT((MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
#endif
} else {
// try to convert to small int (eg from bool)
diff --git a/py/objset.c b/py/objset.c
index 48d037ffc2..f17628d53e 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -476,7 +476,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) {
mp_obj_set_t *self = self_in;
switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0);
- case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->set.used);
+ case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used);
default: return MP_OBJ_NULL; // op not supported
}
}
diff --git a/py/objstr.c b/py/objstr.c
index 63d394e0a9..6ec997f4bf 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
#endif
const byte *p = str_index_to_ptr(type, self_data, self_len, index, false);
if (type == &mp_type_bytes) {
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)*p);
+ return MP_OBJ_NEW_SMALL_INT(*p);
} else {
return mp_obj_new_str((char*)p, 1, true);
}
@@ -1744,6 +1744,16 @@ mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in) {
return o;
}
+mp_obj_t mp_obj_str_builder_end_with_len(mp_obj_t o_in, mp_uint_t len) {
+ mp_obj_str_t *o = o_in;
+ o->data = m_renew(byte, (byte*)o->data, o->len + 1, len + 1);
+ o->len = len;
+ o->hash = qstr_compute_hash(o->data, o->len);
+ byte *p = (byte*)o->data;
+ p[o->len] = '\0'; // for now we add null for compatibility with C ASCIIZ strings
+ return o;
+}
+
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, uint len) {
mp_obj_str_t *o = m_new_obj(mp_obj_str_t);
o->base.type = type;
@@ -1907,7 +1917,7 @@ STATIC mp_obj_t bytes_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_SMALL_INT((mp_int_t)str[self->cur]);
+ mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(str[self->cur]);
self->cur += 1;
return o_out;
} else {
diff --git a/py/objstrunicode.c b/py/objstrunicode.c
index 873b4fc58e..848005c545 100644
--- a/py/objstrunicode.c
+++ b/py/objstrunicode.c
@@ -257,7 +257,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
#endif
if (type == &mp_type_bytes) {
uint index_val = mp_get_index(type, self_len, index, false);
- return MP_OBJ_NEW_SMALL_INT((mp_int_t)self_data[index_val]);
+ return MP_OBJ_NEW_SMALL_INT(self_data[index_val]);
}
const byte *s = str_index_to_ptr(type, self_data, self_len, index, false);
int len = 1;