summaryrefslogtreecommitdiff
path: root/py/mpprint.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-07-30 12:33:44 -0700
committerGitHub <noreply@github.com>2018-07-30 12:33:44 -0700
commita6d94b68453b8535398ff0b61cd6c4a0c7f77f8b (patch)
tree8defd6392975b8145dc11f0cce9c39a4e440b32a /py/mpprint.c
parent433a29bb70d51abb84c77a911ced43c6ff14706e (diff)
parentb1006170f1dcfa3a9499ef31c19c8f20736b136a (diff)
Merge pull request #1068 from dhalbert/micropython-25ae98f-merge
Micropython 25ae98f merge
Diffstat (limited to 'py/mpprint.c')
-rw-r--r--py/mpprint.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/py/mpprint.c b/py/mpprint.c
index a569ef793..c2e65301c 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -446,11 +446,16 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
}
}
- // parse long specifiers (current not used)
- //bool long_arg = false;
+ // parse long specifiers (only for LP64 model where they make a difference)
+ #ifndef __LP64__
+ const
+ #endif
+ bool long_arg = false;
if (*fmt == 'l') {
++fmt;
- //long_arg = true;
+ #ifdef __LP64__
+ long_arg = true;
+ #endif
}
if (*fmt == '\0') {
@@ -505,14 +510,21 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
chrs += mp_print_int(print, va_arg(args, int), 1, 10, 'a', flags, fill, width);
break;
case 'x':
- chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 16, 'a', flags, fill, width);
- break;
- case 'X':
- chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 16, 'A', flags, fill, width);
+ case 'X': {
+ char fmt_c = *fmt - 'X' + '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);
break;
+ }
case 'p':
case 'P': // don't bother to handle upcase for 'P'
- chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 16, 'a', flags, fill, width);
+ // Use unsigned long int to work on both ILP32 and LP64 systems
+ chrs += mp_print_int(print, va_arg(args, unsigned long int), 0, 16, 'a', flags, fill, width);
break;
#if MICROPY_PY_BUILTINS_FLOAT
case 'e':