Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60320cb

Browse files
committed
#3946 fix PyObject_CheckBuffer on a memoryview object
reviewed by Antoine
1 parent 8a1b689 commit 60320cb

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/test/test_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def test_compile(self):
242242
compile(source='pass', filename='?', mode='exec')
243243
compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
244244
compile('pass', '?', dont_inherit=1, mode='exec')
245+
compile(memoryview(b"text"), "name", "exec")
245246
self.assertRaises(TypeError, compile)
246247
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
247248
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 3.0 release candidate 2
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #3946: PyObject_CheckReadBuffer crashed on a memoryview object.
16+
1517
- Issue #1688: On Windows, the input() prompt was not correctly displayed if it
1618
contains non-ascii characters.
1719

Objects/abstract.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,16 @@ int
268268
PyObject_CheckReadBuffer(PyObject *obj)
269269
{
270270
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
271+
Py_buffer view;
271272

272273
if (pb == NULL ||
273274
pb->bf_getbuffer == NULL)
274275
return 0;
275-
if ((*pb->bf_getbuffer)(obj, NULL, PyBUF_SIMPLE) == -1) {
276+
if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE) == -1) {
276277
PyErr_Clear();
277278
return 0;
278279
}
279-
if (*pb->bf_releasebuffer != NULL)
280-
(*pb->bf_releasebuffer)(obj, NULL);
280+
PyBuffer_Release(&view);
281281
return 1;
282282
}
283283

0 commit comments

Comments
 (0)