diff options
author | Michael W. Hudson <mwh@python.net> | 2002-12-05 21:32:32 (GMT) |
---|---|---|
committer | Michael W. Hudson <mwh@python.net> | 2002-12-05 21:32:32 (GMT) |
commit | a69c030c15a49418b9735cf971a31a511459281b (patch) | |
tree | 6b7c988728d04c985a3d12d9933cd631eeb3e41d /Objects/listobject.c | |
parent | 7bc2e1dad72bbad11e2df9bc2ee4b6d25dcc90a3 (diff) | |
download | cpython-a69c030c15a49418b9735cf971a31a511459281b.zip cpython-a69c030c15a49418b9735cf971a31a511459281b.tar.gz cpython-a69c030c15a49418b9735cf971a31a511459281b.tar.bz2 |
The final tweaks before closing
[ 633152 ] list slice ass ignores subtypes of list
Allow arbitrary sequences on the RHS of extended slices.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 3e3b4d7..25372d3 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2238,33 +2238,36 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } else { /* assign slice */ - PyObject **garbage, *ins; + PyObject **garbage, *ins, *seq; int cur, i; - if (!PyList_Check(value)) { - PyErr_Format(PyExc_TypeError, - "must assign list (not \"%.200s\") to slice", - value->ob_type->tp_name); - return -1; + /* protect against a[::-1] = a */ + if (self == (PyListObject*)value) { + seq = list_slice((PyListObject*)value, 0, + PyList_GET_SIZE(value)); + } + else { + char msg[256]; + PyOS_snprintf(msg, sizeof(msg), + "must assign sequence (not \"%.200s\") to extended slice", + value->ob_type->tp_name); + seq = PySequence_Fast(value, msg); + if (!seq) + return -1; } - if (PyList_GET_SIZE(value) != slicelength) { + if (PySequence_Fast_GET_SIZE(seq) != slicelength) { PyErr_Format(PyExc_ValueError, - "attempt to assign list of size %d to extended slice of size %d", - PyList_Size(value), slicelength); + "attempt to assign sequence of size %d to extended slice of size %d", + PySequence_Fast_GET_SIZE(seq), + slicelength); + Py_DECREF(seq); return -1; } - if (!slicelength) + if (!slicelength) { + Py_DECREF(seq); return 0; - - /* protect against a[::-1] = a */ - if (self == (PyListObject*)value) { - value = list_slice((PyListObject*)value, 0, - PyList_GET_SIZE(value)); - } - else { - Py_INCREF(value); } garbage = (PyObject**) @@ -2274,7 +2277,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) cur += step, i++) { garbage[i] = PyList_GET_ITEM(self, cur); - ins = PyList_GET_ITEM(value, i); + ins = PySequence_Fast_GET_ITEM(seq, i); Py_INCREF(ins); PyList_SET_ITEM(self, cur, ins); } @@ -2284,7 +2287,7 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value) } PyMem_FREE(garbage); - Py_DECREF(value); + Py_DECREF(seq); return 0; } |