]> granicus.if.org Git - python/commitdiff
Patch #1674228: when assigning a slice (old-style), check for the
authorGeorg Brandl <georg@python.org>
Mon, 5 Mar 2007 22:28:13 +0000 (22:28 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 5 Mar 2007 22:28:13 +0000 (22:28 +0000)
sq_ass_slice instead of the sq_slice slot.
 (backport from rev. 54139)

Lib/test/test_descr.py
Misc/NEWS
Python/ceval.c

index b108395269267da366e27503bd1547edb3951353..0981f095246fbd57d20ebf11556c7cef81f5cc10 100644 (file)
@@ -4143,6 +4143,19 @@ def notimplemented():
                 check(iexpr, c, N1)
                 check(iexpr, c, N2)
 
+def test_assign_slice():
+    # ceval.c's assign_slice used to check for
+    # tp->tp_as_sequence->sq_slice instead of
+    # tp->tp_as_sequence->sq_ass_slice
+
+    class C(object):
+        def __setslice__(self, start, stop, value):
+            self.value = value
+
+    c = C()
+    c[1:2] = 3
+    vereq(c.value, 3)
+
 def test_main():
     weakref_segfault() # Must be first, somehow
     wrapper_segfault()
@@ -4239,6 +4252,7 @@ def test_main():
     test_init()
     methodwrapper()
     notimplemented()
+    test_assign_slice()
 
     if verbose: print "All OK"
 
index c3fabfeaeafa755ce2c19cf46be2326d0043d3e2..7960f07165d97de45fe5f22628baa9a4ed13a38c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.5.1c1?
 Core and builtins
 -----------------
 
+- Patch #1674228: when assigning a slice (old-style), check for the
+  sq_ass_slice instead of the sq_slice slot.
+
 - Bug #1669182: prevent crash when trying to print an unraisable error
   from a string exception.
 
index 1ee0f3b603986138b98682f80d4d322ee8118d9f..690b2be9b7ebcf2afb191ffec9c3ee5d626e1822 100644 (file)
@@ -3926,7 +3926,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
        PyTypeObject *tp = u->ob_type;
        PySequenceMethods *sq = tp->tp_as_sequence;
 
-       if (sq && sq->sq_slice && ISINDEX(v) && ISINDEX(w)) {
+       if (sq && sq->sq_ass_slice && ISINDEX(v) && ISINDEX(w)) {
                Py_ssize_t ilow = 0, ihigh = PY_SSIZE_T_MAX;
                if (!_PyEval_SliceIndex(v, &ilow))
                        return -1;