summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-08-03 12:25:53 (GMT)
committerJesus Cea <jcea@jcea.es>2012-08-03 12:25:53 (GMT)
commit3e3192d8f76ca6bfbf111ed2059eaef8e49a53e5 (patch)
tree6f6107e37955012a786fb83b30da9f38dd1212e2 /Modules
parent1fa9f7b3d1d5c90cb231946a6edaf7f748e07436 (diff)
downloadcpython-3e3192d8f76ca6bfbf111ed2059eaef8e49a53e5.zip
cpython-3e3192d8f76ca6bfbf111ed2059eaef8e49a53e5.tar.gz
cpython-3e3192d8f76ca6bfbf111ed2059eaef8e49a53e5.tar.bz2
Closes #15512: Correct __sizeof__ support for parser
Diffstat (limited to 'Modules')
-rw-r--r--Modules/parsermodule.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 632475c..a7cdc8f 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -169,8 +169,10 @@ typedef struct {
static void parser_free(PyST_Object *st);
+static PyObject* parser_sizeof(PyST_Object *, void *);
static int parser_compare(PyST_Object *left, PyST_Object *right);
static PyObject *parser_getattr(PyObject *self, char *name);
+static PyMethodDef parser_methods[];
static
@@ -200,7 +202,14 @@ PyTypeObject PyST_Type = {
Py_TPFLAGS_DEFAULT, /* tp_flags */
/* __doc__ */
- "Intermediate representation of a Python parse tree."
+ "Intermediate representation of a Python parse tree.",
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ parser_methods, /* tp_methods */
}; /* PyST_Type */
@@ -508,7 +517,8 @@ parser_methods[] = {
PyDoc_STR("Creates a list-tree representation of this ST.")},
{"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE,
PyDoc_STR("Creates a tuple-tree representation of this ST.")},
-
+ {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS,
+ PyDoc_STR("Returns size in memory, in bytes.")},
{NULL, NULL, 0, NULL}
};
@@ -695,6 +705,15 @@ parser_tuple2ast(PyST_Object *self, PyObject *args, PyObject *kw)
return parser_tuple2st(self, args, kw);
}
+static PyObject *
+parser_sizeof(PyST_Object *st, void *unused)
+{
+ Py_ssize_t res;
+
+ res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node);
+ return PyLong_FromSsize_t(res);
+}
+
/* node* build_node_children()
*