@@ -169,8 +169,10 @@ typedef struct {
169169
170170
171171static void parser_free (PyST_Object * st );
172+ static PyObject * parser_sizeof (PyST_Object * , void * );
172173static int parser_compare (PyST_Object * left , PyST_Object * right );
173174static PyObject * parser_getattr (PyObject * self , char * name );
175+ static PyMethodDef parser_methods [];
174176
175177
176178static
@@ -200,7 +202,14 @@ PyTypeObject PyST_Type = {
200202 Py_TPFLAGS_DEFAULT , /* tp_flags */
201203
202204 /* __doc__ */
203- "Intermediate representation of a Python parse tree."
205+ "Intermediate representation of a Python parse tree." ,
206+ 0 , /* tp_traverse */
207+ 0 , /* tp_clear */
208+ 0 , /* tp_richcompare */
209+ 0 , /* tp_weaklistoffset */
210+ 0 , /* tp_iter */
211+ 0 , /* tp_iternext */
212+ parser_methods , /* tp_methods */
204213}; /* PyST_Type */
205214
206215
@@ -508,7 +517,8 @@ parser_methods[] = {
508517 PyDoc_STR ("Creates a list-tree representation of this ST." )},
509518 {"totuple" , (PyCFunction )parser_st2tuple , PUBLIC_METHOD_TYPE ,
510519 PyDoc_STR ("Creates a tuple-tree representation of this ST." )},
511-
520+ {"__sizeof__" , (PyCFunction )parser_sizeof , METH_NOARGS ,
521+ PyDoc_STR ("Returns size in memory, in bytes." )},
512522 {NULL , NULL , 0 , NULL }
513523};
514524
@@ -695,6 +705,15 @@ parser_tuple2ast(PyST_Object *self, PyObject *args, PyObject *kw)
695705 return parser_tuple2st (self , args , kw );
696706}
697707
708+ static PyObject *
709+ parser_sizeof (PyST_Object * st , void * unused )
710+ {
711+ Py_ssize_t res ;
712+
713+ res = sizeof (PyST_Object ) + _PyNode_SizeOf (st -> st_node );
714+ return PyLong_FromSsize_t (res );
715+ }
716+
698717
699718/* node* build_node_children()
700719 *
0 commit comments