From 01076554b774ac7b1570d3953498263e3e9ad6ab Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 29 Oct 2013 19:39:52 +0100 Subject: [PATCH] Issue #19433: test_capi: add tests on the size of some C types --- Modules/_testcapimodule.c | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 34b95c02a8d..7e27ec4779a 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -64,6 +64,45 @@ test_config(PyObject *self) return Py_None; } +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) { @@ -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},