bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Keith Marshall <keith@users.osdn.me>
Subject: Re: gnulib subverts system typedef for intptr_t
Date: Mon, 18 Nov 2019 22:52:19 +0100	[thread overview]
Message-ID: <2978907.HnveO5ds4X@omega> (raw)
In-Reply-To: <2613685.cZcoHrbQqH@omega>

[-- Attachment #1: Type: text/plain, Size: 1808 bytes --]

Hi Keith,

> > I ran into this, when cross-compiling GNU gettext-0.20.1 for a mingw32
> > host; you may find details at
> > 
> >    https://osdn.net/projects/mingw/ticket/39677
> > 
> > While I can work around the compilation failure, (and the workaround
> > likely makes the MinGW.org headers more robust), I thought you may like
> > to know of the underlying issue.

With earlier versions of mingw, the configure test

  checking whether stdint.h conforms to C99...

reports 'yes', then gnulib does not redefined intptr_t, then the declaration
conflict of '_findclose' would not arise.

In other words, the issue you observed is triggered by the fact that the
mingw headers that you are using do not contain a good <stdint.h> any more.
You can find out what is wrong by looking into config.log.

Now, when I put myself into the same situation, by setting the environment
variable

  $ export gl_cv_header_working_stdint_h=no

I encounter two test failures in <stdint.h>.


The first issue is that WINT_MAX is incorrectly defined: it is defined as
  _STDINT_MAX(0, 32, 0)
but ought to be defined as
  _STDINT_MAX(0, 32, 0u)

The second issue is that intptr_t and uintptr_t are 32-bit, whereas pointers
in 64-bit native Windows are 64-bit.

I'm committing the fixes for these two failures (attached).


2019-11-18  Bruno Haible  <bruno@clisp.org>

	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.

2019-11-18  Bruno Haible  <bruno@clisp.org>

	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.


[-- Attachment #2: 0001-stdint-Fix-value-of-WINT_MAX-when-we-override-wint_t.patch --]
[-- Type: text/x-patch, Size: 2223 bytes --]

From ee1eac82e997ff1b7c8524af74a461b4822c91df Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Mon, 18 Nov 2019 22:40:36 +0100
Subject: [PATCH 1/2] 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.
---
 ChangeLog       |  6 ++++++
 lib/stdint.in.h | 24 ++++++++++++++----------
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 048335a..803dcd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2019-11-18  Bruno Haible  <bruno@clisp.org>
 
+	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.
+
+2019-11-18  Bruno Haible  <bruno@clisp.org>
+
 	vcs-to-changelog: New module.
 	* modules/vcs-to-changelog: New file.
 	* MODULES.html.sh (func_all_modules): Add it.
diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index 733fcb3..e965c4a 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -591,17 +591,21 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
    _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
 
 /* wint_t limits */
-# undef WINT_MIN
-# undef WINT_MAX
-# if @HAVE_SIGNED_WINT_T@
-#  define WINT_MIN  \
-    _STDINT_SIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
-# else
-#  define WINT_MIN  \
-    _STDINT_UNSIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
+/* If gnulib's <wchar.h> or <wctype.h> overrides wint_t, @WINT_T_SUFFIX@ is not
+   accurate, therefore use the definitions from above.  */
+# if !@GNULIB_OVERRIDES_WINT_T@
+#  undef WINT_MIN
+#  undef WINT_MAX
+#  if @HAVE_SIGNED_WINT_T@
+#   define WINT_MIN  \
+     _STDINT_SIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
+#  else
+#   define WINT_MIN  \
+     _STDINT_UNSIGNED_MIN (@BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
+#  endif
+#  define WINT_MAX  \
+    _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
 # endif
-# define WINT_MAX  \
-   _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
 
 /* 7.18.4. Macros for integer constants */
 
-- 
2.7.4


[-- Attachment #3: 0002-stdint-Define-u-intptr_t-correctly-on-64-bit-native-.patch --]
[-- Type: text/x-patch, Size: 3330 bytes --]

From 3701658a6ae874972a7e41e1e9632782f84534d6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
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  <bruno@clisp.org>
 
+	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  <bruno@clisp.org>
+
 	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 <io.h>.  */
 # 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


      reply	other threads:[~2019-11-18 21:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 18:17 gnulib subverts system typedef for intptr_t Keith Marshall
2019-11-18 13:01 ` Bruno Haible
2019-11-18 21:52   ` Bruno Haible [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2978907.HnveO5ds4X@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=keith@users.osdn.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).