summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-09-26 21:49:22 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-09-26 21:49:22 (GMT)
commit60320cb3e4fa0d77ae5f8634d83de497bba003f6 (patch)
treeab3e84cb632dae602140ad8392170c7392930699
parent8a1b689e85a367c1a5f0bcbdcc7cd28e3f20d162 (diff)
downloadcpython-60320cb3e4fa0d77ae5f8634d83de497bba003f6.zip
cpython-60320cb3e4fa0d77ae5f8634d83de497bba003f6.tar.gz
cpython-60320cb3e4fa0d77ae5f8634d83de497bba003f6.tar.bz2
#3946 fix PyObject_CheckBuffer on a memoryview object
reviewed by Antoine
-rw-r--r--Lib/test/test_builtin.py1
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/abstract.c6
3 files changed, 6 insertions, 3 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index f8d4ae0..7175b80 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -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)
diff --git a/Misc/NEWS b/Misc/NEWS
index 36240ed..294c183 100644
--- 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.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 39cb803..aee20d6 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -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;
}