From: Serhiy Storchaka Date: Sun, 12 Mar 2017 09:12:30 +0000 (+0200) Subject: bpo-15695: Implemented StgDict.__sizeof__(). (#509) X-Git-Tag: v3.7.0a1~1146 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8999caeb003ed292011e98b8a30746cce787a125;p=thirdparty%2FPython%2Fcpython.git bpo-15695: Implemented StgDict.__sizeof__(). (#509) --- diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 1ccaf2fd9b99..3496c5706cb2 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -48,6 +48,21 @@ PyCStgDict_dealloc(StgDictObject *self) PyDict_Type.tp_dealloc((PyObject *)self); } +static PyObject * +PyCStgDict_sizeof(StgDictObject *self, void *unused) +{ + Py_ssize_t res; + + res = _PyDict_SizeOf((PyDictObject *)self); + res += sizeof(StgDictObject) - sizeof(PyDictObject); + if (self->format) + res += strlen(self->format) + 1; + res += self->ndim * sizeof(Py_ssize_t); + if (self->ffi_type_pointer.elements) + res += (self->length + 1) * sizeof(ffi_type *); + return PyLong_FromSsize_t(res); +} + int PyCStgDict_clone(StgDictObject *dst, StgDictObject *src) { @@ -106,6 +121,11 @@ PyCStgDict_clone(StgDictObject *dst, StgDictObject *src) return 0; } +static struct PyMethodDef PyCStgDict_methods[] = { + {"__sizeof__", (PyCFunction)PyCStgDict_sizeof, METH_NOARGS}, + {NULL, NULL} /* sentinel */ +}; + PyTypeObject PyCStgDict_Type = { PyVarObject_HEAD_INIT(NULL, 0) "StgDict", @@ -134,7 +154,7 @@ PyTypeObject PyCStgDict_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + PyCStgDict_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */