Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15424] __sizeof__ of array should include size of items

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 22, 2012, 9:22 AM

Post #1 of 25 (362 views)
Permalink
[issue15424] __sizeof__ of array should include size of items

New submission from Ludwig Hähne <wkx [at] gmx>:

If sys.getsizeof is called on an array, the result doesn't include the size of the items:

>>> from array import array
>>> a = array("i", [0] * 100000)
>>> a.__sizeof__()
40

While this makes sense for a list, an array doesn't have separate referents that could be sized:

>>> import gc
>>> gc.get_referents(a)
[]

The attached patch adds an implementation of the __sizeof__ method for arrays that includes the size of the buffer for the elements.

It would be great if the patch would be considered for one of the upcoming versions of Python.

Thanks, Ludwig

----------
components: Library (Lib)
files: array_sizeof.patch
keywords: patch
messages: 166147
nosy: Pankrat
priority: normal
severity: normal
status: open
title: __sizeof__ of array should include size of items
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file26479/array_sizeof.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 22, 2012, 9:58 AM

Post #2 of 25 (362 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Martin v. Löwis <martin [at] v> added the comment:

Can you please submit a contributor form?

----------
nosy: +loewis

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 22, 2012, 10:25 AM

Post #3 of 25 (353 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Serhiy Storchaka <storchaka [at] gmail> added the comment:

I think it should be applied to 3.2 too.

----------
nosy: +storchaka

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 22, 2012, 11:34 AM

Post #4 of 25 (353 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne <wkx [at] gmx> added the comment:

Uses self->allocated instead of Py_SIZE as Martin suggested.

----------
Added file: http://bugs.python.org/file26480/array_sizeof_v2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 22, 2012, 11:57 AM

Post #5 of 25 (353 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne <wkx [at] gmx> added the comment:

Yes, it would be great if the change could be applied to 3.2 (and 2.7) but I guess not many people will be affected by the problem.

BTW, I just submitted the contributor form.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 23, 2012, 6:27 AM

Post #6 of 25 (350 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Jesús Cea Avión <jcea [at] jcea> added the comment:

With the precedent of issue #15402, I think that 2.7 and 3.2 should be fine.

----------
nosy: +jcea

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 23, 2012, 8:44 AM

Post #7 of 25 (351 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Jesús Cea Avión <jcea [at] jcea>:


----------
nosy: +meador.inge
versions: +Python 3.2 -Python 3.4

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 25, 2012, 4:55 AM

Post #8 of 25 (348 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne <wkx [at] gmx> added the comment:

Revised the patch based on the discussion in issue #15402 (http://bugs.python.org/msg166372). It doesn't typecast the function anymore and instead casts to the array type inside the function.

----------
Added file: http://bugs.python.org/file26510/array_sizeof_v3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 5, 2012, 4:19 AM

Post #9 of 25 (341 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Serhiy Storchaka added the comment:

Ludwig, you can use some helpers from test.support (see issue15467) for __sizeof__ testing.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 6, 2012, 4:11 PM

Post #10 of 25 (337 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne added the comment:

Serhiy, the tests now explicitly check the base size of the array.

I'm not sure if I got the base size compution right (only checked on 32bit Linux). Could you check that the struct definition in the test makes sense and matches the C arrayobject definition? Thanks, Ludwig

----------
Added file: http://bugs.python.org/file26713/array_sizeof_v4.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 6, 2012, 6:49 PM

Post #11 of 25 (333 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Meador Inge added the comment:

I left some commits in Rietveld. Otherwise, looks OK.

----------
assignee: -> meador.inge

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 7, 2012, 2:47 AM

Post #12 of 25 (333 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne added the comment:

Meador, thanks for reviewing. The updated patch is now attached to the bug.

----------
Added file: http://bugs.python.org/file26718/array_sizeof_v5.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 7, 2012, 3:21 AM

Post #13 of 25 (333 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Serhiy Storchaka added the comment:

Patch looks good to me, however tests for 3.2 and 2.7 should be modified (change "n" struct format specifier to "P", remove last "i" and use test_support instead test.support (or import test_support as support) in 2.7).

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 7, 2012, 6:49 PM

Post #14 of 25 (334 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Meador Inge added the comment:

Georg, yet another __sizeof__ fix. OK for 3.3?

----------
nosy: +georg.brandl
stage: -> commit review

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 7, 2012, 11:09 PM

Post #15 of 25 (335 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Georg Brandl added the comment:

LGTM.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:24 AM

Post #16 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Added file: http://bugs.python.org/file26756/array_sizeof_2.7.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:24 AM

Post #17 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Added file: http://bugs.python.org/file26757/array_sizeof_3.2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:25 AM

Post #18 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Removed file: http://bugs.python.org/file26713/array_sizeof_v4.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:25 AM

Post #19 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Removed file: http://bugs.python.org/file26510/array_sizeof_v3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:25 AM

Post #20 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Removed file: http://bugs.python.org/file26480/array_sizeof_v2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:25 AM

Post #21 of 25 (327 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Changes by Ludwig Hähne <wkx [at] gmx>:


Removed file: http://bugs.python.org/file26479/array_sizeof.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 5:28 AM

Post #22 of 25 (324 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Ludwig Hähne added the comment:

Meador, Serhiy, I've add patches for Python 2.7 and Python 3.2 following Serhiy suggestions.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 9:33 AM

Post #23 of 25 (322 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Serhiy Storchaka added the comment:

Patches look good to me.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 9:26 PM

Post #24 of 25 (320 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Roundup Robot added the comment:

New changeset 91382d4e2dfb by Meador Inge in branch '2.7':
Issue #15424: Add a __sizeof__ implementation for array objects.
http://hg.python.org/cpython/rev/91382d4e2dfb

New changeset 45ef9bc8739f by Meador Inge in branch '3.2':
Issue #15424: Add a __sizeof__ implementation for array objects.
http://hg.python.org/cpython/rev/45ef9bc8739f

New changeset 7d82a60850fd by Meador Inge in branch 'default':
Issue #15424: Add a __sizeof__ implementation for array objects.
http://hg.python.org/cpython/rev/7d82a60850fd

----------
nosy: +python-dev

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 9:31 PM

Post #25 of 25 (320 views)
Permalink
[issue15424] __sizeof__ of array should include size of items [In reply to]

Meador Inge added the comment:

Thanks for the patches! (I fixed a minor nit on the 2.7 patch where 'array_sizeof' was defined inside #ifdef Py_USING_UNICODE).

----------
resolution: -> fixed
stage: commit review -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15424>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.