bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rewritten inttypes module


From: Paul Eggert
Subject: Re: rewritten inttypes module
Date: Mon, 28 Aug 2006 13:46:09 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Bruno Haible <address@hidden> writes:

> If our replacement <stdint.h> includes simply <inttypes.h>, not
> @ABSOLUTE_INTTYPES_H@, then a simple
>           #include <stdint.h>
> will do the wrong thing: It will
>
>    - start including our stdint.h,
>    - include the system's stdint.h,
>    - start including our inttypes.h,
>      - include the system's inttypes.h,
>      - include our stdint.h, but this has no effect due to the 
> double-inclusion
>        guard,
>      - go on testing various macros like UINT32_MAX or INT64_MAX
>        which have not been defined yet!
>    - end including our inttypes.h,
>    - define the various *_MIN and *_MAX macros
>    - end including our stdint.h.

Thanks for explaining it.  If you don't mind, I'd like to fix the
problem in a different way, so that programs that use the stdint
module but not the inttypes module don't need to find the absolute
name of <inttypes.h>.  It seems a bit cleaner to me to have
the inttypes module be the only module that needs to figure out
the absolute name of <inttypes.h>.  I installed the following
to do that:

2006-08-28  Paul Eggert  <address@hidden>

        * lib/inttypes_.h [defined _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H]:
        Include @ABSOLUTE_INTTYPES_H@ if available, but do nothing else.
        * lib/stdint_.h (_GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H): Define
        just before including <inttypes.h>, to avoid circular inclusion.
        * m4/inttypes.m4 (gl_INTTYPES_H): Move ABSOLUTE_INTTYPES_H code here...
        * m4/stdint.m4 (gl_STDINT_H): ... from here.  This undoes the most
        recent change to stdint.m4, since we're now addressing the problem in a
        different way.
        * modules/stdint (Makefile.am): Do not substitute ABSOLUTE_INTTYPES_H.

Index: lib/inttypes_.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/inttypes_.h,v
retrieving revision 1.2
diff -p -u -r1.2 inttypes_.h
--- lib/inttypes_.h     28 Aug 2006 16:57:52 -0000      1.2
+++ lib/inttypes_.h     28 Aug 2006 20:36:22 -0000
@@ -16,7 +16,16 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
-#ifndef INTTYPES_H
+/* Include the original <inttypes.h> if it exists, and if this file
+   has not been included yet or if this file includes gnulib stdint.h
+   which in turn includes this file.  */
+#if ! defined INTTYPES_H || defined _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
+# if @HAVE_INTTYPES_H@
+#  include @ABSOLUTE_INTTYPES_H@
+# endif
+#endif
+
+#if ! defined INTTYPES_H && ! defined _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
 #define INTTYPES_H
 
 /*
@@ -24,10 +33,6 @@
  * <http://www.opengroup.org/susv3xbd/inttypes.h.html>
  */
 
-/* Include the original <inttypes.h> if it exists.  */
-#if @HAVE_INTTYPES_H@
-# include @ABSOLUTE_INTTYPES_H@
-#endif
 /* Include <stdint.h> or the gnulib replacement.  */
 #include <stdint.h>
 /* Get CHAR_BIT.  */
Index: lib/stdint_.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/stdint_.h,v
retrieving revision 1.32
diff -p -u -r1.32 stdint_.h
--- lib/stdint_.h       28 Aug 2006 12:54:47 -0000      1.32
+++ lib/stdint_.h       28 Aug 2006 20:36:22 -0000
@@ -62,7 +62,9 @@
   /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
      int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
      <inttypes.h> also defines intptr_t and uintptr_t.  */
-# include @ABSOLUTE_INTTYPES_H@
+# define _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
+# include <inttypes.h>
+# undef _GL_JUST_INCLUDE_ABSOLUTE_INTTYPES_H
 #elif @HAVE_SYS_INTTYPES_H@
   /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
      the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX.  */
Index: m4/inttypes.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/inttypes.m4,v
retrieving revision 1.11
diff -p -u -r1.11 inttypes.m4
--- m4/inttypes.m4      28 Aug 2006 16:57:51 -0000      1.11
+++ m4/inttypes.m4      28 Aug 2006 20:36:22 -0000
@@ -1,4 +1,4 @@
-# inttypes.m4 serial 2
+# inttypes.m4 serial 3
 dnl Copyright (C) 2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -135,6 +135,15 @@ const char *l = /* implicit string conca
     INTTYPES_H=''
   else
 
+    dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
+    if test $ac_cv_header_inttypes_h = yes; then
+      gl_ABSOLUTE_HEADER([inttypes.h])
+      ABSOLUTE_INTTYPES_H=\"$gl_cv_absolute_inttypes_h\"
+    else
+      ABSOLUTE_INTTYPES_H=\"no/such/file/inttypes.h\"
+    fi
+    AC_SUBST([ABSOLUTE_INTTYPES_H])
+
     PRIPTR_PREFIX=
     if test -n "$STDINT_H"; then
       dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
Index: m4/stdint.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/stdint.m4,v
retrieving revision 1.21
diff -p -u -r1.21 stdint.m4
--- m4/stdint.m4        28 Aug 2006 12:54:47 -0000      1.21
+++ m4/stdint.m4        28 Aug 2006 20:36:22 -0000
@@ -1,4 +1,4 @@
-# stdint.m4 serial 19
+# stdint.m4 serial 18
 dnl Copyright (C) 2001-2002, 2004-2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -32,14 +32,10 @@ AC_DEFUN([gl_STDINT_H],
   dnl Check for <inttypes.h>.
   dnl AC_INCLUDES_DEFAULT defines $ac_cv_header_inttypes_h.
   if test $ac_cv_header_inttypes_h = yes; then
-    gl_ABSOLUTE_HEADER([inttypes.h])
-    ABSOLUTE_INTTYPES_H=\"$gl_cv_absolute_inttypes_h\"
     HAVE_INTTYPES_H=1
   else
-    ABSOLUTE_INTTYPES_H=\"no/such/file/inttypes.h\"
     HAVE_INTTYPES_H=0
   fi
-  AC_SUBST([ABSOLUTE_INTTYPES_H])
   AC_SUBST([HAVE_INTTYPES_H])
 
   dnl Check for <sys/types.h>.
Index: modules/stdint
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/stdint,v
retrieving revision 1.10
diff -p -u -r1.10 stdint
--- modules/stdint      28 Aug 2006 12:54:47 -0000      1.10
+++ modules/stdint      28 Aug 2006 20:36:22 -0000
@@ -29,7 +29,6 @@ stdint.h: stdint_.h
            -e 's|@''ABSOLUTE_STDINT_H''@|$(ABSOLUTE_STDINT_H)|g' \
            -e 's/@''HAVE_SYS_TYPES_H''@/$(HAVE_SYS_TYPES_H)/g' \
            -e 's/@''HAVE_INTTYPES_H''@/$(HAVE_INTTYPES_H)/g' \
-           -e 's|@''ABSOLUTE_INTTYPES_H''@|$(ABSOLUTE_INTTYPES_H)|g' \
            -e 's/@''HAVE_SYS_INTTYPES_H''@/$(HAVE_SYS_INTTYPES_H)/g' \
            -e 's/@''HAVE_SYS_BITYPES_H''@/$(HAVE_SYS_BITYPES_H)/g' \
            -e 's/@''HAVE_LONG_LONG_INT''@/$(HAVE_LONG_LONG_INT)/g' \




reply via email to

[Prev in Thread] Current Thread [Next in Thread]