[Python-3000-checkins] r66630 - in python/branches/py3k: Lib/test/test_builtin.py Misc/NEWS Objects/abstract.c

benjamin.peterson python-3000-checkins at python.org
Fri Sep 26 23:49:23 CEST 2008


Author: benjamin.peterson
Date: Fri Sep 26 23:49:22 2008
New Revision: 66630

Log:
#3946 fix PyObject_CheckBuffer on a memoryview object

Modified:
   python/branches/py3k/Lib/test/test_builtin.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/abstract.c

Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k/Lib/test/test_builtin.py	Fri Sep 26 23:49:22 2008
@@ -242,6 +242,7 @@
         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)

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Sep 26 23:49:22 2008
@@ -12,6 +12,8 @@
 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.
 

Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c	(original)
+++ python/branches/py3k/Objects/abstract.c	Fri Sep 26 23:49:22 2008
@@ -268,16 +268,16 @@
 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;
 }
 


More information about the Python-3000-checkins mailing list