mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
require C99 bool
This commit is contained in:
parent
2195d537b3
commit
a9296e7f3b
6 changed files with 21 additions and 85 deletions
|
@ -711,14 +711,6 @@ vBOOL_get(void *ptr, Py_ssize_t size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
#define BOOL_TYPE _Bool
|
|
||||||
#else
|
|
||||||
#define BOOL_TYPE char
|
|
||||||
#undef SIZEOF__BOOL
|
|
||||||
#define SIZEOF__BOOL 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
bool_set(void *ptr, PyObject *value, Py_ssize_t size)
|
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:
|
case -1:
|
||||||
return NULL;
|
return NULL;
|
||||||
case 0:
|
case 0:
|
||||||
*(BOOL_TYPE *)ptr = 0;
|
*(_Bool *)ptr = 0;
|
||||||
_RET(value);
|
_RET(value);
|
||||||
default:
|
default:
|
||||||
*(BOOL_TYPE *)ptr = 1;
|
*(_Bool *)ptr = 1;
|
||||||
_RET(value);
|
_RET(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -737,7 +729,7 @@ bool_set(void *ptr, PyObject *value, Py_ssize_t size)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
bool_get(void *ptr, Py_ssize_t size)
|
bool_get(void *ptr, Py_ssize_t size)
|
||||||
{
|
{
|
||||||
return PyBool_FromLong((long)*(BOOL_TYPE *)ptr);
|
return PyBool_FromLong((long)*(_Bool *)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -60,6 +60,7 @@ typedef struct { char c; float x; } st_float;
|
||||||
typedef struct { char c; double x; } st_double;
|
typedef struct { char c; double x; } st_double;
|
||||||
typedef struct { char c; void *x; } st_void_p;
|
typedef struct { char c; void *x; } st_void_p;
|
||||||
typedef struct { char c; size_t x; } st_size_t;
|
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 SHORT_ALIGN (sizeof(st_short) - sizeof(short))
|
||||||
#define INT_ALIGN (sizeof(st_int) - sizeof(int))
|
#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 DOUBLE_ALIGN (sizeof(st_double) - sizeof(double))
|
||||||
#define VOID_P_ALIGN (sizeof(st_void_p) - sizeof(void *))
|
#define VOID_P_ALIGN (sizeof(st_void_p) - sizeof(void *))
|
||||||
#define SIZE_T_ALIGN (sizeof(st_size_t) - sizeof(size_t))
|
#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;
|
/* We can't support q and Q in native mode unless the compiler does;
|
||||||
in std mode, they're 8 bytes on all platforms. */
|
in std mode, they're 8 bytes on all platforms. */
|
||||||
typedef struct { char c; long long x; } s_long_long;
|
typedef struct { char c; long long x; } s_long_long;
|
||||||
#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(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
|
#ifdef __powerc
|
||||||
#pragma options align=reset
|
#pragma options align=reset
|
||||||
#endif
|
#endif
|
||||||
|
@ -480,7 +473,7 @@ nu_ulonglong(const char *p, const formatdef *f)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
nu_bool(const char *p, const formatdef *f)
|
nu_bool(const char *p, const formatdef *f)
|
||||||
{
|
{
|
||||||
BOOL_TYPE x;
|
_Bool x;
|
||||||
memcpy((char *)&x, p, sizeof x);
|
memcpy((char *)&x, p, sizeof x);
|
||||||
return PyBool_FromLong(x != 0);
|
return PyBool_FromLong(x != 0);
|
||||||
}
|
}
|
||||||
|
@ -695,7 +688,7 @@ static int
|
||||||
np_bool(char *p, PyObject *v, const formatdef *f)
|
np_bool(char *p, PyObject *v, const formatdef *f)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
BOOL_TYPE x;
|
_Bool x;
|
||||||
y = PyObject_IsTrue(v);
|
y = PyObject_IsTrue(v);
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -774,7 +767,7 @@ static const formatdef native_table[] = {
|
||||||
{'N', sizeof(size_t), SIZE_T_ALIGN, nu_size_t, np_size_t},
|
{'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_longlong, np_longlong},
|
||||||
{'Q', sizeof(long long), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
|
{'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},
|
{'e', sizeof(short), SHORT_ALIGN, nu_halffloat, np_halffloat},
|
||||||
{'f', sizeof(float), FLOAT_ALIGN, nu_float, np_float},
|
{'f', sizeof(float), FLOAT_ALIGN, nu_float, np_float},
|
||||||
{'d', sizeof(double), DOUBLE_ALIGN, nu_double, np_double},
|
{'d', sizeof(double), DOUBLE_ALIGN, nu_double, np_double},
|
||||||
|
|
|
@ -1115,11 +1115,7 @@ get_native_fmtchar(char *result, const char *fmt)
|
||||||
case 'n': case 'N': size = sizeof(Py_ssize_t); break;
|
case 'n': case 'N': size = sizeof(Py_ssize_t); break;
|
||||||
case 'f': size = sizeof(float); break;
|
case 'f': size = sizeof(float); break;
|
||||||
case 'd': size = sizeof(double); break;
|
case 'd': size = sizeof(double); break;
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
case '?': size = sizeof(_Bool); break;
|
case '?': size = sizeof(_Bool); break;
|
||||||
#else
|
|
||||||
case '?': size = sizeof(char); break;
|
|
||||||
#endif
|
|
||||||
case 'P': size = sizeof(void *); break;
|
case 'P': size = sizeof(void *); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1162,11 +1158,7 @@ get_native_fmtstr(const char *fmt)
|
||||||
case 'N': RETURN("N");
|
case 'N': RETURN("N");
|
||||||
case 'f': RETURN("f");
|
case 'f': RETURN("f");
|
||||||
case 'd': RETURN("d");
|
case 'd': RETURN("d");
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
case '?': RETURN("?");
|
case '?': RETURN("?");
|
||||||
#else
|
|
||||||
case '?': RETURN("?");
|
|
||||||
#endif
|
|
||||||
case 'P': RETURN("P");
|
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;
|
case 'l': UNPACK_SINGLE(ld, ptr, long); goto convert_ld;
|
||||||
|
|
||||||
/* boolean */
|
/* boolean */
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
case '?': UNPACK_SINGLE(ld, ptr, _Bool); goto convert_bool;
|
case '?': UNPACK_SINGLE(ld, ptr, _Bool); goto convert_bool;
|
||||||
#else
|
|
||||||
case '?': UNPACK_SINGLE(ld, ptr, char); goto convert_bool;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* unsigned integers */
|
/* unsigned integers */
|
||||||
case 'H': UNPACK_SINGLE(lu, ptr, unsigned short); goto convert_lu;
|
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);
|
ld = PyObject_IsTrue(item);
|
||||||
if (ld < 0)
|
if (ld < 0)
|
||||||
return -1; /* preserve original error */
|
return -1; /* preserve original error */
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
PACK_SINGLE(ptr, ld, _Bool);
|
PACK_SINGLE(ptr, ld, _Bool);
|
||||||
#else
|
|
||||||
PACK_SINGLE(ptr, ld, char);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* bytes object */
|
/* 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;
|
case 'l': CMP_SINGLE(p, q, long); return equal;
|
||||||
|
|
||||||
/* boolean */
|
/* boolean */
|
||||||
#ifdef HAVE_C99_BOOL
|
|
||||||
case '?': CMP_SINGLE(p, q, _Bool); return equal;
|
case '?': CMP_SINGLE(p, q, _Bool); return equal;
|
||||||
#else
|
|
||||||
case '?': CMP_SINGLE(p, q, char); return equal;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* unsigned integers */
|
/* unsigned integers */
|
||||||
case 'H': CMP_SINGLE(p, q, unsigned short); return equal;
|
case 'H': CMP_SINGLE(p, q, unsigned short); return equal;
|
||||||
|
|
42
configure
vendored
42
configure
vendored
|
@ -777,6 +777,7 @@ infodir
|
||||||
docdir
|
docdir
|
||||||
oldincludedir
|
oldincludedir
|
||||||
includedir
|
includedir
|
||||||
|
runstatedir
|
||||||
localstatedir
|
localstatedir
|
||||||
sharedstatedir
|
sharedstatedir
|
||||||
sysconfdir
|
sysconfdir
|
||||||
|
@ -888,6 +889,7 @@ datadir='${datarootdir}'
|
||||||
sysconfdir='${prefix}/etc'
|
sysconfdir='${prefix}/etc'
|
||||||
sharedstatedir='${prefix}/com'
|
sharedstatedir='${prefix}/com'
|
||||||
localstatedir='${prefix}/var'
|
localstatedir='${prefix}/var'
|
||||||
|
runstatedir='${localstatedir}/run'
|
||||||
includedir='${prefix}/include'
|
includedir='${prefix}/include'
|
||||||
oldincludedir='/usr/include'
|
oldincludedir='/usr/include'
|
||||||
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
|
||||||
|
@ -1140,6 +1142,15 @@ do
|
||||||
| -silent | --silent | --silen | --sile | --sil)
|
| -silent | --silent | --silen | --sile | --sil)
|
||||||
silent=yes ;;
|
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)
|
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
|
||||||
ac_prev=sbindir ;;
|
ac_prev=sbindir ;;
|
||||||
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
|
||||||
|
@ -1277,7 +1288,7 @@ fi
|
||||||
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
|
||||||
datadir sysconfdir sharedstatedir localstatedir includedir \
|
datadir sysconfdir sharedstatedir localstatedir includedir \
|
||||||
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
|
||||||
libdir localedir mandir
|
libdir localedir mandir runstatedir
|
||||||
do
|
do
|
||||||
eval ac_val=\$$ac_var
|
eval ac_val=\$$ac_var
|
||||||
# Remove trailing slashes.
|
# Remove trailing slashes.
|
||||||
|
@ -1430,6 +1441,7 @@ Fine tuning of the installation directories:
|
||||||
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
|
||||||
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
|
||||||
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
|
||||||
|
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
|
||||||
--libdir=DIR object code libraries [EPREFIX/lib]
|
--libdir=DIR object code libraries [EPREFIX/lib]
|
||||||
--includedir=DIR C header files [PREFIX/include]
|
--includedir=DIR C header files [PREFIX/include]
|
||||||
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
--oldincludedir=DIR C header files for non-gcc [/usr/include]
|
||||||
|
@ -8482,33 +8494,6 @@ _ACEOF
|
||||||
|
|
||||||
fi
|
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
|
# 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
|
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||||
|
@ -8542,7 +8527,6 @@ cat >>confdefs.h <<_ACEOF
|
||||||
_ACEOF
|
_ACEOF
|
||||||
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The cast to long int works around a bug in the HP C Compiler
|
# 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
|
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||||
|
|
10
configure.ac
10
configure.ac
|
@ -2128,17 +2128,7 @@ if test "$have_long_double" = yes ; then
|
||||||
AC_CHECK_SIZEOF(long double, 16)
|
AC_CHECK_SIZEOF(long double, 16)
|
||||||
fi
|
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)
|
AC_CHECK_SIZEOF(_Bool, 1)
|
||||||
fi
|
|
||||||
|
|
||||||
AC_CHECK_SIZEOF(off_t, [], [
|
AC_CHECK_SIZEOF(off_t, [], [
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
|
|
|
@ -107,9 +107,6 @@
|
||||||
/* Has builtin atomics */
|
/* Has builtin atomics */
|
||||||
#undef HAVE_BUILTIN_ATOMIC
|
#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. */
|
/* Define to 1 if you have the 'chflags' function. */
|
||||||
#undef HAVE_CHFLAGS
|
#undef HAVE_CHFLAGS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue