Skip to content

Commit ab1e36d

Browse files
committed
py/mpprint: Implement %llu and %lld format specifiers for mp_printf.
Only enabled for MICROPY_OBJ_REPR_D.
1 parent d977d26 commit ab1e36d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

py/mpprint.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,20 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
526526
break;
527527
}
528528
#endif
529+
// Because 'l' is eaten above, another 'l' means %ll. We need to support
530+
// this length specifier for OBJ_REPR_D (64-bit NaN boxing).
531+
// TODO Either enable this unconditionally, or provide a specific config var.
532+
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
533+
case 'l': {
534+
unsigned long long int arg_value = va_arg(args, unsigned long long int);
535+
++fmt;
536+
if (*fmt == 'u' || *fmt == 'd') {
537+
chrs += mp_print_int(print, arg_value, *fmt == 'd', 10, 'a', flags, fill, width);
538+
break;
539+
}
540+
// fall through to default case to print unknown format char
541+
}
542+
#endif
529543
default:
530544
print->print_strn(print->data, fmt, 1);
531545
chrs += 1;

0 commit comments

Comments
 (0)