Commit 3014d6eb authored by Serhiy Storchaka's avatar Serhiy Storchaka Committed by GitHub

[2.7] bpo-33767: Fix improper use of SystemError by mmap.mmap objects (GH-7381) (GH-7432)

Raise TypeError instead of SystemError for unsupported operations.
(cherry picked from commit e9e39760)
Co-authored-by: default avatarZackery Spytz <zspytz@gmail.com>
parent bc3df70b
...@@ -666,6 +666,13 @@ class MmapTests(unittest.TestCase): ...@@ -666,6 +666,13 @@ class MmapTests(unittest.TestCase):
self.assertRaises(ValueError, m.write_byte, 'b') self.assertRaises(ValueError, m.write_byte, 'b')
self.assertRaises(ValueError, m.write, 'abc') self.assertRaises(ValueError, m.write, 'abc')
def test_concat_repeat_exception(self):
m = mmap.mmap(-1, 16)
with self.assertRaises(TypeError):
m + m
with self.assertRaises(TypeError):
m * 2
class LargeMmapTests(unittest.TestCase): class LargeMmapTests(unittest.TestCase):
......
The concatenation (``+``) and repetition (``*``) sequence operations now
raise :exc:`TypeError` instead of :exc:`SystemError` when performed on
:class:`mmap.mmap` objects. Patch by Zackery Spytz.
...@@ -818,24 +818,6 @@ mmap_subscript(mmap_object *self, PyObject *item) ...@@ -818,24 +818,6 @@ mmap_subscript(mmap_object *self, PyObject *item)
} }
} }
static PyObject *
mmap_concat(mmap_object *self, PyObject *bb)
{
CHECK_VALID(NULL);
PyErr_SetString(PyExc_SystemError,
"mmaps don't support concatenation");
return NULL;
}
static PyObject *
mmap_repeat(mmap_object *self, Py_ssize_t n)
{
CHECK_VALID(NULL);
PyErr_SetString(PyExc_SystemError,
"mmaps don't support repeat operation");
return NULL;
}
static int static int
mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) mmap_ass_slice(mmap_object *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
{ {
...@@ -993,9 +975,9 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) ...@@ -993,9 +975,9 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
static PySequenceMethods mmap_as_sequence = { static PySequenceMethods mmap_as_sequence = {
(lenfunc)mmap_length, /*sq_length*/ (lenfunc)mmap_length, /*sq_length*/
(binaryfunc)mmap_concat, /*sq_concat*/ 0, /*sq_concat*/
(ssizeargfunc)mmap_repeat, /*sq_repeat*/ 0, /*sq_repeat*/
(ssizeargfunc)mmap_item, /*sq_item*/ (ssizeargfunc)mmap_item, /*sq_item*/
(ssizessizeargfunc)mmap_slice, /*sq_slice*/ (ssizessizeargfunc)mmap_slice, /*sq_slice*/
(ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/ (ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
(ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/ (ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment