[Python-checkins] cpython: array module stores the typecode in a char, instead of Py_UNICODE

victor.stinner python-checkins at python.org
Fri Sep 30 00:54:00 CEST 2011


http://hg.python.org/cpython/rev/7042a83f37e6
changeset:   72540:7042a83f37e6
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Fri Sep 30 00:03:59 2011 +0200
summary:
  array module stores the typecode in a char, instead of Py_UNICODE

files:
  Modules/arraymodule.c |  35 ++++++++++++++----------------
  1 files changed, 16 insertions(+), 19 deletions(-)


diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -22,7 +22,7 @@
  * functions aren't visible yet.
  */
 struct arraydescr {
-    Py_UNICODE typecode;
+    char typecode;
     int itemsize;
     PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
     int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
@@ -1510,7 +1510,7 @@
 {
     Py_UNICODE *ustr;
     Py_ssize_t n;
-    Py_UNICODE typecode;
+    char typecode;
 
     if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n))
         return NULL;
@@ -1545,7 +1545,7 @@
 static PyObject *
 array_tounicode(arrayobject *self, PyObject *unused)
 {
-    Py_UNICODE typecode;
+    char typecode;
     typecode = self->ob_descr->typecode;
     if ((typecode != 'u')) {
         PyErr_SetString(PyExc_ValueError,
@@ -1642,7 +1642,7 @@
  * be found.
  */
 static enum machine_format_code
-typecode_to_mformat_code(int typecode)
+typecode_to_mformat_code(char typecode)
 {
 #ifdef WORDS_BIGENDIAN
     const int is_big_endian = 1;
@@ -1721,7 +1721,7 @@
         intsize = sizeof(PY_LONG_LONG);
         is_signed = 0;
         break;
-#endif 
+#endif
     default:
         return UNKNOWN_FORMAT;
     }
@@ -1752,7 +1752,7 @@
  * NULL is returned to indicate a failure.
  */
 static PyObject *
-make_array(PyTypeObject *arraytype, Py_UNICODE typecode, PyObject *items)
+make_array(PyTypeObject *arraytype, char typecode, PyObject *items)
 {
     PyObject *new_args;
     PyObject *array_obj;
@@ -1761,7 +1761,7 @@
     assert(arraytype != NULL);
     assert(items != NULL);
 
-    typecode_obj = PyUnicode_FromUnicode(&typecode, 1);
+    typecode_obj = PyUnicode_FromOrdinal(typecode);
     if (typecode_obj == NULL)
         return NULL;
 
@@ -1791,17 +1791,14 @@
     PyObject *items;
     PyObject *converted_items;
     PyObject *result;
-    int typecode_int;
-    Py_UNICODE typecode;
+    int typecode;
     enum machine_format_code mformat_code;
     struct arraydescr *descr;
 
     if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor",
-                    &arraytype, &typecode_int, &mformat_code, &items))
+                    &arraytype, &typecode, &mformat_code, &items))
         return NULL;
 
-    typecode = (Py_UNICODE)typecode_int;
-
     if (!PyType_Check(arraytype)) {
         PyErr_Format(PyExc_TypeError,
             "first argument must a type object, not %.200s",
@@ -1815,7 +1812,7 @@
         return NULL;
     }
     for (descr = descriptors; descr->typecode != '\0'; descr++) {
-        if (descr->typecode == typecode)
+        if ((int)descr->typecode == typecode)
             break;
     }
     if (descr->typecode == '\0') {
@@ -1837,9 +1834,9 @@
     }
 
     /* Fast path: No decoding has to be done. */
-    if (mformat_code == typecode_to_mformat_code(typecode) ||
+    if (mformat_code == typecode_to_mformat_code((char)typecode) ||
         mformat_code == UNKNOWN_FORMAT) {
-        return make_array(arraytype, typecode, items);
+        return make_array(arraytype, (char)typecode, items);
     }
 
     /* Slow path: Decode the byte string according to the given machine
@@ -1985,7 +1982,7 @@
         return NULL;
     }
 
-    result = make_array(arraytype, typecode, converted_items);
+    result = make_array(arraytype, (char)typecode, converted_items);
     Py_DECREF(converted_items);
     return result;
 }
@@ -2074,8 +2071,8 @@
 static PyObject *
 array_get_typecode(arrayobject *a, void *closure)
 {
-    Py_UNICODE tc = a->ob_descr->typecode;
-    return PyUnicode_FromUnicode(&tc, 1);
+    char typecode = a->ob_descr->typecode;
+    return PyUnicode_FromOrdinal(typecode);
 }
 
 static PyObject *
@@ -2147,7 +2144,7 @@
 static PyObject *
 array_repr(arrayobject *a)
 {
-    Py_UNICODE typecode;
+    char typecode;
     PyObject *s, *v = NULL;
     Py_ssize_t len;
 

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


More information about the Python-checkins mailing list