Skip to content

Commit bb33cc6

Browse files
committed
Properly print MP_OBJ_QSTR objects.
1 parent 2c7a1b2 commit bb33cc6

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

py/obj.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void printf_wrapper(void *env, const char *fmt, ...) {
4444
void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
4545
if (MP_OBJ_IS_SMALL_INT(o_in)) {
4646
print(env, "%d", (int)MP_OBJ_SMALL_INT_VALUE(o_in));
47+
} else if (MP_OBJ_IS_QSTR(o_in)) {
48+
mp_obj_str_print_qstr(print, env, MP_OBJ_QSTR_VALUE(o_in), kind);
4749
} else {
4850
mp_obj_base_t *o = o_in;
4951
if (o->type->print != NULL) {

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine
280280
// str
281281
extern const mp_obj_type_t str_type;
282282
qstr mp_obj_str_get(mp_obj_t self_in);
283+
void mp_obj_str_print_qstr(void (*print)(void *env, const char *fmt, ...), void *env, qstr q, mp_print_kind_t kind);
283284

284285
#if MICROPY_ENABLE_FLOAT
285286
// float

py/objstr.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ static mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur);
2222
/******************************************************************************/
2323
/* str */
2424

25-
void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
26-
mp_obj_str_t *self = self_in;
25+
void mp_obj_str_print_qstr(void (*print)(void *env, const char *fmt, ...), void *env, qstr q, mp_print_kind_t kind) {
2726
if (kind == PRINT_STR) {
28-
print(env, "%s", qstr_str(self->qstr));
27+
print(env, "%s", qstr_str(q));
2928
} else {
3029
// TODO need to escape chars etc
31-
print(env, "'%s'", qstr_str(self->qstr));
30+
print(env, "'%s'", qstr_str(q));
3231
}
3332
}
3433

34+
void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
35+
mp_obj_str_t *self = self_in;
36+
mp_obj_str_print_qstr(print, env, self->qstr, kind);
37+
}
38+
3539
mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
3640
mp_obj_str_t *lhs = lhs_in;
3741
const char *lhs_str = qstr_str(lhs->qstr);

0 commit comments

Comments
 (0)