]> granicus.if.org Git - python/commitdiff
Merged revisions 88550 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 24 Feb 2011 20:53:48 +0000 (20:53 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 24 Feb 2011 20:53:48 +0000 (20:53 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r88550 | antoine.pitrou | 2011-02-24 21:50:49 +0100 (jeu., 24 févr. 2011) | 4 lines

  Issue #11286: Raise a ValueError from calling PyMemoryView_FromBuffer with
  a buffer struct having a NULL data pointer.
........

Lib/test/test_capi.py
Misc/NEWS
Modules/_testcapimodule.c
Objects/memoryobject.c

index 32f8fae25af441f44f215d58eb921b6f4ce866b8..529a2a5e1630595c3a4ab213c977ac48d4d3f30e 100644 (file)
@@ -50,6 +50,8 @@ class CAPITest(unittest.TestCase):
                          b'Fatal Python error:'
                          b' PyThreadState_Get: no current thread')
 
+    def test_memoryview_from_NULL_pointer(self):
+        self.assertRaises(ValueError, _testcapi.make_memoryview_from_NULL_pointer)
 
 @unittest.skipUnless(threading, 'Threading required for this test.')
 class TestPendingCalls(unittest.TestCase):
index a7f9ba5a567d84b5d5dd65c4253068436a7194ba..e1710324511933435afe902f77083c48370d7a38 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.1?
 Core and Builtins
 -----------------
 
+- Issue #11286: Raise a ValueError from calling PyMemoryView_FromBuffer with
+  a buffer struct having a NULL data pointer.
+
 - Issue #11272: On Windows, input() strips '\r' (and not only '\n'), and
   sys.stdin uses universal newline (replace '\r\n' by '\n').
 
index f326568ea29a40cdd570c1a42cb95098205d0ce0..f19d0df5944bc853b3da24d953a7a7646f1a3719 100644 (file)
@@ -2231,6 +2231,15 @@ make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
     return PyErr_NewExceptionWithDoc(name, doc, base, dict);
 }
 
+static PyObject *
+make_memoryview_from_NULL_pointer(PyObject *self)
+{
+    Py_buffer info;
+    if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0)
+        return NULL;
+    return PyMemoryView_FromBuffer(&info);
+}
+
 /* Test that the fatal error from not having a current thread doesn't
    cause an infinite loop.  Run via Lib/test/test_capi.py */
 static PyObject *
@@ -2326,6 +2335,8 @@ static PyMethodDef TestMethods[] = {
     {"code_newempty",           code_newempty,                   METH_VARARGS},
     {"make_exception_with_doc", (PyCFunction)make_exception_with_doc,
      METH_VARARGS | METH_KEYWORDS},
+    {"make_memoryview_from_NULL_pointer", (PyCFunction)make_memoryview_from_NULL_pointer,
+     METH_NOARGS},
     {"crash_no_current_thread", (PyCFunction)crash_no_current_thread, METH_NOARGS},
     {NULL, NULL} /* sentinel */
 };
index 7782076a5b50a15dd5cd7602aa386d925525cba2..2e32b2a0e9f51c560b2f2b7d2d2cf8e758867109 100644 (file)
@@ -75,6 +75,11 @@ PyMemoryView_FromBuffer(Py_buffer *info)
 {
     PyMemoryViewObject *mview;
 
+    if (info->buf == NULL) {
+        PyErr_SetString(PyExc_ValueError,
+            "cannot make memory view from a buffer with a NULL data pointer");
+        return NULL;
+    }
     mview = (PyMemoryViewObject *)
         PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type);
     if (mview == NULL)