Mercurial > cpython-lru_cache-weakref
comparison Modules/arraymodule.c @ 78492:91382d4e2dfb 2.7
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:05:45 -0500 |
| parents | 78a7d5f8f054 |
| children |
comparison
equal
deleted
inserted
replaced
| 78484:260f3ad7af4b | 78492:91382d4e2dfb |
|---|---|
| 1529 Py_DECREF(dict); | 1529 Py_DECREF(dict); |
| 1530 return result; | 1530 return result; |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); | 1533 PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); |
| 1534 | |
| 1535 static PyObject * | |
| 1536 array_sizeof(arrayobject *self, PyObject *unused) | |
| 1537 { | |
| 1538 Py_ssize_t res; | |
| 1539 res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize; | |
| 1540 return PyLong_FromSsize_t(res); | |
| 1541 } | |
| 1542 | |
| 1543 PyDoc_STRVAR(sizeof_doc, | |
| 1544 "__sizeof__() -> int\n\ | |
| 1545 \n\ | |
| 1546 Size of the array in memory, in bytes."); | |
| 1534 | 1547 |
| 1535 static PyObject * | 1548 static PyObject * |
| 1536 array_get_typecode(arrayobject *a, void *closure) | 1549 array_get_typecode(arrayobject *a, void *closure) |
| 1537 { | 1550 { |
| 1538 char tc = a->ob_descr->typecode; | 1551 char tc = a->ob_descr->typecode; |
| 1604 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, | 1617 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, |
| 1605 tounicode_doc}, | 1618 tounicode_doc}, |
| 1606 #endif | 1619 #endif |
| 1607 {"write", (PyCFunction)array_tofile_as_write, METH_O, | 1620 {"write", (PyCFunction)array_tofile_as_write, METH_O, |
| 1608 tofile_doc}, | 1621 tofile_doc}, |
| 1622 {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS, | |
| 1623 sizeof_doc}, | |
| 1609 {NULL, NULL} /* sentinel */ | 1624 {NULL, NULL} /* sentinel */ |
| 1610 }; | 1625 }; |
| 1611 | 1626 |
| 1612 static PyObject * | 1627 static PyObject * |
| 1613 array_repr(arrayobject *a) | 1628 array_repr(arrayobject *a) |
