]> granicus.if.org Git - python/commitdiff
Merged revisions 84408-84409 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 1 Sep 2010 21:17:34 +0000 (21:17 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 1 Sep 2010 21:17:34 +0000 (21:17 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84408 | antoine.pitrou | 2010-09-01 23:14:16 +0200 (mer., 01 sept. 2010) | 4 lines

  Issue #9737: Fix a crash when trying to delete a slice or an item from
  a memoryview object.
........
  r84409 | antoine.pitrou | 2010-09-01 23:14:46 +0200 (mer., 01 sept. 2010) | 3 lines

  Fix a compilation warning
........

Lib/test/test_memoryview.py
Misc/NEWS
Objects/memoryobject.c

index 2240740bfc1b199a56b44d9106feb440d764a111..611f57da043fe62d57253fa2ac82d0e8607873ad 100644 (file)
@@ -117,6 +117,15 @@ class AbstractMemoryTests:
         m = None
         self.assertEquals(sys.getrefcount(b), oldrefcount)
 
+    def test_delitem(self):
+        for tp in self._types:
+            b = tp(self._source)
+            m = self._view(b)
+            with self.assertRaises(TypeError):
+                del m[1]
+            with self.assertRaises(TypeError):
+                del m[1:4]
+
     def test_tobytes(self):
         for tp in self._types:
             m = self._view(tp(self._source))
index 6d5d8896e8282dc6326e2d01b456a5513a161545..e1ff17a293f190d16f5fae69e31f0eb6bc0927a3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7.1?
 Core and Builtins
 -----------------
 
+- Issue #9737: Fix a crash when trying to delete a slice or an item from
+  a memoryview object.
+
 - Restore GIL in nis_cat in case of error.
 
 - Issue #9688: __basicsize__ and __itemsize__ must be accessed as Py_ssize_t.
index ad16bb2a389f1ed8ca481f20e5ea1bd5978ac353..4997fcc6c965e4bec45ddf90db59142498438cec 100644 (file)
@@ -179,7 +179,7 @@ _indirect_copy_nd(char *dest, Py_buffer *view, char fort)
     int k;
     Py_ssize_t elements;
     char *ptr;
-    void (*func)(int, Py_ssize_t *, Py_ssize_t *);
+    void (*func)(int, Py_ssize_t *, const Py_ssize_t *);
 
     if (view->ndim > PY_SSIZE_T_MAX / sizeof(Py_ssize_t)) {
         PyErr_NoMemory();
@@ -639,6 +639,11 @@ memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value)
             "cannot modify read-only memory");
         return -1;
     }
+    if (value == NULL) {
+        PyErr_SetString(PyExc_TypeError,
+                        "cannot delete memory");
+        return -1;
+    }
     if (view->ndim != 1) {
         PyErr_SetNone(PyExc_NotImplementedError);
         return -1;