[Python-checkins] cpython: Issue #19433: test_capi: add tests on the size of some C types

victor.stinner python-checkins at python.org
Tue Oct 29 19:46:00 CET 2013


http://hg.python.org/cpython/rev/daa1ab27b5c2
changeset:   86745:daa1ab27b5c2
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Oct 29 19:39:52 2013 +0100
summary:
  Issue #19433: test_capi: add tests on the size of some C types

files:
  Modules/_testcapimodule.c |  40 +++++++++++++++++++++++++++
  1 files changed, 40 insertions(+), 0 deletions(-)


diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -65,6 +65,45 @@
 }
 
 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 @@
     {"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},

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list