]> granicus.if.org Git - python/commitdiff
#3946 fix PyObject_CheckBuffer on a memoryview object
authorBenjamin Peterson <benjamin@python.org>
Fri, 26 Sep 2008 21:49:22 +0000 (21:49 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 26 Sep 2008 21:49:22 +0000 (21:49 +0000)
reviewed by Antoine

Lib/test/test_builtin.py
Misc/NEWS
Objects/abstract.c

index f8d4ae0e44d6c1559b177586fd0d801a80aee471..7175b80c88aa3ab5fb6fd3d60e6a927e23af1e84 100644 (file)
@@ -242,6 +242,7 @@ class BuiltinTest(unittest.TestCase):
         compile(source='pass', filename='?', mode='exec')
         compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
         compile('pass', '?', dont_inherit=1, mode='exec')
+        compile(memoryview(b"text"), "name", "exec")
         self.assertRaises(TypeError, compile)
         self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
         self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)
index 36240edcf3c8010f4e76f73956eec0db7df71b6b..294c183e1c8675f8ec184ad16f01631300e8dc2d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.0 release candidate 2
 Core and Builtins
 -----------------
 
+- Issue #3946: PyObject_CheckReadBuffer crashed on a memoryview object.
+
 - Issue #1688: On Windows, the input() prompt was not correctly displayed if it
   contains non-ascii characters.
 
index 39cb8036140ff9fccc86e29a2f388012cbfcf07b..aee20d69ade0948fd72ee4caa3da5ccd3c7de9cf 100644 (file)
@@ -268,16 +268,16 @@ int
 PyObject_CheckReadBuffer(PyObject *obj)
 {
        PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
+       Py_buffer view;
 
        if (pb == NULL ||
            pb->bf_getbuffer == NULL)
                return 0;
-       if ((*pb->bf_getbuffer)(obj, NULL, PyBUF_SIMPLE) == -1) {
+       if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE) == -1) {
                PyErr_Clear();
                return 0;
        }
-       if (*pb->bf_releasebuffer != NULL)
-               (*pb->bf_releasebuffer)(obj, NULL);
+       PyBuffer_Release(&view);
        return 1;
 }