@@ -2057,6 +2057,18 @@ product_dealloc(productobject *lz)
20572057 Py_TYPE (lz )-> tp_free (lz );
20582058}
20592059
2060+ static PyObject *
2061+ product_sizeof (productobject * lz , void * unused )
2062+ {
2063+ Py_ssize_t res ;
2064+
2065+ res = sizeof (productobject );
2066+ res += PyTuple_GET_SIZE (lz -> pools ) * sizeof (Py_ssize_t );
2067+ return PyLong_FromSsize_t (res );
2068+ }
2069+
2070+ PyDoc_STRVAR (sizeof_doc , "Returns size in memory, in bytes." );
2071+
20602072static int
20612073product_traverse (productobject * lz , visitproc visit , void * arg )
20622074{
@@ -2226,6 +2238,8 @@ static PyMethodDef product_methods[] = {
22262238 reduce_doc },
22272239 {"__setstate__" , (PyCFunction )product_setstate , METH_O ,
22282240 setstate_doc },
2241+ {"__sizeof__" , (PyCFunction )product_sizeof , METH_NOARGS ,
2242+ sizeof_doc },
22292243 {NULL , NULL } /* sentinel */
22302244};
22312245
@@ -2366,6 +2380,16 @@ combinations_dealloc(combinationsobject *co)
23662380 Py_TYPE (co )-> tp_free (co );
23672381}
23682382
2383+ static PyObject *
2384+ combinations_sizeof (combinationsobject * co , void * unused )
2385+ {
2386+ Py_ssize_t res ;
2387+
2388+ res = sizeof (combinationsobject );
2389+ res += co -> r * sizeof (Py_ssize_t );
2390+ return PyLong_FromSsize_t (res );
2391+ }
2392+
23692393static int
23702394combinations_traverse (combinationsobject * co , visitproc visit , void * arg )
23712395{
@@ -2537,6 +2561,8 @@ static PyMethodDef combinations_methods[] = {
25372561 reduce_doc },
25382562 {"__setstate__" , (PyCFunction )combinations_setstate , METH_O ,
25392563 setstate_doc },
2564+ {"__sizeof__" , (PyCFunction )combinations_sizeof , METH_NOARGS ,
2565+ sizeof_doc },
25402566 {NULL , NULL } /* sentinel */
25412567};
25422568
@@ -2695,6 +2721,16 @@ cwr_dealloc(cwrobject *co)
26952721 Py_TYPE (co )-> tp_free (co );
26962722}
26972723
2724+ static PyObject *
2725+ cwr_sizeof (cwrobject * co , void * unused )
2726+ {
2727+ Py_ssize_t res ;
2728+
2729+ res = sizeof (cwrobject );
2730+ res += co -> r * sizeof (Py_ssize_t );
2731+ return PyLong_FromSsize_t (res );
2732+ }
2733+
26982734static int
26992735cwr_traverse (cwrobject * co , visitproc visit , void * arg )
27002736{
@@ -2854,6 +2890,8 @@ static PyMethodDef cwr_methods[] = {
28542890 reduce_doc },
28552891 {"__setstate__" , (PyCFunction )cwr_setstate , METH_O ,
28562892 setstate_doc },
2893+ {"__sizeof__" , (PyCFunction )cwr_sizeof , METH_NOARGS ,
2894+ sizeof_doc },
28572895 {NULL , NULL } /* sentinel */
28582896};
28592897
@@ -3030,6 +3068,17 @@ permutations_dealloc(permutationsobject *po)
30303068 Py_TYPE (po )-> tp_free (po );
30313069}
30323070
3071+ static PyObject *
3072+ permutations_sizeof (permutationsobject * po , void * unused )
3073+ {
3074+ Py_ssize_t res ;
3075+
3076+ res = sizeof (permutationsobject );
3077+ res += PyTuple_GET_SIZE (po -> pool ) * sizeof (Py_ssize_t );
3078+ res += po -> r * sizeof (Py_ssize_t );
3079+ return PyLong_FromSsize_t (res );
3080+ }
3081+
30333082static int
30343083permutations_traverse (permutationsobject * po , visitproc visit , void * arg )
30353084{
@@ -3235,6 +3284,8 @@ static PyMethodDef permuations_methods[] = {
32353284 reduce_doc },
32363285 {"__setstate__" , (PyCFunction )permutations_setstate , METH_O ,
32373286 setstate_doc },
3287+ {"__sizeof__" , (PyCFunction )permutations_sizeof , METH_NOARGS ,
3288+ sizeof_doc },
32383289 {NULL , NULL } /* sentinel */
32393290};
32403291
0 commit comments