This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Correct __sizeof__ support for code objects
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.3
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, jcea, loewis, ncoghlan, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-07-26 10:29 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
code_sizeof.patch serhiy.storchaka, 2012-07-26 10:29 review
Messages (6)
msg166469 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-26 10:29
Here is a patch that implements __sizeof__ for code objects (PyCodeObject) counting co_cell2arg array.
msg166470 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-26 10:36
See also issue12399.
msg166512 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-26 20:18
Interestingly, the original patch did change the sizeof test, but incorrectly (adding the extra pointer to the struct spec, but failing to recognize that there is additional memory allocated).

This tells me

a) we *absolutely* need to preserve the current testing style where the test cases count the individual fields (see issue15402 for the related discussion). Had the test used object.__sizeof__, it would not have needed any change to continue to pass, losing all hope that somebody might have detected it except by very careful review.

b) the trigger that the test broke apparently was not sufficient to hint Benjamin that the sizeof implementation may be incorrect, he just assumed that the test was incorrect.
msg166514 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-26 20:23
New changeset 5093cfdff2a9 by Martin v. Löwis in branch 'default':
Issue #15456: Fix code __sizeof__ after #12399 change.
msg166516 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-26 20:24
Thanks for the patch!
msg166637 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-28 08:28
Thank you for fast commiting.
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59661
2012-08-03 01:05:24jceasetnosy: + jcea
2012-07-28 08:28:22serhiy.storchakasetmessages: + msg166637
2012-07-26 20:24:03loewissetstatus: open -> closed
resolution: fixed
messages: + msg166516
2012-07-26 20:23:38python-devsetnosy: + python-dev
messages: + msg166514
2012-07-26 20:18:22loewissetnosy: + loewis
messages: + msg166512
2012-07-26 10:36:10serhiy.storchakasetnosy: + ncoghlan, benjamin.peterson
messages: + msg166470
2012-07-26 10:29:14serhiy.storchakacreate