diff options
author | Jesus Cea <jcea@jcea.es> | 2012-08-03 12:28:37 (GMT) |
---|---|---|
committer | Jesus Cea <jcea@jcea.es> | 2012-08-03 12:28:37 (GMT) |
commit | e9c5318967e1e62e940b72cd47502a1a3b559b95 (patch) | |
tree | 34c525b3471a0d8f9ae478c4e4e78142f9081ca4 /Parser | |
parent | a9a53c7dc055b54133f2dee33f1834d7566de842 (diff) | |
download | cpython-e9c5318967e1e62e940b72cd47502a1a3b559b95.zip cpython-e9c5318967e1e62e940b72cd47502a1a3b559b95.tar.gz cpython-e9c5318967e1e62e940b72cd47502a1a3b559b95.tar.bz2 |
Closes #15512: Correct __sizeof__ support for parser
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/node.c | 26 |
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; +} |