diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-11-09 09:38:30 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-11-09 09:38:30 (GMT) |
commit | 9f0b51e4e319f5950d89bb5055bb947712ff953d (patch) | |
tree | 4fd9270007682c2e4f83b18093e488077728b093 | |
parent | 3e2b7171bf29f80c06805e60741b5b813376294e (diff) | |
download | cpython-9f0b51e4e319f5950d89bb5055bb947712ff953d.zip cpython-9f0b51e4e319f5950d89bb5055bb947712ff953d.tar.gz cpython-9f0b51e4e319f5950d89bb5055bb947712ff953d.tar.bz2 |
Issue #10359: Use Py_UNICODE for the typecode in array
And don't create non constant array, invalid in ISO C.
-rw-r--r-- | Modules/arraymodule.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 6ece49f..a4ce80d 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -22,7 +22,7 @@ struct arrayobject; /* Forward */ * functions aren't visible yet. */ struct arraydescr { - int typecode; + Py_UNICODE typecode; int itemsize; PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); @@ -1428,7 +1428,7 @@ representation."); static PyObject * array_tostring(arrayobject *self, PyObject *unused) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, + if (PyErr_WarnEx(PyExc_DeprecationWarning, "tostring() is deprecated. Use tobytes() instead.", 2) != 0) return NULL; return array_tobytes(self, unused); @@ -1680,17 +1680,16 @@ static PyObject *array_new(PyTypeObject *type, PyObject *args, PyObject *kwds); * NULL is returned to indicate a failure. */ static PyObject * -make_array(PyTypeObject *arraytype, int typecode, PyObject *items) +make_array(PyTypeObject *arraytype, Py_UNICODE typecode, PyObject *items) { PyObject *new_args; PyObject *array_obj; PyObject *typecode_obj; - Py_UNICODE typecode_str[1] = {typecode}; assert(arraytype != NULL); assert(items != NULL); - typecode_obj = PyUnicode_FromUnicode(typecode_str, 1); + typecode_obj = PyUnicode_FromUnicode(&typecode, 1); if (typecode_obj == NULL) return NULL; @@ -1720,14 +1719,17 @@ array_reconstructor(PyObject *self, PyObject *args) PyObject *items; PyObject *converted_items; PyObject *result; - int typecode; + int typecode_int; + Py_UNICODE typecode; enum machine_format_code mformat_code; struct arraydescr *descr; if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor", - &arraytype, &typecode, &mformat_code, &items)) + &arraytype, &typecode_int, &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", |