mirror of https://github.com/python/cpython.git
#3946 fix PyObject_CheckBuffer on a memoryview object
reviewed by Antoine
This commit is contained in:
parent
8a1b689e85
commit
60320cb3e4
|
@ -242,6 +242,7 @@ def test_compile(self):
|
||||||
compile(source='pass', filename='?', mode='exec')
|
compile(source='pass', filename='?', mode='exec')
|
||||||
compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
|
compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
|
||||||
compile('pass', '?', dont_inherit=1, mode='exec')
|
compile('pass', '?', dont_inherit=1, mode='exec')
|
||||||
|
compile(memoryview(b"text"), "name", "exec")
|
||||||
self.assertRaises(TypeError, compile)
|
self.assertRaises(TypeError, compile)
|
||||||
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
|
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
|
||||||
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)
|
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)
|
||||||
|
|
|
@ -12,6 +12,8 @@ What's New in Python 3.0 release candidate 2
|
||||||
Core and Builtins
|
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
|
- Issue #1688: On Windows, the input() prompt was not correctly displayed if it
|
||||||
contains non-ascii characters.
|
contains non-ascii characters.
|
||||||
|
|
||||||
|
|
|
@ -268,16 +268,16 @@ int
|
||||||
PyObject_CheckReadBuffer(PyObject *obj)
|
PyObject_CheckReadBuffer(PyObject *obj)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
|
||||||
|
Py_buffer view;
|
||||||
|
|
||||||
if (pb == NULL ||
|
if (pb == NULL ||
|
||||||
pb->bf_getbuffer == NULL)
|
pb->bf_getbuffer == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if ((*pb->bf_getbuffer)(obj, NULL, PyBUF_SIMPLE) == -1) {
|
if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE) == -1) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*pb->bf_releasebuffer != NULL)
|
PyBuffer_Release(&view);
|
||||||
(*pb->bf_releasebuffer)(obj, NULL);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue