Mercurial > cpython-lru_cache-weakref
comparison Modules/arraymodule.c @ 66105:646dfdc48ca8
Issue #10359: Use Py_UNICODE for the typecode in array
And don't create non constant array, invalid in ISO C.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Tue, 09 Nov 2010 09:38:30 +0000 |
| parents | fa8b57f987c5 |
| children | 67882105dd65 |
comparison
equal
deleted
inserted
replaced
| 66104:448ab7516c0a | 66105:646dfdc48ca8 |
|---|---|
| 20 /* All possible arraydescr values are defined in the vector "descriptors" | 20 /* All possible arraydescr values are defined in the vector "descriptors" |
| 21 * below. That's defined later because the appropriate get and set | 21 * below. That's defined later because the appropriate get and set |
| 22 * functions aren't visible yet. | 22 * functions aren't visible yet. |
| 23 */ | 23 */ |
| 24 struct arraydescr { | 24 struct arraydescr { |
| 25 int typecode; | 25 Py_UNICODE typecode; |
| 26 int itemsize; | 26 int itemsize; |
| 27 PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); | 27 PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); |
| 28 int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); | 28 int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); |
| 29 char *formats; | 29 char *formats; |
| 30 int is_integer_type; | 30 int is_integer_type; |
| 1426 | 1426 |
| 1427 | 1427 |
| 1428 static PyObject * | 1428 static PyObject * |
| 1429 array_tostring(arrayobject *self, PyObject *unused) | 1429 array_tostring(arrayobject *self, PyObject *unused) |
| 1430 { | 1430 { |
| 1431 if (PyErr_WarnEx(PyExc_DeprecationWarning, | 1431 if (PyErr_WarnEx(PyExc_DeprecationWarning, |
| 1432 "tostring() is deprecated. Use tobytes() instead.", 2) != 0) | 1432 "tostring() is deprecated. Use tobytes() instead.", 2) != 0) |
| 1433 return NULL; | 1433 return NULL; |
| 1434 return array_tobytes(self, unused); | 1434 return array_tobytes(self, unused); |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1678 * | 1678 * |
| 1679 * On success, this functions returns the array object created. Otherwise, | 1679 * On success, this functions returns the array object created. Otherwise, |
| 1680 * NULL is returned to indicate a failure. | 1680 * NULL is returned to indicate a failure. |
| 1681 */ | 1681 */ |
| 1682 static PyObject * | 1682 static PyObject * |
| 1683 make_array(PyTypeObject *arraytype, int typecode, PyObject *items) | 1683 make_array(PyTypeObject *arraytype, Py_UNICODE typecode, PyObject *items) |
| 1684 { | 1684 { |
| 1685 PyObject *new_args; | 1685 PyObject *new_args; |
| 1686 PyObject *array_obj; | 1686 PyObject *array_obj; |
| 1687 PyObject *typecode_obj; | 1687 PyObject *typecode_obj; |
| 1688 Py_UNICODE typecode_str[1] = {typecode}; | |
| 1689 | 1688 |
| 1690 assert(arraytype != NULL); | 1689 assert(arraytype != NULL); |
| 1691 assert(items != NULL); | 1690 assert(items != NULL); |
| 1692 | 1691 |
| 1693 typecode_obj = PyUnicode_FromUnicode(typecode_str, 1); | 1692 typecode_obj = PyUnicode_FromUnicode(&typecode, 1); |
| 1694 if (typecode_obj == NULL) | 1693 if (typecode_obj == NULL) |
| 1695 return NULL; | 1694 return NULL; |
| 1696 | 1695 |
| 1697 new_args = PyTuple_New(2); | 1696 new_args = PyTuple_New(2); |
| 1698 if (new_args == NULL) | 1697 if (new_args == NULL) |
| 1718 { | 1717 { |
| 1719 PyTypeObject *arraytype; | 1718 PyTypeObject *arraytype; |
| 1720 PyObject *items; | 1719 PyObject *items; |
| 1721 PyObject *converted_items; | 1720 PyObject *converted_items; |
| 1722 PyObject *result; | 1721 PyObject *result; |
| 1723 int typecode; | 1722 int typecode_int; |
| 1723 Py_UNICODE typecode; | |
| 1724 enum machine_format_code mformat_code; | 1724 enum machine_format_code mformat_code; |
| 1725 struct arraydescr *descr; | 1725 struct arraydescr *descr; |
| 1726 | 1726 |
| 1727 if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor", | 1727 if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor", |
| 1728 &arraytype, &typecode, &mformat_code, &items)) | 1728 &arraytype, &typecode_int, &mformat_code, &items)) |
| 1729 return NULL; | 1729 return NULL; |
| 1730 | |
| 1731 typecode = (Py_UNICODE)typecode_int; | |
| 1730 | 1732 |
| 1731 if (!PyType_Check(arraytype)) { | 1733 if (!PyType_Check(arraytype)) { |
| 1732 PyErr_Format(PyExc_TypeError, | 1734 PyErr_Format(PyExc_TypeError, |
| 1733 "first argument must a type object, not %.200s", | 1735 "first argument must a type object, not %.200s", |
| 1734 Py_TYPE(arraytype)->tp_name); | 1736 Py_TYPE(arraytype)->tp_name); |
