@@ -398,6 +398,17 @@ buffered_dealloc(buffered *self)
398398 Py_TYPE (self )-> tp_free ((PyObject * )self );
399399}
400400
401+ static PyObject *
402+ buffered_sizeof (buffered * self , void * unused )
403+ {
404+ Py_ssize_t res ;
405+
406+ res = sizeof (buffered );
407+ if (self -> buffer )
408+ res += self -> buffer_size ;
409+ return PyLong_FromSsize_t (res );
410+ }
411+
401412static int
402413buffered_traverse (buffered * self , visitproc visit , void * arg )
403414{
@@ -1699,6 +1710,7 @@ static PyMethodDef bufferedreader_methods[] = {
16991710 {"seek" , (PyCFunction )buffered_seek , METH_VARARGS },
17001711 {"tell" , (PyCFunction )buffered_tell , METH_NOARGS },
17011712 {"truncate" , (PyCFunction )buffered_truncate , METH_VARARGS },
1713+ {"__sizeof__" , (PyCFunction )buffered_sizeof , METH_NOARGS },
17021714 {NULL , NULL }
17031715};
17041716
@@ -2079,6 +2091,7 @@ static PyMethodDef bufferedwriter_methods[] = {
20792091 {"flush" , (PyCFunction )buffered_flush , METH_NOARGS },
20802092 {"seek" , (PyCFunction )buffered_seek , METH_VARARGS },
20812093 {"tell" , (PyCFunction )buffered_tell , METH_NOARGS },
2094+ {"__sizeof__" , (PyCFunction )buffered_sizeof , METH_NOARGS },
20822095 {NULL , NULL }
20832096};
20842097
@@ -2470,6 +2483,7 @@ static PyMethodDef bufferedrandom_methods[] = {
24702483 {"readline" , (PyCFunction )buffered_readline , METH_VARARGS },
24712484 {"peek" , (PyCFunction )buffered_peek , METH_VARARGS },
24722485 {"write" , (PyCFunction )bufferedwriter_write , METH_VARARGS },
2486+ {"__sizeof__" , (PyCFunction )buffered_sizeof , METH_NOARGS },
24732487 {NULL , NULL }
24742488};
24752489
0 commit comments