[Python-checkins] [2.7] bpo-33767: Fix improper use of SystemError by mmap.mmap objects (GH-7381) (GH-7432)
Serhiy Storchaka
webhook-mailer at python.org
Tue Jun 5 12:51:46 EDT 2018
https://github.com/python/cpython/commit/3014d6eb7f6ed8cc61b9b26fe1c4454760dc8621
commit: 3014d6eb7f6ed8cc61b9b26fe1c4454760dc8621
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2018-06-05T19:51:37+03:00
summary:
[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 e9e397605789b2a67b67558fbbe756b7b88934f5)
Co-authored-by: Zackery Spytz <zspytz at gmail.com>
files:
A Misc/NEWS.d/next/Library/2018-06-03-22-41-59.bpo-33767.2e82g3.rst
M Lib/test/test_mmap.py
M Modules/mmapmodule.c
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 0350b3de38f2..fc6d6e1cac9c 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -666,6 +666,13 @@ def test_resize_past_pos(self):
self.assertRaises(ValueError, m.write_byte, 'b')
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):
diff --git a/Misc/NEWS.d/next/Library/2018-06-03-22-41-59.bpo-33767.2e82g3.rst b/Misc/NEWS.d/next/Library/2018-06-03-22-41-59.bpo-33767.2e82g3.rst
new file mode 100644
index 000000000000..348330189095
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-03-22-41-59.bpo-33767.2e82g3.rst
@@ -0,0 +1,3 @@
+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.
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 2ae52c7b28df..bafdce3b1f84 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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
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)
static PySequenceMethods mmap_as_sequence = {
(lenfunc)mmap_length, /*sq_length*/
- (binaryfunc)mmap_concat, /*sq_concat*/
- (ssizeargfunc)mmap_repeat, /*sq_repeat*/
- (ssizeargfunc)mmap_item, /*sq_item*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ (ssizeargfunc)mmap_item, /*sq_item*/
(ssizessizeargfunc)mmap_slice, /*sq_slice*/
(ssizeobjargproc)mmap_ass_item, /*sq_ass_item*/
(ssizessizeobjargproc)mmap_ass_slice, /*sq_ass_slice*/
More information about the Python-checkins
mailing list