diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:59:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:59:31 (GMT) |
commit | f866f97ca8fed17cb10c0fd06b65b75b33843ff9 (patch) | |
tree | c73fe1b929551305eeeb52c992a9057a08cf4295 /Modules/_testcapimodule.c | |
parent | 01076554b774ac7b1570d3953498263e3e9ad6ab (diff) | |
download | cpython-f866f97ca8fed17cb10c0fd06b65b75b33843ff9.zip cpython-f866f97ca8fed17cb10c0fd06b65b75b33843ff9.tar.gz cpython-f866f97ca8fed17cb10c0fd06b65b75b33843ff9.tar.bz2 |
Issue #19433: test_capi: check signness of some C types
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7e27ec4..3362454 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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 } |