mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
This commit is contained in:
parent
a939105a40
commit
2d639d5665
4 changed files with 32 additions and 0 deletions
|
@ -985,6 +985,19 @@ class UnsignedNumberTest(NumberTest):
|
||||||
upper = long(pow(2, a.itemsize * 8)) - 1L
|
upper = long(pow(2, a.itemsize * 8)) - 1L
|
||||||
self.check_overflow(lower, upper)
|
self.check_overflow(lower, upper)
|
||||||
|
|
||||||
|
@test_support.cpython_only
|
||||||
|
def test_sizeof_with_buffer(self):
|
||||||
|
a = array.array(self.typecode, self.example)
|
||||||
|
basesize = test_support.calcvobjsize('4P')
|
||||||
|
buffer_size = a.buffer_info()[1] * a.itemsize
|
||||||
|
test_support.check_sizeof(self, a, basesize + buffer_size)
|
||||||
|
|
||||||
|
@test_support.cpython_only
|
||||||
|
def test_sizeof_without_buffer(self):
|
||||||
|
a = array.array(self.typecode)
|
||||||
|
basesize = test_support.calcvobjsize('4P')
|
||||||
|
test_support.check_sizeof(self, a, basesize)
|
||||||
|
|
||||||
|
|
||||||
class ByteTest(SignedNumberTest):
|
class ByteTest(SignedNumberTest):
|
||||||
typecode = 'b'
|
typecode = 'b'
|
||||||
|
|
|
@ -393,6 +393,7 @@ Jim Hugunin
|
||||||
Greg Humphreys
|
Greg Humphreys
|
||||||
Eric Huss
|
Eric Huss
|
||||||
Jeremy Hylton
|
Jeremy Hylton
|
||||||
|
Ludwig Hähne
|
||||||
Gerhard Häring
|
Gerhard Häring
|
||||||
Fredrik Håård
|
Fredrik Håård
|
||||||
Catalin Iacob
|
Catalin Iacob
|
||||||
|
|
|
@ -94,6 +94,9 @@ Library
|
||||||
|
|
||||||
- Issue #15567: Fix NameError when running threading._test
|
- Issue #15567: Fix NameError when running threading._test
|
||||||
|
|
||||||
|
- Issue #15424: Add a __sizeof__ implementation for array objects.
|
||||||
|
Patch by Ludwig Hähne.
|
||||||
|
|
||||||
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
|
- Issue #13052: Fix IDLE crashing when replace string in Search/Replace dialog
|
||||||
ended with '\'. Patch by Roger Serwy.
|
ended with '\'. Patch by Roger Serwy.
|
||||||
|
|
||||||
|
|
|
@ -1532,6 +1532,19 @@ array_reduce(arrayobject *array)
|
||||||
|
|
||||||
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
array_sizeof(arrayobject *self, PyObject *unused)
|
||||||
|
{
|
||||||
|
Py_ssize_t res;
|
||||||
|
res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize;
|
||||||
|
return PyLong_FromSsize_t(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(sizeof_doc,
|
||||||
|
"__sizeof__() -> int\n\
|
||||||
|
\n\
|
||||||
|
Size of the array in memory, in bytes.");
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
array_get_typecode(arrayobject *a, void *closure)
|
array_get_typecode(arrayobject *a, void *closure)
|
||||||
{
|
{
|
||||||
|
@ -1606,6 +1619,8 @@ static PyMethodDef array_methods[] = {
|
||||||
#endif
|
#endif
|
||||||
{"write", (PyCFunction)array_tofile_as_write, METH_O,
|
{"write", (PyCFunction)array_tofile_as_write, METH_O,
|
||||||
tofile_doc},
|
tofile_doc},
|
||||||
|
{"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS,
|
||||||
|
sizeof_doc},
|
||||||
{NULL, NULL} /* sentinel */
|
{NULL, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue