mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +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
|
||||
|
||||
#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 *
|
||||
|
|
|
@ -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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue