Mercurial > cpython-lru_cache-weakref
comparison Modules/arraymodule.c @ 78493:45ef9bc8739f 3.2
Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
| author | Meador Inge <meadori@gmail.com> |
|---|---|
| date | Fri, 10 Aug 2012 22:35:45 -0500 |
| parents | 1e2880250610 |
| children | 88dcccb46298 7d82a60850fd |
comparison
equal
deleted
inserted
replaced
| 78479:4787b9b2f860 | 78493:45ef9bc8739f |
|---|---|
| 1507 Convert the array to a unicode string. The array must be\n\ | 1507 Convert the array to a unicode string. The array must be\n\ |
| 1508 a unicode type array; otherwise a ValueError is raised. Use\n\ | 1508 a unicode type array; otherwise a ValueError is raised. Use\n\ |
| 1509 array.tobytes().decode() to obtain a unicode string from\n\ | 1509 array.tobytes().decode() to obtain a unicode string from\n\ |
| 1510 an array of some other type."); | 1510 an array of some other type."); |
| 1511 | 1511 |
| 1512 | |
| 1513 static PyObject * | |
| 1514 array_sizeof(arrayobject *self, PyObject *unused) | |
| 1515 { | |
| 1516 Py_ssize_t res; | |
| 1517 res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; | |
| 1518 return PyLong_FromSsize_t(res); | |
| 1519 } | |
| 1520 | |
| 1521 PyDoc_STRVAR(sizeof_doc, | |
| 1522 "__sizeof__() -> int\n\ | |
| 1523 \n\ | |
| 1524 Size of the array in memory, in bytes."); | |
| 1512 | 1525 |
| 1513 | 1526 |
| 1514 /*********************** Pickling support ************************/ | 1527 /*********************** Pickling support ************************/ |
| 1515 | 1528 |
| 1516 enum machine_format_code { | 1529 enum machine_format_code { |
| 2075 tostring_doc}, | 2088 tostring_doc}, |
| 2076 {"tobytes", (PyCFunction)array_tobytes, METH_NOARGS, | 2089 {"tobytes", (PyCFunction)array_tobytes, METH_NOARGS, |
| 2077 tobytes_doc}, | 2090 tobytes_doc}, |
| 2078 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, | 2091 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, |
| 2079 tounicode_doc}, | 2092 tounicode_doc}, |
| 2093 {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, | |
| 2094 sizeof_doc}, | |
| 2080 {NULL, NULL} /* sentinel */ | 2095 {NULL, NULL} /* sentinel */ |
| 2081 }; | 2096 }; |
| 2082 | 2097 |
| 2083 static PyObject * | 2098 static PyObject * |
| 2084 array_repr(arrayobject *a) | 2099 array_repr(arrayobject *a) |
