require C99 bool

This commit is contained in:
Benjamin Peterson 2016-09-07 11:06:17 -07:00
parent 2195d537b3
commit a9296e7f3b
6 changed files with 21 additions and 85 deletions

View File

@ -711,14 +711,6 @@ vBOOL_get(void *ptr, Py_ssize_t size)
}
#endif
#ifdef HAVE_C99_BOOL
#define BOOL_TYPE _Bool
#else
#define BOOL_TYPE char
#undef SIZEOF__BOOL
#define SIZEOF__BOOL 1
#endif
static PyObject *
bool_set(void *ptr, PyObject *value, Py_ssize_t size)
{
@ -726,10 +718,10 @@ bool_set(void *ptr, PyObject *value, Py_ssize_t size)
case -1:
return NULL;
case 0:
*(BOOL_TYPE *)ptr = 0;
*(_Bool *)ptr = 0;
_RET(value);
default:
*(BOOL_TYPE *)ptr = 1;
*(_Bool *)ptr = 1;
_RET(value);
}
}
@ -737,7 +729,7 @@ bool_set(void *ptr, PyObject *value, Py_ssize_t size)
static PyObject *
bool_get(void *ptr, Py_ssize_t size)
{
return PyBool_FromLong((long)*(BOOL_TYPE *)ptr);
return PyBool_FromLong((long)*(_Bool *)ptr);
}
static PyObject *

View File

@ -60,6 +60,7 @@ typedef struct { char c; float x; } st_float;
typedef struct { char c; double x; } st_double;
typedef struct { char c; void *x; } st_void_p;
typedef struct { char c; size_t x; } st_size_t;
typedef struct { char c; _Bool x; } st_bool;
#define SHORT_ALIGN (sizeof(st_short) - sizeof(short))
#define INT_ALIGN (sizeof(st_int) - sizeof(int))
@ -68,21 +69,13 @@ typedef struct { char c; size_t x; } st_size_t;
#define DOUBLE_ALIGN (sizeof(st_double) - sizeof(double))
#define VOID_P_ALIGN (sizeof(st_void_p) - sizeof(void *))
#define SIZE_T_ALIGN (sizeof(st_size_t) - sizeof(size_t))
#define BOOL_ALIGN (sizeof(st_bool) - sizeof(_Bool))
/* We can't support q and Q in native mode unless the compiler does;
in std mode, they're 8 bytes on all platforms. */
typedef struct { char c; long long x; } s_long_long;
#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(long long))
#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
#ifdef __powerc
#pragma options align=reset
#endif
@ -480,7 +473,7 @@ nu_ulonglong(const char *p, const formatdef *f)
static PyObject *
nu_bool(const char *p, const formatdef *f)
{
BOOL_TYPE x;
_Bool x;
memcpy((char *)&x, p, sizeof x);
return PyBool_FromLong(x != 0);
}
@ -695,7 +688,7 @@ static int
np_bool(char *p, PyObject *v, const formatdef *f)
{
int y;
BOOL_TYPE x;
_Bool x;
y = PyObject_IsTrue(v);
if (y < 0)
return -1;
@ -774,7 +767,7 @@ static const formatdef native_table[] = {
{'N', sizeof(size_t), SIZE_T_ALIGN, nu_size_t, np_size_t},
{'q', sizeof(long long), LONG_LONG_ALIGN, nu_longlong, np_longlong},
{'Q', sizeof(long long), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
{'?', sizeof(BOOL_TYPE), BOOL_ALIGN, nu_bool, np_bool},
{'?', sizeof(_Bool), BOOL_ALIGN, nu_bool, np_bool},
{'e', sizeof(short), SHORT_ALIGN, nu_halffloat, np_halffloat},
{'f', sizeof(float), FLOAT_ALIGN, nu_float, np_float},
{'d', sizeof(double), DOUBLE_ALIGN, nu_double, np_double},

View File

@ -1115,11 +1115,7 @@ get_native_fmtchar(char *result, const char *fmt)
case 'n': case 'N': size = sizeof(Py_ssize_t); break;
case 'f': size = sizeof(float); break;
case 'd': size = sizeof(double); break;
#ifdef HAVE_C99_BOOL
case '?': size = sizeof(_Bool); break;
#else
case '?': size = sizeof(char); break;
#endif
case 'P': size = sizeof(void *); break;
}
@ -1162,11 +1158,7 @@ get_native_fmtstr(const char *fmt)
case 'N': RETURN("N");
case 'f': RETURN("f");
case 'd': RETURN("d");
#ifdef HAVE_C99_BOOL
case '?': RETURN("?");
#else
case '?': RETURN("?");
#endif
case 'P': RETURN("P");
}
@ -1673,11 +1665,7 @@ unpack_single(const char *ptr, const char *fmt)
case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld;
/* boolean */
#ifdef HAVE_C99_BOOL
case '?': UNPACK_SINGLE(ld, ptr, _Bool); goto convert_bool;
#else
case '?': UNPACK_SINGLE(ld, ptr, char); goto convert_bool;
#endif
/* unsigned integers */
case 'H': UNPACK_SINGLE(lu, ptr, unsigned short); goto convert_lu;
@ -1843,11 +1831,7 @@ pack_single(char *ptr, PyObject *item, const char *fmt)
ld = PyObject_IsTrue(item);
if (ld < 0)
return -1; /* preserve original error */
#ifdef HAVE_C99_BOOL
PACK_SINGLE(ptr, ld, _Bool);
#else
PACK_SINGLE(ptr, ld, char);
#endif
break;
/* bytes object */
@ -2634,11 +2618,7 @@ unpack_cmp(const char *p, const char *q, char fmt,
case 'l': CMP_SINGLE(p, q, long); return equal;
/* boolean */
#ifdef HAVE_C99_BOOL
case '?': CMP_SINGLE(p, q, _Bool); return equal;
#else
case '?': CMP_SINGLE(p, q, char); return equal;
#endif
/* unsigned integers */
case 'H': CMP_SINGLE(p, q, unsigned short); return equal;

42
configure vendored
View File

@ -777,6 +777,7 @@ infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
@ -888,6 +889,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1140,6 +1142,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1277,7 +1288,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir
libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@ -1430,6 +1441,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@ -8482,33 +8494,6 @@ _ACEOF
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _Bool support" >&5
$as_echo_n "checking for _Bool support... " >&6; }
have_c99_bool=no
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
_Bool x; x = (_Bool)0;
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
$as_echo "#define HAVE_C99_BOOL 1" >>confdefs.h
have_c99_bool=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_c99_bool" >&5
$as_echo "$have_c99_bool" >&6; }
if test "$have_c99_bool" = yes ; then
# The cast to long int 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]];'.
@ -8542,7 +8527,6 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
fi
# The cast to long int works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects

View File

@ -2128,17 +2128,7 @@ if test "$have_long_double" = yes ; then
AC_CHECK_SIZEOF(long double, 16)
fi
AC_MSG_CHECKING(for _Bool support)
have_c99_bool=no
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[_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_SIZEOF(off_t, [], [
#ifdef HAVE_SYS_TYPES_H

View File

@ -107,9 +107,6 @@
/* Has builtin atomics */
#undef HAVE_BUILTIN_ATOMIC
/* Define this if you have the type _Bool. */
#undef HAVE_C99_BOOL
/* Define to 1 if you have the 'chflags' function. */
#undef HAVE_CHFLAGS