Kaydet (Commit) 9f0b51e4 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #10359: Use Py_UNICODE for the typecode in array

And don't create non constant array, invalid in ISO C.
üst 3e2b7171
...@@ -22,7 +22,7 @@ struct arrayobject; /* Forward */ ...@@ -22,7 +22,7 @@ struct arrayobject; /* Forward */
* functions aren't visible yet. * functions aren't visible yet.
*/ */
struct arraydescr { struct arraydescr {
int typecode; Py_UNICODE typecode;
int itemsize; int itemsize;
PyObject * (*getitem)(struct arrayobject *, Py_ssize_t); PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *); int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
...@@ -1680,17 +1680,16 @@ static PyObject *array_new(PyTypeObject *type, PyObject *args, PyObject *kwds); ...@@ -1680,17 +1680,16 @@ static PyObject *array_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
* NULL is returned to indicate a failure. * NULL is returned to indicate a failure.
*/ */
static PyObject * static PyObject *
make_array(PyTypeObject *arraytype, int typecode, PyObject *items) make_array(PyTypeObject *arraytype, Py_UNICODE typecode, PyObject *items)
{ {
PyObject *new_args; PyObject *new_args;
PyObject *array_obj; PyObject *array_obj;
PyObject *typecode_obj; PyObject *typecode_obj;
Py_UNICODE typecode_str[1] = {typecode};
assert(arraytype != NULL); assert(arraytype != NULL);
assert(items != NULL); assert(items != NULL);
typecode_obj = PyUnicode_FromUnicode(typecode_str, 1); typecode_obj = PyUnicode_FromUnicode(&typecode, 1);
if (typecode_obj == NULL) if (typecode_obj == NULL)
return NULL; return NULL;
...@@ -1720,14 +1719,17 @@ array_reconstructor(PyObject *self, PyObject *args) ...@@ -1720,14 +1719,17 @@ array_reconstructor(PyObject *self, PyObject *args)
PyObject *items; PyObject *items;
PyObject *converted_items; PyObject *converted_items;
PyObject *result; PyObject *result;
int typecode; int typecode_int;
Py_UNICODE typecode;
enum machine_format_code mformat_code; enum machine_format_code mformat_code;
struct arraydescr *descr; struct arraydescr *descr;
if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor", if (!PyArg_ParseTuple(args, "OCiO:array._array_reconstructor",
&arraytype, &typecode, &mformat_code, &items)) &arraytype, &typecode_int, &mformat_code, &items))
return NULL; return NULL;
typecode = (Py_UNICODE)typecode_int;
if (!PyType_Check(arraytype)) { if (!PyType_Check(arraytype)) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"first argument must a type object, not %.200s", "first argument must a type object, not %.200s",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment