@@ -48,6 +48,21 @@ PyCStgDict_dealloc(StgDictObject *self)
4848 PyDict_Type .tp_dealloc ((PyObject * )self );
4949}
5050
51+ static PyObject *
52+ PyCStgDict_sizeof (StgDictObject * self , void * unused )
53+ {
54+ Py_ssize_t res ;
55+
56+ res = _PyDict_SizeOf ((PyDictObject * )self );
57+ res += sizeof (StgDictObject ) - sizeof (PyDictObject );
58+ if (self -> format )
59+ res += strlen (self -> format ) + 1 ;
60+ res += self -> ndim * sizeof (Py_ssize_t );
61+ if (self -> ffi_type_pointer .elements )
62+ res += (self -> length + 1 ) * sizeof (ffi_type * );
63+ return PyLong_FromSsize_t (res );
64+ }
65+
5166int
5267PyCStgDict_clone (StgDictObject * dst , StgDictObject * src )
5368{
@@ -106,6 +121,11 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
106121 return 0 ;
107122}
108123
124+ static struct PyMethodDef PyCStgDict_methods [] = {
125+ {"__sizeof__" , (PyCFunction )PyCStgDict_sizeof , METH_NOARGS },
126+ {NULL , NULL } /* sentinel */
127+ };
128+
109129PyTypeObject PyCStgDict_Type = {
110130 PyVarObject_HEAD_INIT (NULL , 0 )
111131 "StgDict" ,
@@ -134,7 +154,7 @@ PyTypeObject PyCStgDict_Type = {
134154 0 , /* tp_weaklistoffset */
135155 0 , /* tp_iter */
136156 0 , /* tp_iternext */
137- 0 , /* tp_methods */
157+ PyCStgDict_methods , /* tp_methods */
138158 0 , /* tp_members */
139159 0 , /* tp_getset */
140160 0 , /* tp_base */
0 commit comments