Skip to content

Commit 0a4eb4d

Browse files
stinosdpgeorge
authored andcommitted
py/mpprint: Fix printing of 64bit integers for 64bit windows builds
This makes all tests pass again for 64bit windows builds which would previously fail for anything printing ranges (builtin_range/unpack1) because they were printed as range( ld, ld ). This is done by reusing the mp_vprintf implementation for MICROPY_OBJ_REPR_D for 64bit windows builds (both msvc and mingw-w64) since the format specifier used for 64bit integers is also %lld, or %llu for the unsigned version. Note these specifiers used to be fetched from inttypes.h, which is the C99 way of working with printf/scanf in a portable way, but mingw-w64 wants to be backwards compatible with older MS C runtimes and uses the non-portable %I64i instead of %lld in inttypes.h, so remove the use of said header again in mpconfig.h and define the specifiers manually.
1 parent b613364 commit 0a4eb4d

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

py/mpconfig.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,8 @@ typedef double mp_float_t;
909909
#define UINT_FMT "%lu"
910910
#define INT_FMT "%ld"
911911
#elif defined(_WIN64)
912-
#include <inttypes.h>
913-
#define UINT_FMT "%"PRIu64
914-
#define INT_FMT "%"PRId64
912+
#define UINT_FMT "%llu"
913+
#define INT_FMT "%lld"
915914
#else
916915
// Archs where mp_int_t == int
917916
#define UINT_FMT "%u"

py/mpprint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
529529
// Because 'l' is eaten above, another 'l' means %ll. We need to support
530530
// this length specifier for OBJ_REPR_D (64-bit NaN boxing).
531531
// TODO Either enable this unconditionally, or provide a specific config var.
532-
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
532+
#if (MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D) || defined(_WIN64)
533533
case 'l': {
534534
unsigned long long int arg_value = va_arg(args, unsigned long long int);
535535
++fmt;

0 commit comments

Comments
 (0)