>From 3701658a6ae874972a7e41e1e9632782f84534d6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 18 Nov 2019 22:41:09 +0100 Subject: [PATCH 2/2] stdint: Define [u]intptr_t correctly on 64-bit native Windows. * lib/stdint.in.h (gl_intptr_t, gl_uintptr_t, INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX): Consider _WIN64. * tests/test-stdint.c: Verify that [u]intptr_t is large enough to hold a pointer. --- ChangeLog | 8 ++++++++ lib/stdint.in.h | 25 ++++++++++++++++++------- tests/test-stdint.c | 2 ++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 803dcd1..5c8eed1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2019-11-18 Bruno Haible + stdint: Define [u]intptr_t correctly on 64-bit native Windows. + * lib/stdint.in.h (gl_intptr_t, gl_uintptr_t, INTPTR_MIN, INTPTR_MAX, + UINTPTR_MAX): Consider _WIN64. + * tests/test-stdint.c: Verify that [u]intptr_t is large enough to hold + a pointer. + +2019-11-18 Bruno Haible + stdint: Fix value of WINT_MAX when we override wint_t. * lib/stdint.in.h (WINT_MIN, WINT_MAX): Don't override a second time when GNULIB_OVERRIDES_WINT_T is 1. diff --git a/lib/stdint.in.h b/lib/stdint.in.h index e965c4a..37c15fc 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h @@ -308,12 +308,17 @@ typedef gl_uint_fast32_t gl_uint_fast16_t; _findclose in . */ # if !((defined __KLIBC__ && defined _INTPTR_T_DECLARED) \ || (defined __MINGW32__ && defined _INTPTR_T_DEFINED && defined _UINTPTR_T_DEFINED)) -# undef intptr_t -# undef uintptr_t +# undef intptr_t +# undef uintptr_t +# ifdef _WIN64 +typedef long long int gl_intptr_t; +typedef unsigned long long int gl_uintptr_t; +# else typedef long int gl_intptr_t; typedef unsigned long int gl_uintptr_t; -# define intptr_t gl_intptr_t -# define uintptr_t gl_uintptr_t +# endif +# define intptr_t gl_intptr_t +# define uintptr_t gl_uintptr_t # endif /* 7.18.1.5. Greatest-width integer types */ @@ -490,9 +495,15 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t) # undef INTPTR_MIN # undef INTPTR_MAX # undef UINTPTR_MAX -# define INTPTR_MIN LONG_MIN -# define INTPTR_MAX LONG_MAX -# define UINTPTR_MAX ULONG_MAX +# ifdef _WIN64 +# define INTPTR_MIN LLONG_MIN +# define INTPTR_MAX LLONG_MAX +# define UINTPTR_MAX ULLONG_MAX +# else +# define INTPTR_MIN LONG_MIN +# define INTPTR_MAX LONG_MAX +# define UINTPTR_MAX ULONG_MAX +# endif /* 7.18.2.5. Limits of greatest-width integer types */ diff --git a/tests/test-stdint.c b/tests/test-stdint.c index a87830b..057d5e3 100644 --- a/tests/test-stdint.c +++ b/tests/test-stdint.c @@ -217,12 +217,14 @@ err or; /* 7.18.2.4. Limits of integer types capable of holding object pointers */ intptr_t g[3] = { 17, INTPTR_MIN, INTPTR_MAX }; +verify (sizeof (void *) <= sizeof (intptr_t)); verify (TYPE_MINIMUM (intptr_t) == INTPTR_MIN); verify (TYPE_MAXIMUM (intptr_t) == INTPTR_MAX); verify_same_types (INTPTR_MIN, (intptr_t) 0 + 0); verify_same_types (INTPTR_MAX, (intptr_t) 0 + 0); uintptr_t h[2] = { 17, UINTPTR_MAX }; +verify (sizeof (void *) <= sizeof (uintptr_t)); verify (TYPE_MAXIMUM (uintptr_t) == UINTPTR_MAX); verify_same_types (UINTPTR_MAX, (uintptr_t) 0 + 0); -- 2.7.4