]> granicus.if.org Git - python/commitdiff
Patch #1610575: Add support for _Bool to struct.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 21 Jan 2007 09:33:07 +0000 (09:33 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 21 Jan 2007 09:33:07 +0000 (09:33 +0000)
Doc/lib/libstruct.tex
Lib/test/test_struct.py
Misc/NEWS
Modules/_struct.c
configure
configure.in
pyconfig.h.in

index 026968cb1c11ae3db4d82e56b402acee36273ace..539e9372fe8cd4f4b2ca44dc3e7c9f4cde39b61e 100644 (file)
@@ -50,14 +50,15 @@ C and Python values should be obvious given their types:
   \lineiv{c}{\ctype{char}}{string of length 1}{}
   \lineiv{b}{\ctype{signed char}}{integer}{}
   \lineiv{B}{\ctype{unsigned char}}{integer}{}
+  \lineiv{t}{\ctype{_Bool}}{bool}{(1)}
   \lineiv{h}{\ctype{short}}{integer}{}
   \lineiv{H}{\ctype{unsigned short}}{integer}{}
   \lineiv{i}{\ctype{int}}{integer}{}
   \lineiv{I}{\ctype{unsigned int}}{long}{}
   \lineiv{l}{\ctype{long}}{integer}{}
   \lineiv{L}{\ctype{unsigned long}}{long}{}
-  \lineiv{q}{\ctype{long long}}{long}{(1)}
-  \lineiv{Q}{\ctype{unsigned long long}}{long}{(1)}
+  \lineiv{q}{\ctype{long long}}{long}{(2)}
+  \lineiv{Q}{\ctype{unsigned long long}}{long}{(2)}
   \lineiv{f}{\ctype{float}}{float}{}
   \lineiv{d}{\ctype{double}}{float}{}
   \lineiv{s}{\ctype{char[]}}{string}{}
@@ -70,6 +71,11 @@ Notes:
 
 \begin{description}
 \item[(1)]
+  The \character{t} conversion code corresponds to the \ctype{_Bool} type
+  defined by C99. If this type is not available, it is simulated using a
+  \ctype{char}. In standard mode, it is always represented by one byte.
+  \versionadded{2.6}
+\item[(2)]
   The \character{q} and \character{Q} conversion codes are available in
   native mode only if the platform C compiler supports C \ctype{long long},
   or, on Windows, \ctype{__int64}.  They are always available in standard
@@ -118,6 +124,12 @@ example, the Alpha and Merced processors use 64-bit pointer values,
 meaning a Python long integer will be used to hold the pointer; other
 platforms use 32-bit pointers and will use a Python integer.
 
+For the \character{t} format character, the return value is either
+\constant{True} or \constant{False}. When packing, the truth value
+of the argument object is used. Either 0 or 1 in the native or standard
+bool representation will be packed, and any non-zero value will be True
+when unpacking.
+
 By default, C numbers are represented in the machine's native format
 and byte order, and properly aligned by skipping pad bytes if
 necessary (according to the rules used by the C compiler).
@@ -151,6 +163,7 @@ for any type (so you have to use pad bytes);
 \ctype{long long} (\ctype{__int64} on Windows) is 8 bytes;
 \ctype{float} and \ctype{double} are 32-bit and 64-bit
 IEEE floating point numbers, respectively.
+\ctype{_Bool} is 1 byte.
 
 Note the difference between \character{@} and \character{=}: both use
 native byte order, but the size and alignment of the latter is
index 0144a0fb552f7db9e18b2851a65f1948ded3b91a..b6a3e0bf97b4277b88eba6f5c5628c4dfe40b3f9 100644 (file)
@@ -84,8 +84,8 @@ sz = struct.calcsize('i')
 if sz * 3 != struct.calcsize('iii'):
     raise TestFailed, 'inconsistent sizes'
 
-fmt = 'cbxxxxxxhhhhiillffd'
-fmt3 = '3c3b18x12h6i6l6f3d'
+fmt = 'cbxxxxxxhhhhiillffdt'
+fmt3 = '3c3b18x12h6i6l6f3d3t'
 sz = struct.calcsize(fmt)
 sz3 = struct.calcsize(fmt3)
 if sz * 3 != sz3:
@@ -108,19 +108,21 @@ i = 65535
 l = 65536
 f = 3.1415
 d = 3.1415
+t = True
 
 for prefix in ('', '@', '<', '>', '=', '!'):
-    for format in ('xcbhilfd', 'xcBHILfd'):
+    for format in ('xcbhilfdt', 'xcBHILfdt'):
         format = prefix + format
         if verbose:
             print "trying:", format
-        s = struct.pack(format, c, b, h, i, l, f, d)
-        cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s)
+        s = struct.pack(format, c, b, h, i, l, f, d, t)
+        cp, bp, hp, ip, lp, fp, dp, tp = struct.unpack(format, s)
         if (cp != c or bp != b or hp != h or ip != i or lp != l or
-            int(100 * fp) != int(100 * f) or int(100 * dp) != int(100 * d)):
+            int(100 * fp) != int(100 * f) or int(100 * dp) != int(100 * d) or
+                       tp != t):
             # ^^^ calculate only to two decimal places
             raise TestFailed, "unpack/pack not transitive (%s, %s)" % (
-                str(format), str((cp, bp, hp, ip, lp, fp, dp)))
+                str(format), str((cp, bp, hp, ip, lp, fp, dp, tp)))
 
 # Test some of the new features in detail
 
@@ -158,6 +160,11 @@ tests = [
     ('f', -2.0, '\300\000\000\000', '\000\000\000\300', 0),
     ('d', -2.0, '\300\000\000\000\000\000\000\000',
                '\000\000\000\000\000\000\000\300', 0),
+       ('t', 0, '\0', '\0', 0),
+       ('t', 3, '\1', '\1', 1),
+       ('t', True, '\1', '\1', 0),
+       ('t', [], '\0', '\0', 1),
+       ('t', (1,), '\1', '\1', 1),
 ]
 
 for fmt, arg, big, lil, asy in tests:
@@ -612,3 +619,50 @@ def test_pack_into_fn():
 test_unpack_from()
 test_pack_into()
 test_pack_into_fn()
+
+def test_bool():
+       for prefix in tuple("<>!=")+('',):
+               false = (), [], [], '', 0
+               true = [1], 'test', 5, -1, 0xffffffffL+1, 0xffffffff/2
+               
+               falseFormat = prefix + 't' * len(false)
+               if verbose:
+                       print 'trying bool pack/unpack on', false, 'using format', falseFormat
+               packedFalse = struct.pack(falseFormat, *false)
+               unpackedFalse = struct.unpack(falseFormat, packedFalse)
+               
+               trueFormat = prefix + 't' * len(true)
+               if verbose:
+                       print 'trying bool pack/unpack on', true, 'using format', trueFormat
+               packedTrue = struct.pack(trueFormat, *true)
+               unpackedTrue = struct.unpack(trueFormat, packedTrue)
+               
+               if len(true) != len(unpackedTrue):
+                       raise TestFailed('unpacked true array is not of same size as input')
+               if len(false) != len(unpackedFalse):
+                       raise TestFailed('unpacked false array is not of same size as input')
+               
+               for t in unpackedFalse:
+                       if t is not False:
+                               raise TestFailed('%r did not unpack as False' % t)
+               for t in unpackedTrue:
+                       if t is not True:
+                               raise TestFailed('%r did not unpack as false' % t)
+       
+               if prefix and verbose:
+                       print 'trying size of bool with format %r' % (prefix+'t')
+               packed = struct.pack(prefix+'t', 1)
+               
+               if len(packed) != struct.calcsize(prefix+'t'):
+                       raise TestFailed('packed length is not equal to calculated size')
+               
+               if len(packed) != 1 and prefix:
+                       raise TestFailed('encoded bool is not one byte: %r' % packed)
+               elif not prefix and verbose:
+                       print 'size of bool in native format is %i' % (len(packed))
+               
+               for c in '\x01\x7f\xff\x0f\xf0':
+                       if struct.unpack('>t', c)[0] is not True:
+                               raise TestFailed('%c did not unpack as True' % c)
+
+test_bool()
index 60aa8c23bb932cbfd54a7ec18ce27962590ec7cc..4bb5b10e6a00ba5e7a98437ef9caefde9ceacb44 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -313,6 +313,9 @@ Library
 Extension Modules
 -----------------
 
+- Patch #1610575: The struct module now supports the 't' code, for
+  C99 _Bool.
+
 - Patch #1635058: ensure that htonl and friends never accept or
   return negative numbers, per the underlying C implementation.
 
index 22d0e030cfcfe828847d3af2dff86dd37b5c5f51..059d98867da0449a1beb45e7a5f9b4de1f97bed4 100644 (file)
@@ -104,6 +104,15 @@ typedef struct { char c; PY_LONG_LONG x; } s_long_long;
 #define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(PY_LONG_LONG))
 #endif
 
+#ifdef HAVE_C99_BOOL
+#define BOOL_TYPE _Bool
+typedef struct { char c; _Bool x; } s_bool;
+#define BOOL_ALIGN (sizeof(s_bool) - sizeof(BOOL_TYPE))
+#else
+#define BOOL_TYPE char
+#define BOOL_ALIGN 0
+#endif
+
 #define STRINGIFY(x)    #x
 
 #ifdef __powerc
@@ -535,6 +544,15 @@ nu_ulonglong(const char *p, const formatdef *f)
 
 #endif
 
+static PyObject *
+nu_bool(const char *p, const formatdef *f)
+{
+       BOOL_TYPE x;
+       memcpy((char *)&x, p, sizeof x);
+       return PyBool_FromLong(x != 0);
+}
+
+
 static PyObject *
 nu_float(const char *p, const formatdef *f)
 {
@@ -711,6 +729,16 @@ np_ulonglong(char *p, PyObject *v, const formatdef *f)
 }
 #endif
 
+
+static int
+np_bool(char *p, PyObject *v, const formatdef *f)
+{
+       BOOL_TYPE y; 
+       y = PyObject_IsTrue(v);
+       memcpy(p, (char *)&y, sizeof y);
+       return 0;
+}
+
 static int
 np_float(char *p, PyObject *v, const formatdef *f)
 {
@@ -771,6 +799,7 @@ static formatdef native_table[] = {
        {'q',   sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_longlong, np_longlong},
        {'Q',   sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
 #endif
+       {'t',   sizeof(BOOL_TYPE),      BOOL_ALIGN,     nu_bool,        np_bool},
        {'f',   sizeof(float),  FLOAT_ALIGN,    nu_float,       np_float},
        {'d',   sizeof(double), DOUBLE_ALIGN,   nu_double,      np_double},
        {'P',   sizeof(void *), VOID_P_ALIGN,   nu_void_p,      np_void_p},
@@ -865,6 +894,14 @@ bu_double(const char *p, const formatdef *f)
        return unpack_double(p, 0);
 }
 
+static PyObject *
+bu_bool(const char *p, const formatdef *f)
+{
+       char x;
+       memcpy((char *)&x, p, sizeof x);
+       return PyBool_FromLong(x != 0);
+}
+
 static int
 bp_int(char *p, PyObject *v, const formatdef *f)
 {
@@ -969,6 +1006,15 @@ bp_double(char *p, PyObject *v, const formatdef *f)
        return _PyFloat_Pack8(x, (unsigned char *)p, 0);
 }
 
+static int
+bp_bool(char *p, PyObject *v, const formatdef *f)
+{
+       char y; 
+       y = PyObject_IsTrue(v);
+       memcpy(p, (char *)&y, sizeof y);
+       return 0;
+}
+
 static formatdef bigendian_table[] = {
        {'x',   1,              0,              NULL},
 #ifdef PY_STRUCT_OVERFLOW_MASKING
@@ -990,6 +1036,7 @@ static formatdef bigendian_table[] = {
        {'L',   4,              0,              bu_uint,        bp_uint},
        {'q',   8,              0,              bu_longlong,    bp_longlong},
        {'Q',   8,              0,              bu_ulonglong,   bp_ulonglong},
+       {'t',   1,              0,              bu_bool,        bp_bool},
        {'f',   4,              0,              bu_float,       bp_float},
        {'d',   8,              0,              bu_double,      bp_double},
        {0}
@@ -1208,6 +1255,8 @@ static formatdef lilendian_table[] = {
        {'L',   4,              0,              lu_uint,        lp_uint},
        {'q',   8,              0,              lu_longlong,    lp_longlong},
        {'Q',   8,              0,              lu_ulonglong,   lp_ulonglong},
+       {'t',   1,              0,              bu_bool,        bp_bool}, /* Std rep not endian dep,
+               but potentially different from native rep -- reuse bx_bool funcs. */
        {'f',   4,              0,              lu_float,       lp_float},
        {'d',   8,              0,              lu_double,      lp_double},
        {0}
index a2c80fbd0bd034fa13be1d53f74137022199b26d..ac97264df215f1c7db63768b3de0545f23ae3802 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 52456 .
+# From configure.in Revision: 52843 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.6.
 #
@@ -10142,6 +10142,479 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+fi
+
+echo "$as_me:$LINENO: checking for _Bool support" >&5
+echo $ECHO_N "checking for _Bool support... $ECHO_C" >&6
+have_c99_bool=no
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+_Bool x; x = (_Bool)0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_C99_BOOL 1
+_ACEOF
+
+  have_c99_bool=yes
+
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $have_c99_bool" >&5
+echo "${ECHO_T}$have_c99_bool" >&6
+if test "$have_c99_bool" = yes ; then
+echo "$as_me:$LINENO: checking for _Bool" >&5
+echo $ECHO_N "checking for _Bool... $ECHO_C" >&6
+if test "${ac_cv_type__Bool+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+if ((_Bool *) 0)
+  return 0;
+if (sizeof (_Bool))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type__Bool=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_type__Bool=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5
+echo "${ECHO_T}$ac_cv_type__Bool" >&6
+
+echo "$as_me:$LINENO: checking size of _Bool" >&5
+echo $ECHO_N "checking size of _Bool... $ECHO_C" >&6
+if test "${ac_cv_sizeof__Bool+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$ac_cv_type__Bool" = yes; then
+  # The cast to unsigned long works around a bug in the HP C Compiler
+  # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
+  # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
+  # This bug is HP SR number 8606223364.
+  if test "$cross_compiling" = yes; then
+  # Depending upon the size, compute the lo and hi bounds.
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) >= 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_lo=0 ac_mid=0
+  while :; do
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_hi=$ac_mid; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr $ac_mid + 1`
+                   if test $ac_lo -le $ac_mid; then
+                     ac_lo= ac_hi=
+                     break
+                   fi
+                   ac_mid=`expr 2 '*' $ac_mid + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) < 0)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_hi=-1 ac_mid=-1
+  while :; do
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) >= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_lo=$ac_mid; break
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_hi=`expr '(' $ac_mid ')' - 1`
+                      if test $ac_mid -le $ac_hi; then
+                        ac_lo= ac_hi=
+                        break
+                      fi
+                      ac_mid=`expr 2 '*' $ac_mid`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo= ac_hi=
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+# Binary search between lo and hi bounds.
+while test "x$ac_lo" != "x$ac_hi"; do
+  ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo`
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+static int test_array [1 - 2 * !(((long) (sizeof (_Bool))) <= $ac_mid)];
+test_array [0] = 0
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_hi=$ac_mid
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_lo=`expr '(' $ac_mid ')' + 1`
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+case $ac_lo in
+?*) ac_cv_sizeof__Bool=$ac_lo;;
+'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (_Bool), 77
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; } ;;
+esac
+else
+  if test "$cross_compiling" = yes; then
+  { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run test program while cross compiling
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+long longval () { return (long) (sizeof (_Bool)); }
+unsigned long ulongval () { return (long) (sizeof (_Bool)); }
+#include <stdio.h>
+#include <stdlib.h>
+int
+main ()
+{
+
+  FILE *f = fopen ("conftest.val", "w");
+  if (! f)
+    exit (1);
+  if (((long) (sizeof (_Bool))) < 0)
+    {
+      long i = longval ();
+      if (i != ((long) (sizeof (_Bool))))
+       exit (1);
+      fprintf (f, "%ld\n", i);
+    }
+  else
+    {
+      unsigned long i = ulongval ();
+      if (i != ((long) (sizeof (_Bool))))
+       exit (1);
+      fprintf (f, "%lu\n", i);
+    }
+  exit (ferror (f) || fclose (f) != 0);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_sizeof__Bool=`cat conftest.val`
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+{ { echo "$as_me:$LINENO: error: cannot compute sizeof (_Bool), 77
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute sizeof (_Bool), 77
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
+rm -f conftest.val
+else
+  ac_cv_sizeof__Bool=0
+fi
+fi
+echo "$as_me:$LINENO: result: $ac_cv_sizeof__Bool" >&5
+echo "${ECHO_T}$ac_cv_sizeof__Bool" >&6
+cat >>confdefs.h <<_ACEOF
+#define SIZEOF__BOOL $ac_cv_sizeof__Bool
+_ACEOF
+
+
 fi
 
 echo "$as_me:$LINENO: checking for uintptr_t" >&5
index 1259ccfebcc3a18bf1a55c4bb1efdb70cae7165e..1a11ec2ca287cac37719f7f4e0390ccf84bb4f8e 100644 (file)
@@ -1218,6 +1218,17 @@ if test "$have_long_long" = yes ; then
 AC_CHECK_SIZEOF(long long, 8)
 fi
 
+AC_MSG_CHECKING(for _Bool support)
+have_c99_bool=no
+AC_TRY_COMPILE([], [_Bool x; x = (_Bool)0;], [
+  AC_DEFINE(HAVE_C99_BOOL, 1, [Define this if you have the type _Bool.]) 
+  have_c99_bool=yes
+])
+AC_MSG_RESULT($have_c99_bool)
+if test "$have_c99_bool" = yes ; then
+AC_CHECK_SIZEOF(_Bool, 1)
+fi
+
 AC_CHECK_TYPES(uintptr_t, 
    [AC_CHECK_SIZEOF(uintptr_t, 4)], 
    [], [#ifdef HAVE_STDINT_H
index 6407871725821006d57bfe412dbaed97a7d99012..2e8f4bff01e9fd7056ad443827133969f28211b1 100644 (file)
@@ -64,6 +64,9 @@
 /* Define if pthread_sigmask() does not work on your system. */
 #undef HAVE_BROKEN_PTHREAD_SIGMASK
 
+/* Define this if you have the type _Bool. */
+#undef HAVE_C99_BOOL
+
 /* Define to 1 if you have the `chown' function. */
 #undef HAVE_CHOWN
 
 /* The size of a `wchar_t', as computed by sizeof. */
 #undef SIZEOF_WCHAR_T
 
+/* The size of a `_Bool', as computed by sizeof. */
+#undef SIZEOF__BOOL
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS