Skip to content

Commit 519cba4

Browse files
jeplerdpgeorge
authored andcommitted
py: 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 <[email protected]>
1 parent 7493275 commit 519cba4

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

py/builtinhelp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static void mp_help_print_obj(const mp_obj_t obj) {
135135
// try to print something sensible about the given object
136136
mp_print_str(MP_PYTHON_PRINTER, "object ");
137137
mp_obj_print(obj, PRINT_STR);
138-
mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", type->name);
138+
mp_printf(MP_PYTHON_PRINTER, " is of type %q\n", (qstr)type->name);
139139

140140
mp_map_t *map = NULL;
141141
if (type == &mp_type_module) {

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
128128
if (MP_OBJ_TYPE_HAS_SLOT(type, print)) {
129129
MP_OBJ_TYPE_GET_SLOT(type, print)((mp_print_t *)print, o_in, kind);
130130
} else {
131-
mp_printf(print, "<%q>", type->name);
131+
mp_printf(print, "<%q>", (qstr)type->name);
132132
}
133133
}
134134

py/objdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
8484
#endif
8585
}
8686
if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict && kind != PRINT_JSON) {
87-
mp_printf(print, "%q(", self->base.type->name);
87+
mp_printf(print, "%q(", (qstr)self->base.type->name);
8888
}
8989
mp_print_str(print, "{");
9090
size_t cur = 0;

py/objnamedtuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(namedtuple_asdict_obj, namedtuple_asdict);
6363
static void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
6464
(void)kind;
6565
mp_obj_namedtuple_t *o = MP_OBJ_TO_PTR(o_in);
66-
mp_printf(print, "%q", o->tuple.base.type->name);
66+
mp_printf(print, "%q", (qstr)o->tuple.base.type->name);
6767
const qstr *fields = ((mp_obj_namedtuple_type_t *)o->tuple.base.type)->fields;
6868
mp_obj_attrtuple_print_helper(print, fields, &o->tuple);
6969
}

py/objtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ static bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
977977
static void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
978978
(void)kind;
979979
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
980-
mp_printf(print, "<class '%q'>", self->name);
980+
mp_printf(print, "<class '%q'>", (qstr)self->name);
981981
}
982982

983983
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) {

0 commit comments

Comments
 (0)