py/mpprint: Support printing %ld and %lu formats on 64-bit archs.

Fixes issue #4702.
This commit is contained in:
Damien George 2019-04-19 17:38:27 +10:00
parent 8402c26cfa
commit 27d22d8712
1 changed files with 13 additions and 7 deletions

View File

@ -503,22 +503,28 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
chrs += mp_print_strn(print, str, prec, flags, fill, width);
break;
}
case 'd': {
mp_int_t val;
if (long_arg) {
val = va_arg(args, long int);
} else {
val = va_arg(args, int);
}
chrs += mp_print_int(print, val, 1, 10, 'a', flags, fill, width);
break;
}
case 'u':
chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 10, 'a', flags, fill, width);
break;
case 'd':
chrs += mp_print_int(print, va_arg(args, int), 1, 10, 'a', flags, fill, width);
break;
case 'x':
case 'X': {
char fmt_c = *fmt - 'X' + 'A';
int base = 16 - ((*fmt + 1) & 6); // maps char u/x/X to base 10/16/16
char fmt_c = (*fmt & 0xf0) - 'P' + 'A'; // maps char u/x/X to char a/a/A
mp_uint_t val;
if (long_arg) {
val = va_arg(args, unsigned long int);
} else {
val = va_arg(args, unsigned int);
}
chrs += mp_print_int(print, val, 0, 16, fmt_c, flags, fill, width);
chrs += mp_print_int(print, val, 0, base, fmt_c, flags, fill, width);
break;
}
case 'p':