]> 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:08 +0000 (22:28 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 5 Mar 2007 22:28:08 +0000 (22:28 +0000)
sq_ass_slice instead of the sq_slice slot.

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

index 208201cf78586cec7fd86a07979f823f8cbdb52e..1c0b366cc3c91962689be68ff8149a12e66a5510 100644 (file)
@@ -4206,6 +4206,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()
@@ -4301,6 +4314,7 @@ def test_main():
     test_init()
     methodwrapper()
     notimplemented()
+    test_assign_slice()
 
     from test import test_descr
     run_doctest(test_descr, verbosity=True)
index c59a15a612295675ce79392cec46e3bdcb86057c..1141ecf3ad2c7a540a772c59f9a3f23d2a58b852 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Patch #1674228: when assigning a slice (old-style), check for the
+  sq_ass_slice instead of the sq_slice slot.
+
 - When printing an unraisable error, don't print exceptions. before the name.
   This duplicates the behavior whening normally printing exceptions.
 
index 3a87052d99b576c877de9a74050870a1f5f9f42f..63efd4ee958d7eefcd5338ec6423e30b86a1960b 100644 (file)
@@ -3927,7 +3927,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;