Issue #15696: Add a __sizeof__ implementation for mmap objects on Windows.
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 @@
}
}
+#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 @@
{"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 */
};