Issue #19433: test_capi: check signness of some C types

This commit is contained in:
Victor Stinner 2013-10-29 19:59:31 +01:00
parent 01076554b7
commit f866f97ca8
1 changed files with 34 additions and 10 deletions

View File

@ -67,38 +67,62 @@ test_config(PyObject *self)
static PyObject*
test_sizeof_c_types(PyObject *self)
{
#define CHECK_SIZEOF(EXPECTED, TYPE) \
#define CHECK_SIZEOF(TYPE, EXPECTED) \
if (EXPECTED != sizeof(TYPE)) { \
PyErr_Format(TestError, \
"sizeof(%s) = %u instead of %u", \
#TYPE, sizeof(TYPE), EXPECTED); \
return (PyObject*)NULL; \
}
#define IS_SIGNED(TYPE) (((TYPE)-1) < (TYPE)0)
#define CHECK_SIGNNESS(TYPE, SIGNED) \
if (IS_SIGNED(TYPE) != SIGNED) { \
PyErr_Format(TestError, \
"%s signness is, instead of %i", \
#TYPE, IS_SIGNED(TYPE), SIGNED); \
return (PyObject*)NULL; \
}
/* integer types */
CHECK_SIZEOF(1, Py_UCS1);
CHECK_SIZEOF(2, Py_UCS2);
CHECK_SIZEOF(4, Py_UCS4);
CHECK_SIZEOF(Py_UCS1, 1);
CHECK_SIZEOF(Py_UCS2, 2);
CHECK_SIZEOF(Py_UCS4, 4);
CHECK_SIGNNESS(Py_UCS1, 0);
CHECK_SIGNNESS(Py_UCS2, 0);
CHECK_SIGNNESS(Py_UCS4, 0);
#ifdef HAVE_INT32_T
CHECK_SIZEOF(4, PY_INT32_T);
CHECK_SIZEOF(PY_INT32_T, 4);
CHECK_SIGNNESS(PY_INT32_T, 1);
#endif
#ifdef HAVE_UINT32_T
CHECK_SIZEOF(4, PY_UINT32_T);
CHECK_SIZEOF(PY_UINT32_T, 4);
CHECK_SIGNNESS(PY_UINT32_T, 0);
#endif
#ifdef HAVE_INT64_T
CHECK_SIZEOF(8, PY_INT64_T);
CHECK_SIZEOF(PY_INT64_T, 8);
CHECK_SIGNNESS(PY_INT64_T, 1);
#endif
#ifdef HAVE_UINT64_T
CHECK_SIZEOF(8, PY_UINT64_T);
CHECK_SIZEOF(PY_UINT64_T, 8);
CHECK_SIGNNESS(PY_UINT64_T, 0);
#endif
/* pointer/size types */
CHECK_SIZEOF(sizeof(void *), size_t);
CHECK_SIZEOF(sizeof(void *), Py_ssize_t);
CHECK_SIZEOF(size_t, sizeof(void *));
CHECK_SIGNNESS(size_t, 0);
CHECK_SIZEOF(Py_ssize_t, sizeof(void *));
CHECK_SIGNNESS(Py_ssize_t, 1);
CHECK_SIZEOF(Py_uintptr_t, sizeof(void *));
CHECK_SIGNNESS(Py_uintptr_t, 0);
CHECK_SIZEOF(Py_intptr_t, sizeof(void *));
CHECK_SIGNNESS(Py_intptr_t, 1);
Py_INCREF(Py_None);
return Py_None;
#undef IS_SIGNED
#undef CHECK_SIGNESS
#undef CHECK_SIZEOF
}