From 3a4f1890986aeea9906c261c146bfaab4136a263 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 26 Feb 2009 01:21:03 +0100 Subject: [PATCH] Work around broken INT8_MAX, UINT8_MAX etc. values on HP-UX 11.23. --- ChangeLog | 8 +++++ doc/posix-headers/stdint.texi | 4 +++ m4/stdint.m4 | 72 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 597630087..5962517be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-02-25 Bruno Haible + + Work around broken INT8_MAX, UINT8_MAX etc. values on HP-UX 11.23. + * m4/stdint.m4 (gl_STDINT_H): Also check whether the expansions of + INT8_MAX, UINT8_MAX etc. contain casts to elementary types. + * doc/posix-headers/stdint.texi: Mention the HP-UX bug. + Reported by Gary V. Vaughan . + 2009-02-25 Eric Blake tests: skip fseek/ftell tests if ungetc is broken diff --git a/doc/posix-headers/stdint.texi b/doc/posix-headers/stdint.texi index 6466edc2f..d927de270 100644 --- a/doc/posix-headers/stdint.texi +++ b/doc/posix-headers/stdint.texi @@ -19,6 +19,10 @@ FreeBSD 6.2 / ia64. @item The value of @code{WINT_MAX} is incorrect on some platforms: mingw. +@item +The values of @code{INT8_MAX}, @code{UINT8_MAX} etc. are not usable in +preprocessor expressions on some platforms: +HP-UX 11.23. @end itemize Portability problems not fixed by Gnulib: diff --git a/m4/stdint.m4 b/m4/stdint.m4 index b4194c8ad..a2e8bdd62 100644 --- a/m4/stdint.m4 +++ b/m4/stdint.m4 @@ -1,4 +1,4 @@ -# stdint.m4 serial 33 +# stdint.m4 serial 34 dnl Copyright (C) 2001-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -201,7 +201,75 @@ struct s { int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1; }; ]])], - [gl_cv_header_working_stdint_h=yes])]) + [dnl Determine whether the various *_MIN, *_MAX macros are usable + dnl in preprocessor expression. We could do it by compiling a test + dnl program for each of these macros. It is faster to run a program + dnl that inspects the macro expansion. + dnl This detects a bug on HP-UX 11.23/ia64. + AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[ +#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */ +#define __STDC_CONSTANT_MACROS 1 /* to make it work also in C++ mode */ +#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */ +#include +] +gl_STDINT_INCLUDES +[ +#include +#include +#define MVAL(macro) MVAL1(macro) +#define MVAL1(expression) #expression +static const char *macro_values[] = + { +#ifdef INT8_MAX + MVAL (INT8_MAX), +#endif +#ifdef INT16_MAX + MVAL (INT16_MAX), +#endif +#ifdef INT32_MAX + MVAL (INT32_MAX), +#endif +#ifdef INT64_MAX + MVAL (INT64_MAX), +#endif +#ifdef UINT8_MAX + MVAL (UINT8_MAX), +#endif +#ifdef UINT16_MAX + MVAL (UINT16_MAX), +#endif +#ifdef UINT32_MAX + MVAL (UINT32_MAX), +#endif +#ifdef UINT64_MAX + MVAL (UINT64_MAX), +#endif + NULL + }; +]], [[ + const char **mv; + for (mv = macro_values; *mv != NULL; mv++) + { + const char *value = *mv; + /* Test whether it looks like a cast expression. */ + if (strncmp (value, "((unsigned int)"/*)*/, 15) == 0 + || strncmp (value, "((unsigned short)"/*)*/, 17) == 0 + || strncmp (value, "((unsigned char)"/*)*/, 16) == 0 + || strncmp (value, "((int)"/*)*/, 6) == 0 + || strncmp (value, "((signed short)"/*)*/, 15) == 0 + || strncmp (value, "((signed char)"/*)*/, 14) == 0) + return 1; + } + return 0; +]])], + [gl_cv_header_working_stdint_h=yes], + [], + [dnl When cross-compiling, assume it works. + gl_cv_header_working_stdint_h=yes + ]) + ]) + ]) fi if test "$gl_cv_header_working_stdint_h" = yes; then STDINT_H= -- 2.11.0