diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-19 14:03:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-08-19 14:03:42 (GMT) |
commit | cbee972e358f2adc7399ccdf2b5a34b9229285ce (patch) | |
tree | 9ac879bf5867694ba0a7ed873a4071fd0f082332 | |
parent | ede745a7edb9ada7fba7cee07d60f2a8ee9d924f (diff) | |
download | cpython-cbee972e358f2adc7399ccdf2b5a34b9229285ce.zip cpython-cbee972e358f2adc7399ccdf2b5a34b9229285ce.tar.gz cpython-cbee972e358f2adc7399ccdf2b5a34b9229285ce.tar.bz2 |
Issue #15696: Add a __sizeof__ implementation for mmap objects on Windows.
-rw-r--r-- | Lib/test/test_mmap.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 16 |
3 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 62c65bd..f23a259 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,5 +1,5 @@ from test.test_support import (TESTFN, run_unittest, import_module, unlink, - requires, _2G, _4G) + requires, _2G, _4G, gc_collect, cpython_only) import unittest import os, re, itertools, socket, sys @@ -606,6 +606,15 @@ class MmapTests(unittest.TestCase): m2.close() m1.close() + @cpython_only + @unittest.skipUnless(os.name == 'nt', 'requires Windows') + def test_sizeof(self): + m1 = mmap.mmap(-1, 100) + tagname = "foo" + m2 = mmap.mmap(-1, 100, tagname=tagname) + self.assertEqual(sys.getsize(m2), + sys.getsize(m1) + len(tagname) + 1) + @unittest.skipUnless(os.name == 'nt', 'requires Windows') def test_crasher_on_windows(self): # Should not crash (Issue 1733986) @@ -19,6 +19,8 @@ Core and Builtins Library ------- +- Issue #15696: Add a __sizeof__ implementation for mmap objects on Windows. + - Issue #22068: Avoided reference loops with Variables and Fonts in Tkinter. - Issue #21448: Changed FeedParser feed() to avoid O(N**2) behavior when diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 67e4000..0784350 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -649,6 +649,19 @@ mmap_move_method(mmap_object *self, PyObject *args) } } +#ifdef MS_WINDOWS +static PyObject * +mmap__sizeof__method(mmap_object *self, void *unused) +{ + Py_ssize_t res; + + res = sizeof(mmap_object); + if (self->tagname) + res += strlen(self->tagname) + 1; + return PyLong_FromSsize_t(res); +} +#endif + static struct PyMethodDef mmap_object_methods[] = { {"close", (PyCFunction) mmap_close_method, METH_NOARGS}, {"find", (PyCFunction) mmap_find_method, METH_VARARGS}, @@ -664,6 +677,9 @@ static struct PyMethodDef mmap_object_methods[] = { {"tell", (PyCFunction) mmap_tell_method, METH_NOARGS}, {"write", (PyCFunction) mmap_write_method, METH_VARARGS}, {"write_byte", (PyCFunction) mmap_write_byte_method, METH_VARARGS}, +#ifdef MS_WINDOWS + {"__sizeof__", (PyCFunction) mmap__sizeof__method, METH_NOARGS}, +#endif {NULL, NULL} /* sentinel */ }; |