@@ -48,6 +48,21 @@ PyCStgDict_dealloc(StgDictObject *self)
48
48
PyDict_Type .tp_dealloc ((PyObject * )self );
49
49
}
50
50
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
+
51
66
int
52
67
PyCStgDict_clone (StgDictObject * dst , StgDictObject * src )
53
68
{
@@ -106,6 +121,11 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src)
106
121
return 0 ;
107
122
}
108
123
124
+ static struct PyMethodDef PyCStgDict_methods [] = {
125
+ {"__sizeof__" , (PyCFunction )PyCStgDict_sizeof , METH_NOARGS },
126
+ {NULL , NULL } /* sentinel */
127
+ };
128
+
109
129
PyTypeObject PyCStgDict_Type = {
110
130
PyVarObject_HEAD_INIT (NULL , 0 )
111
131
"StgDict" ,
@@ -134,7 +154,7 @@ PyTypeObject PyCStgDict_Type = {
134
154
0 , /* tp_weaklistoffset */
135
155
0 , /* tp_iter */
136
156
0 , /* tp_iternext */
137
- 0 , /* tp_methods */
157
+ PyCStgDict_methods , /* tp_methods */
138
158
0 , /* tp_members */
139
159
0 , /* tp_getset */
140
160
0 , /* tp_base */
0 commit comments