diff options
author | Jesus Cea <jcea@jcea.es> | 2012-08-03 12:29:26 (GMT) |
---|---|---|
committer | Jesus Cea <jcea@jcea.es> | 2012-08-03 12:29:26 (GMT) |
commit | 88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb (patch) | |
tree | 5a7af12a79f62a6ee89b489c65ca8d143af74a0d /Modules/parsermodule.c | |
parent | 5323173dee1f20fc53c2df4707ec6d266534b748 (diff) | |
parent | e9c5318967e1e62e940b72cd47502a1a3b559b95 (diff) | |
download | cpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.zip cpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.tar.gz cpython-88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb.tar.bz2 |
MERGE: Closes #15512: Correct __sizeof__ support for parser
Diffstat (limited to 'Modules/parsermodule.c')
-rw-r--r-- | Modules/parsermodule.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index b9c1201..2c079ad 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -167,6 +167,7 @@ typedef struct { static void parser_free(PyST_Object *st); +static PyObject* parser_sizeof(PyST_Object *, void *); static PyObject* parser_richcompare(PyObject *left, PyObject *right, int op); static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); @@ -187,7 +188,8 @@ static PyMethodDef 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} }; @@ -361,6 +363,15 @@ parser_free(PyST_Object *st) PyObject_Del(st); } +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); +} + /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) * |