summaryrefslogtreecommitdiffstats
path: root/Modules/_elementtree.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2012-06-17 08:41:22 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2012-06-17 08:41:22 (GMT)
commitbce166681cf18cb2e6ce61c937acbe7e5fdfafae (patch)
tree9f29fd9890427cd27226d790606aa35d484bfe68 /Modules/_elementtree.c
parent1e5d0ff8a02d18367001f009886241319331cc3f (diff)
downloadcpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.zip
cpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.tar.gz
cpython-bce166681cf18cb2e6ce61c937acbe7e5fdfafae.tar.bz2
Issue #14055: Add __sizeof__ support to _elementtree.
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r--Modules/_elementtree.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index cb84048..6415797 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -842,6 +842,19 @@ element_deepcopy(ElementObject* self, PyObject* args)
return NULL;
}
+static PyObject*
+element_sizeof(PyObject* _self, PyObject* args)
+{
+ ElementObject *self = (ElementObject*)_self;
+ Py_ssize_t result = sizeof(ElementObject);
+ if (self->extra) {
+ result += sizeof(ElementObjectExtra);
+ if (self->extra->children != self->extra->_children)
+ result += sizeof(PyObject*) * self->extra->allocated;
+ }
+ return PyLong_FromSsize_t(result);
+}
+
LOCAL(int)
checkpath(PyObject* tag)
{
@@ -1609,6 +1622,7 @@ static PyMethodDef element_methods[] = {
{"__copy__", (PyCFunction) element_copy, METH_VARARGS},
{"__deepcopy__", (PyCFunction) element_deepcopy, METH_VARARGS},
+ {"__sizeof__", element_sizeof, METH_NOARGS},
{NULL, NULL}
};