mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
py/runtime: Check that keys in dicts passed as ** args are strings.
Prior to this patch the code would crash if a key in a ** dict was anything other than a str or qstr. This is because mp_setup_code_state() assumes that keys in kwargs are qstrs (for efficiency). Thanks to @jepler for finding the bug.
This commit is contained in:
@@ -2062,6 +2062,12 @@ mp_obj_t mp_obj_str_intern(mp_obj_t str) {
|
||||
return mp_obj_new_str_via_qstr((const char*)data, len);
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_str_intern_checked(mp_obj_t obj) {
|
||||
size_t len;
|
||||
const char *data = mp_obj_str_get_data(obj, &len);
|
||||
return mp_obj_new_str_via_qstr((const char*)data, len);
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_new_bytes(const byte* data, size_t len) {
|
||||
return mp_obj_new_str_copy(&mp_type_bytes, data, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user