summaryrefslogtreecommitdiffstatshomepage
path: root/py/builtin.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/builtin.c')
-rw-r--r--py/builtin.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/py/builtin.c b/py/builtin.c
index f102aa5885..8340ad3045 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -8,7 +8,7 @@
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
-#include "mpqstr.h"
+#include "qstr.h"
#include "obj.h"
#include "runtime0.h"
#include "runtime.h"
@@ -139,8 +139,8 @@ 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) {
- char str[2] = {ord, '\0'};
- return mp_obj_new_str(qstr_from_strn_copy(str, 1));
+ char str[1] = {ord};
+ return mp_obj_new_str(qstr_from_strn(str, 1));
} else {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "chr() arg not in range(0x110000)"));
}
@@ -257,11 +257,12 @@ static mp_obj_t mp_builtin_next(mp_obj_t o) {
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) {
- const char *str = qstr_str(mp_obj_get_qstr(o_in));
- if (strlen(str) == 1) {
+ uint len;
+ const byte *str = qstr_data(mp_obj_get_qstr(o_in), &len);
+ if (len == 1) {
return mp_obj_new_int(str[0]);
} else {
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "ord() expected a character, but string of length %d found", strlen(str)));
+ nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "ord() expected a character, but string of length %d found", len));
}
}
@@ -304,7 +305,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_range_obj, 1, 3, mp_builtin_range
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);
- return mp_obj_new_str(qstr_from_str_take(vstr->buf, vstr->alloc));
+ // TODO don't intern this string
+ return mp_obj_new_str(qstr_from_strn_take(vstr->buf, vstr->alloc, vstr->len));
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr);
@@ -343,7 +345,8 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_sorted_obj, 1, mp_builtin_sorted);
static mp_obj_t mp_builtin_str(mp_obj_t o_in) {
vstr_t *vstr = vstr_new();
mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, o_in, PRINT_STR);
- return mp_obj_new_str(qstr_from_str_take(vstr->buf, vstr->alloc));
+ // TODO don't intern this string
+ return mp_obj_new_str(qstr_from_strn_take(vstr->buf, vstr->alloc, vstr->len));
}
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_str_obj, mp_builtin_str);