@@ -167,6 +167,7 @@ typedef struct {
167167
168168
169169static void parser_free (PyST_Object * st );
170+ static PyObject * parser_sizeof (PyST_Object * , void * );
170171static PyObject * parser_richcompare (PyObject * left , PyObject * right , int op );
171172static PyObject * parser_compilest (PyST_Object * , PyObject * , PyObject * );
172173static PyObject * parser_isexpr (PyST_Object * , PyObject * , PyObject * );
@@ -187,7 +188,8 @@ static PyMethodDef parser_methods[] = {
187188 PyDoc_STR ("Creates a list-tree representation of this ST." )},
188189 {"totuple" , (PyCFunction )parser_st2tuple , PUBLIC_METHOD_TYPE ,
189190 PyDoc_STR ("Creates a tuple-tree representation of this ST." )},
190-
191+ {"__sizeof__" , (PyCFunction )parser_sizeof , METH_NOARGS ,
192+ PyDoc_STR ("Returns size in memory, in bytes." )},
191193 {NULL , NULL , 0 , NULL }
192194};
193195
@@ -361,6 +363,15 @@ parser_free(PyST_Object *st)
361363 PyObject_Del (st );
362364}
363365
366+ static PyObject *
367+ parser_sizeof (PyST_Object * st , void * unused )
368+ {
369+ Py_ssize_t res ;
370+
371+ res = sizeof (PyST_Object ) + _PyNode_SizeOf (st -> st_node );
372+ return PyLong_FromSsize_t (res );
373+ }
374+
364375
365376/* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw)
366377 *
0 commit comments