summaryrefslogtreecommitdiffstats
path: root/Parser/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/node.c')
-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;
+}