[Python-checkins] r88550 - in python/branches/py3k: Lib/test/test_capi.py Misc/NEWS Modules/_testcapimodule.c Objects/memoryobject.c

antoine.pitrou python-checkins at python.org
Thu Feb 24 21:50:49 CET 2011


Author: antoine.pitrou
Date: Thu Feb 24 21:50:49 2011
New Revision: 88550

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



Modified:
   python/branches/py3k/Lib/test/test_capi.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_testcapimodule.c
   python/branches/py3k/Objects/memoryobject.c

Modified: python/branches/py3k/Lib/test/test_capi.py
==============================================================================
--- python/branches/py3k/Lib/test/test_capi.py	(original)
+++ python/branches/py3k/Lib/test/test_capi.py	Thu Feb 24 21:50:49 2011
@@ -50,6 +50,8 @@
                          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):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Feb 24 21:50:49 2011
@@ -10,6 +10,9 @@
 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').
 

Modified: python/branches/py3k/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k/Modules/_testcapimodule.c	(original)
+++ python/branches/py3k/Modules/_testcapimodule.c	Thu Feb 24 21:50:49 2011
@@ -2231,6 +2231,15 @@
     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 @@
     {"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 */
 };

Modified: python/branches/py3k/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k/Objects/memoryobject.c	(original)
+++ python/branches/py3k/Objects/memoryobject.c	Thu Feb 24 21:50:49 2011
@@ -75,6 +75,11 @@
 {
     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)


More information about the Python-checkins mailing list