bug-gnulib
[Top][All Lists]
Advanced

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

limits-h: Define LONG_BIT correctly on Haiku/x86_64


From: Bruno Haible
Subject: limits-h: Define LONG_BIT correctly on Haiku/x86_64
Date: Sat, 09 May 2020 00:30:09 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; )

On a new Haiku/x86_64, testing a POSIX testdir produces a build failure:

In file included from ../../gltests/test-limits-h.c:23:
../../gltests/../gllib/verify.h:216:41: error: static assertion failed: "verify 
((0x7fffffffffffffffL) >> ((32) - 1 - (((-0x7fffffffffffffffL - 1L)) < 0)) == 
1)"
 # define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
                                         ^~~~~~~~~~~~~~
../../gltests/../gllib/verify.h:276:20: note: in expansion of macro '_GL_VERIFY'
 # define verify(R) _GL_VERIFY (R, "verify (" #R ")", -)
                    ^~~~~~~~~~
../../gltests/test-limits-h.c:30:3: note: in expansion of macro 'verify'
   verify ((max) >> ((width) - 1 - ((min) < 0)) == 1)
   ^~~~~~
../../gltests/test-limits-h.c:51:1: note: in expansion of macro 'verify_width'
 verify_width (LONG_BIT, LONG_MIN, LONG_MAX);
 ^~~~~~~~~~~~

The reason is that LONG_BIT was defined to 32 instead of 64. This happens in
this gnulib code:

# if LONG_MAX == INT_MAX
#  define LONG_BIT 32
# else
#  define LONG_BIT 64
# endif

Here, LONG_MAX and INT_MAX were both not defined yet, so evaluated to 0
in the preprocessor directive. This is because the system's <limits.h>
does #include_next <limits.h> and thus ends up including gnulib's limits.h
recursively.

This patch fixes it.


2020-05-08  Bruno Haible  <address@hidden>

        limits-h: Define LONG_BIT correctly on Haiku/x86_64.
        * lib/limits.in.h: Define and test _GL_ALREADY_INCLUDING_LIMITS_H.

diff --git a/lib/limits.in.h b/lib/limits.in.h
index d8d1916..9103d2d 100644
--- a/lib/limits.in.h
+++ b/lib/limits.in.h
@@ -15,16 +15,32 @@
    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
 
-#ifndef _@GUARD_PREFIX@_LIMITS_H
-
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
 #endif
 @PRAGMA_COLUMNS@
 
-/* The include_next requires a split double-inclusion guard.  */
+#if defined _GL_ALREADY_INCLUDING_LIMITS_H
+/* Special invocation convention:
+   On Haiku/x86_64, we have a sequence of nested includes
+   <limits.h> -> <syslimits.h> -> <limits.h>.
+   In this situation, LONG_MAX and INT_MAX are not yet defined,
+   therefore we should not attempt to define LONG_BIT.  */
+
 #@INCLUDE_NEXT@ @NEXT_LIMITS_H@
 
+#else
+/* Normal invocation convention.  */
+
+#ifndef _@GUARD_PREFIX@_LIMITS_H
+
+# define _GL_ALREADY_INCLUDING_LIMITS_H
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_LIMITS_H@
+
+# undef _GL_ALREADY_INCLUDING_LIMITS_H
+
 #ifndef _@GUARD_PREFIX@_LIMITS_H
 #define _@GUARD_PREFIX@_LIMITS_H
 
@@ -102,3 +118,4 @@
 
 #endif /* _@GUARD_PREFIX@_LIMITS_H */
 #endif /* _@GUARD_PREFIX@_LIMITS_H */
+#endif




reply via email to

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