diff -r 5206b9dbf1ac Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py Thu Aug 16 07:27:47 2012 +0300 +++ b/Lib/test/test_mmap.py Thu Aug 16 17:50:02 2012 +0300 @@ -1,5 +1,5 @@ from test.support import (TESTFN, run_unittest, import_module, unlink, - requires, _2G, _4G) + requires, _2G, _4G, cpython_only) import unittest import os import re @@ -633,6 +633,14 @@ m2.close() m1.close() + @cpython_only + 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) + def test_crasher_on_windows(self): # Should not crash (Issue 1733986) m = mmap.mmap(-1, 1000, tagname="foo") diff -r 5206b9dbf1ac Modules/mmapmodule.c --- a/Modules/mmapmodule.c Thu Aug 16 07:27:47 2012 +0300 +++ b/Modules/mmapmodule.c Thu Aug 16 17:50:02 2012 +0300 @@ -705,6 +705,19 @@ return _PyObject_CallMethodId(self, &PyId_close, NULL); } +#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}, @@ -722,6 +735,9 @@ {"write_byte", (PyCFunction) mmap_write_byte_method, METH_VARARGS}, {"__enter__", (PyCFunction) mmap__enter__method, METH_NOARGS}, {"__exit__", (PyCFunction) mmap__exit__method, METH_VARARGS}, +#ifdef MS_WINDOWS + {"__sizeof__", (PyCFunction) mmap__sizeof__method, METH_NOARGS}, +#endif {NULL, NULL} /* sentinel */ };