Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,14 @@ def test_resize_past_pos(self):
self.assertRaises(ValueError, m.write_byte, 42)
self.assertRaises(ValueError, m.write, b'abc')

def test_concat_repeat_exception(self):
# A SystemError was raised on two unsupported sequence operations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick, but I think we can drop this comment. If future readers want to know more about the test, they will find it via git blame.

m = mmap.mmap(-1, 16)
with self.assertRaises(TypeError):
m + m
with self.assertRaises(TypeError):
m * 2


class LargeMmapTests(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix improper use of :exc:`SystemError` by :class:`mmap.mmap` objects. Patch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also mention that the + and * operations will now raise TypeErrors?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to reword this entry something like: "Conatenating (``+``) and repeating (``*``) of :class:`mmap.mmap` objects now raises :exc:`TypeError` instead of :exc:`SystemError`."

by Zackery Spytz.
22 changes: 2 additions & 20 deletions Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,24 +812,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
mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
{
Expand Down Expand Up @@ -949,8 +931,8 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)

static PySequenceMethods mmap_as_sequence = {
(lenfunc)mmap_length, /*sq_length*/
(binaryfunc)mmap_concat, /*sq_concat*/
(ssizeargfunc)mmap_repeat, /*sq_repeat*/
0, /*sq_concat*/
0, /*sq_repeat*/
(ssizeargfunc)mmap_item, /*sq_item*/
0, /*sq_slice*/
(ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
Expand Down