py/objstr: Always ensure mp_obj_str_from_vstr is unicode-safe.
Now that we have `mp_obj_new_str_type_from_vstr` (private helper used by objstr.c) split from the public API (`mp_obj_new_str_from_vstr`), we can enforce a unicode check at the public API without incurring a performance cost on the various objstr.c methods (which are already working on known unicode-safe strings). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
8a0ee5a5c0
commit
88864587f5
|
@ -2248,6 +2248,11 @@ STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_obj_new_str_from_vstr(vstr_t *vstr) {
|
mp_obj_t mp_obj_new_str_from_vstr(vstr_t *vstr) {
|
||||||
|
#if MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
|
||||||
|
if (!utf8_check((byte *)vstr->buf, vstr->len)) {
|
||||||
|
mp_raise_msg(&mp_type_UnicodeError, NULL);
|
||||||
|
}
|
||||||
|
#endif // MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
|
||||||
return mp_obj_new_str_type_from_vstr(&mp_type_str, vstr);
|
return mp_obj_new_str_type_from_vstr(&mp_type_str, vstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue