summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-08-03 12:29:26 (GMT)
committerJesus Cea <jcea@jcea.es>2012-08-03 12:29:26 (GMT)
commit88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb (patch)
tree5a7af12a79f62a6ee89b489c65ca8d143af74a0d /Parser
parent5323173dee1f20fc53c2df4707ec6d266534b748 (diff)
parente9c5318967e1e62e940b72cd47502a1a3b559b95 (diff)
downloadcpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.zip
cpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.tar.gz
cpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.tar.bz2
MERGE: Closes #15512: Correct __sizeof__ support for parser
Diffstat (limited to 'Parser')
-rw-r--r--Parser/node.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Parser/node.c b/Parser/node.c
index 9eba76b..0dea30f 100644
--- a/Parser/node.c
+++ b/Parser/node.c
@@ -114,6 +114,7 @@ PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offs
/* Forward */
static void freechildren(node *);
+static Py_ssize_t sizeofchildren(node *n);
void
@@ -125,6 +126,16 @@ PyNode_Free(node *n)
}
}
+Py_ssize_t
+_PyNode_SizeOf(node *n)
+{
+ Py_ssize_t res = 0;
+
+ if (n != NULL)
+ res = sizeof(node) + sizeofchildren(n);
+ return res;
+}
+
static void
freechildren(node *n)
{
@@ -136,3 +147,18 @@ freechildren(node *n)
if (STR(n) != NULL)
PyObject_FREE(STR(n));
}
+
+static Py_ssize_t
+sizeofchildren(node *n)
+{
+ Py_ssize_t res = 0;
+ int i;
+ for (i = NCH(n); --i >= 0; )
+ res += sizeofchildren(CHILD(n, i));
+ if (n->n_child != NULL)
+ /* allocated size of n->n_child array */
+ res += XXXROUNDUP(NCH(n)) * sizeof(node);
+ if (STR(n) != NULL)
+ res += strlen(STR(n)) + 1;
+ return res;
+}