krb5 commit: Add configure checks for portability assumptions

Tom Yu tlyu at mit.edu
Mon Feb 9 15:07:08 EST 2015


https://github.com/krb5/krb5/commit/5e54fa769d1b04ccf0d904164e897d081051647f
commit 5e54fa769d1b04ccf0d904164e897d081051647f
Author: Tom Yu <tlyu at mit.edu>
Date:   Mon Feb 9 15:02:20 2015 -0500

    Add configure checks for portability assumptions
    
    Check a few portability assumptions:
    
    * Integers are two's complement.  Testing that the bitwise complement
      of the representation of -1 is zero is sufficient, because C99
      6.2.6.2 only allows sign and magnitude, one's complement, and two's
      complement as representations.
    
    * Integer values with sign bit one and value bits zero are valid and
      not trap representations.  C99 6.2.6.2 allows such a value to be a
      trap representation.  Testing that the declared integer value bounds
      are asymmetric in magnitude is sufficient.
    
    * Conversion of an unsigned integer value that is not representable in
      the corresponding signed type preserves the bit pattern.  C99
      6.3.1.3 says this is implementation-defined, or raises an
      implementation-defined signal.  Exhaustively checking for the
      desired behavior is prohibitive, so this spot check will have to do.
    
    * Bytes are 8 bits

 src/configure.in |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/configure.in b/src/configure.in
index 58e6e54..1a79ee2 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -22,6 +22,40 @@ AC_SUBST(KRB5_VERSION)
 
 AC_REQUIRE_CPP
 
+AC_CACHE_CHECK([whether integers are two's complement],
+  [krb5_cv_ints_twos_compl],
+  [AC_COMPILE_IFELSE(
+    [AC_LANG_BOOL_COMPILE_TRY(
+[#include <limits.h>
+],
+	[/* Basic two's complement check */
+	  ~(-1) == 0 && ~(-1L) == 0L &&
+	  /* Check that values with sign bit 1 and value bits 0 are valid */
+	  -(INT_MIN + 1) == INT_MAX && -(LONG_MIN + 1) == LONG_MAX &&
+	  /* Check that unsigned-to-signed conversions preserve bit patterns */
+	  (int)((unsigned int)INT_MAX + 1) == INT_MIN &&
+	  (long)((unsigned long)LONG_MAX + 1) == LONG_MIN])],
+    [krb5_cv_ints_twos_compl=yes],
+    [krb5_cv_ints_twos_compl=no])])
+
+if test "$krb5_cv_ints_twos_compl" = "no"; then
+  AC_MSG_ERROR([integers are not two's complement])
+fi
+
+AC_CACHE_CHECK([whether CHAR_BIT is 8],
+  [krb5_cv_char_bit_8],
+  [AC_PREPROC_IFELSE([AC_LANG_SOURCE(
+[[#include <limits.h>
+#if CHAR_BIT != 8
+  #error CHAR_BIT != 8
+#endif
+]])],
+    [krb5_cv_char_bit_8=yes], [krb5_cv_char_bit_8=no])])
+
+if test "$krb5_cv_char_bit_8" = "no"; then
+  AC_MSG_ERROR([CHAR_BIT is not 8])
+fi
+
 AC_CACHE_CHECK(if va_copy is available, krb5_cv_va_copy,
 [AC_LINK_IFELSE([AC_LANG_SOURCE([
 #include <stdarg.h>


More information about the cvs-krb5 mailing list