diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-09-07 18:06:17 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-09-07 18:06:17 (GMT) |
commit | a9296e7f3be4d6c22271b25c86467ff867c63bbb (patch) | |
tree | b5f2db17acd82ff33b61cb25d069e12b01f23516 /Modules | |
parent | 2195d537b37c1bc12759c6ed85aba2846e7ab574 (diff) | |
download | cpython-a9296e7f3be4d6c22271b25c86467ff867c63bbb.zip cpython-a9296e7f3be4d6c22271b25c86467ff867c63bbb.tar.gz cpython-a9296e7f3be4d6c22271b25c86467ff867c63bbb.tar.bz2 |
require C99 bool
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/cfield.c | 14 | ||||
-rw-r--r-- | Modules/_struct.c | 17 |
2 files changed, 8 insertions, 23 deletions
diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 06835cc..782336d 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -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 * diff --git a/Modules/_struct.c b/Modules/_struct.c index a601f03..0820961 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -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}, |