bpo-33767: Fix improper use of SystemError by mmap.mmap objects (GH-7… · python/cpython@ae55d29 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -734,6 +734,13 @@ def test_resize_past_pos(self):
734 734 self.assertRaises(ValueError, m.write_byte, 42)
735 735 self.assertRaises(ValueError, m.write, b'abc')
736 736
737 +def test_concat_repeat_exception(self):
738 +m = mmap.mmap(-1, 16)
739 +with self.assertRaises(TypeError):
740 +m + m
741 +with self.assertRaises(TypeError):
742 +m * 2
743 +
737 744
738 745 class LargeMmapTests(unittest.TestCase):
739 746
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 +The concatenation (``+``) and repetition (``*``) sequence operations now
2 +raise :exc:`TypeError` instead of :exc:`SystemError` when performed on
3 +:class:`mmap.mmap` objects. Patch by Zackery Spytz.
Original file line number Diff line number Diff line change
@@ -840,24 +840,6 @@ mmap_subscript(mmap_object *self, PyObject *item)
840 840 }
841 841 }
842 842
843 -static PyObject *
844 -mmap_concat(mmap_object *self, PyObject *bb)
845 -{
846 -CHECK_VALID(NULL);
847 -PyErr_SetString(PyExc_SystemError,
848 -"mmaps don't support concatenation");
849 -return NULL;
850 -}
851 -
852 -static PyObject *
853 -mmap_repeat(mmap_object *self, Py_ssize_t n)
854 -{
855 -CHECK_VALID(NULL);
856 -PyErr_SetString(PyExc_SystemError,
857 -"mmaps don't support repeat operation");
858 -return NULL;
859 -}
860 -
861 843 static int
862 844 mmap_ass_item(mmap_object *self, Py_ssize_t i, PyObject *v)
863 845 {
@@ -977,8 +959,8 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
977 959
978 960 static PySequenceMethods mmap_as_sequence = {
979 961 (lenfunc)mmap_length, /*sq_length*/
980 -(binaryfunc)mmap_concat, /*sq_concat*/
981 -(ssizeargfunc)mmap_repeat, /*sq_repeat*/
962 +0, /*sq_concat*/
963 +0, /*sq_repeat*/
982 964 (ssizeargfunc)mmap_item, /*sq_item*/
983 965 0, /*sq_slice*/
984 966 (ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/