core: Cast type names to qstr explicitly.

The name field of type objects is of type uint16_t for efficiency,
but when the type is passed to mp_printf it must be cast explicitly
to type qstr.

These locations were found using an experimental gcc plugin
for mp_printf error checking, cross-building for x64 windows
on Linux.

Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
Jeff Epler 2025-06-21 15:37:35 +02:00
parent 431b79146e
commit 061eaefefb
5 changed files with 5 additions and 5 deletions

View file

@ -135,7 +135,7 @@ static void mp_help_print_obj(const mp_obj_t obj) {
// try to print something sensible about the given object
mp_print_str(MP_PYTHON_PRINTER, "object ");
mp_obj_print(obj, PRINT_STR);
mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", type->name);
mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", (qstr)type->name);
mp_map_t *map = NULL;
if (type == &mp_type_module) {

View file

@ -128,7 +128,7 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
if (MP_OBJ_TYPE_HAS_SLOT(type, print)) {
MP_OBJ_TYPE_GET_SLOT(type, print)((mp_print_t *)print, o_in, kind);
} else {
mp_printf(print, "<%q>", type->name);
mp_printf(print, "<%q>", (qstr)type->name);
}
}

View file

@ -84,7 +84,7 @@ static void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
#endif
}
if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict && kind != PRINT_JSON) {
mp_printf(print, "%q(", self->base.type->name);
mp_printf(print, "%q(", (qstr)self->base.type->name);
}
mp_print_str(print, "{");
size_t cur = 0;

View file

@ -63,7 +63,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(namedtuple_asdict_obj, namedtuple_asdict);
static void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_namedtuple_t *o = MP_OBJ_TO_PTR(o_in);
mp_printf(print, "%q", o->tuple.base.type->name);
mp_printf(print, "%q", (qstr)o->tuple.base.type->name);
const qstr *fields = ((mp_obj_namedtuple_type_t *)o->tuple.base.type)->fields;
mp_obj_attrtuple_print_helper(print, fields, &o->tuple);
}

View file

@ -977,7 +977,7 @@ static bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
static void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<class '%q'>", self->name);
mp_printf(print, "<class '%q'>", (qstr)self->name);
}
static mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {