diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:39:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:39:52 (GMT) |
commit | 01076554b774ac7b1570d3953498263e3e9ad6ab (patch) | |
tree | e0f58b4f3dc9a9741cb49ea1c06372314fcf3393 /Modules | |
parent | 68b674c9d403906e91bb5a294449d90f2d747b8c (diff) | |
download | cpython-01076554b774ac7b1570d3953498263e3e9ad6ab.zip cpython-01076554b774ac7b1570d3953498263e3e9ad6ab.tar.gz cpython-01076554b774ac7b1570d3953498263e3e9ad6ab.tar.bz2 |
Issue #19433: test_capi: add tests on the size of some C types
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 34b95c0..7e27ec4 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -65,6 +65,45 @@ test_config(PyObject *self) } static PyObject* +test_sizeof_c_types(PyObject *self) +{ +#define CHECK_SIZEOF(EXPECTED, TYPE) \ + if (EXPECTED != sizeof(TYPE)) { \ + PyErr_Format(TestError, \ + "sizeof(%s) = %u instead of %u", \ + #TYPE, sizeof(TYPE), EXPECTED); \ + return (PyObject*)NULL; \ + } + + /* integer types */ + CHECK_SIZEOF(1, Py_UCS1); + CHECK_SIZEOF(2, Py_UCS2); + CHECK_SIZEOF(4, Py_UCS4); +#ifdef HAVE_INT32_T + CHECK_SIZEOF(4, PY_INT32_T); +#endif +#ifdef HAVE_UINT32_T + CHECK_SIZEOF(4, PY_UINT32_T); +#endif +#ifdef HAVE_INT64_T + CHECK_SIZEOF(8, PY_INT64_T); +#endif +#ifdef HAVE_UINT64_T + CHECK_SIZEOF(8, PY_UINT64_T); +#endif + + /* pointer/size types */ + CHECK_SIZEOF(sizeof(void *), size_t); + CHECK_SIZEOF(sizeof(void *), Py_ssize_t); + + Py_INCREF(Py_None); + return Py_None; + +#undef CHECK_SIZEOF +} + + +static PyObject* test_list_api(PyObject *self) { PyObject* list; @@ -2783,6 +2822,7 @@ static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, {"raise_memoryerror", (PyCFunction)raise_memoryerror, METH_NOARGS}, {"test_config", (PyCFunction)test_config, METH_NOARGS}, + {"test_sizeof_c_types", (PyCFunction)test_sizeof_c_types, METH_NOARGS}, {"test_datetime_capi", test_datetime_capi, METH_NOARGS}, {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS}, {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS}, |