[issue15402] Correct __sizeof__ support for struct

2012-07-28 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: issue15456 efficiently demonstrates that the current style can detect bugs which testing with object.__sizeof__ can't. Hmm, I see this as a counterexample. The bug *was not detected* with the current style of testing. But if you

[issue15402] Correct __sizeof__ support for struct

2012-07-28 Thread Meador Inge
Meador Inge added the comment: On Sat, Jul 28, 2012 at 3:27 AM, Serhiy Storchaka rep...@bugs.python.org wrote: Serhiy Storchaka storch...@gmail.com added the comment: issue15456 efficiently demonstrates that the current style can detect bugs which testing with object.__sizeof__ can't.

[issue15402] Correct __sizeof__ support for struct

2012-07-28 Thread Roundup Robot
Roundup Robot added the comment: New changeset 37554bda2014 by Meador Inge in branch '2.7': Issue #15402: Simplify Struct.__sizeof__ and make tests more precise. http://hg.python.org/cpython/rev/37554bda2014 New changeset 97dd2090a36c by Meador Inge in branch '3.2': Issue #15402: Simplify

[issue15402] Correct __sizeof__ support for struct

2012-07-28 Thread Meador Inge
Changes by Meador Inge mead...@gmail.com: -- resolution: - fixed stage: needs patch - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___

[issue15402] Correct __sizeof__ support for struct

2012-07-26 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: What if use totalsize = object.__sizeof__(struct_obj) ? That would defeat the purpose of the test. We want to test whether __sizeof__ is correct, so we shouldn't use __sizeof__ in the test to compute the expected result. I understand that

[issue15402] Correct __sizeof__ support for struct

2012-07-26 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: That would defeat the purpose of the test. We want to test whether __sizeof__ is correct, so we shouldn't use __sizeof__ in the test to compute the expected result. I understand that object.__sizeof__ is actually a different

[issue15402] Correct __sizeof__ support for struct

2012-07-26 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I do not think that the purpose of testing is a testing of object.__sizeof__. Memory consumption consists of two parts -- memory for C structure (and the base object implementation works for this) Note that object.__sizeof__ does

[issue15402] Correct __sizeof__ support for struct

2012-07-26 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Note that object.__sizeof__ does something slightly different, though: it uses basicsize (which may or may not contain the sizeof() invocation of the correct C structure), and it considers tp_itemsize (which may or may not have a

[issue15402] Correct __sizeof__ support for struct

2012-07-26 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: All such cases are bugs (memory manager works with tp_basicsize and tp_itemsize, not with __sizeof__ result) and tests do not test it. In paranoidal mode we should tests both __sizeof__ and object.__sizeof__. For all classes, even

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: [Martin] The patch that Meador committed is incorrect: METH_NOARGS functions still take a PyObject* args argument, which will be NULL. Hmm. I see this usage in a lot of places---e.g. see unicode_capitalize, unicode_casefold, unicode_title

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: I will happily fix it, but if it is wrong one place, then it is wrong everywhere. Yes, it is wrong everywhere. METH_NOARGS functions do take an args argument, see ceval.c:call_function. -- ___

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Hmm. I see this usage in a lot of places---e.g. see unicode_capitalize, unicode_casefold, unicode_title etc. in Objects/unicodeobject.c. So it looks like we're relying on the (PyCFunction) cast to convert from a one-argument function

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: The compiler has no chance to find out. You cast the pointer to PyCFunction, telling the compiler that it really is a PyCFunction. True; I was thinking that the compiler should have the necessary information to warn about the suspicious

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Stefan Krah
Stefan Krah stefan-use...@bytereef.org added the comment: Everywhere is nowhere close to the truth. There are tons of NOARGS functions which have the correct signature. When I started writing C-extensions, I used the PyObject *unused idiom. Then I saw Meador's version in so many places in the

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Jesús Cea Avión
Jesús Cea Avión j...@jcea.es added the comment: I think that C standard actually documents the parameter order placement, so you can left out the last ones in the actual function definition. So, that this is working is not an accident, it is a C standard requirement. I think... --

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Jesús: this is a (common) mistake. Standard C makes it undefined behavior to call a function with an incorrect number of arguments, see 6.5.2.2p9 # If the function is defined with a type that is not compatible with the # type (of the

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Stefan: not sure whether raising this to python-dev really helps; see also msg42177, msg58196, issue1648268, and msg75239. Feel free to raise it, though. -- ___ Python tracker

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: While looking this up in the C Standard (ISO/IEC 9899:TC3) I also noticed 6.3.2.3p8: A pointer to a function of one type may be converted to a pointer to a function of another type and back again; the result shall compare equal to the original

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Jesús Cea Avión
Jesús Cea Avión j...@jcea.es added the comment: So the good old int main(void) behaviour is undefined :-) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Jesús Cea Avión
Jesús Cea Avión j...@jcea.es added the comment: Talking about this, anybody has an electronic version of C Standard to share with me, or should I hunt around the dark corners of Internet? :-) -- ___ Python tracker rep...@bugs.python.org

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: On Wed, Jul 25, 2012 at 5:38 PM, Jesús Cea Avión rep...@bugs.python.org wrote: So the good old int main(void) behaviour is undefined :-) Actually the C Standard says that is OK. See 5.1.2.2.1 of ISO/IEC 9899:TC3. --

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: The attached patch fixes: (1) the test cases to make them exact (inspired by 'test_sys.py'), (2) the definition of 's_sizeof' to add the dummy parameter, and (3) simplifies the sizeof calculation using 's_len'. -- Added file:

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Talking about this, anybody has an electronic version of C Standard to share with me, or should I hunt around the dark corners of Internet? :-) http://www.open-std.org/jtc1/sc22/wg14/www/standards (see n1256.pdf). --

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: So the good old int main(void) behaviour is undefined :-) No, it's not; see 5.1.2.2.1p1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: issue15402-redux-v1.patch LGTM. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___

[issue15402] Correct __sizeof__ support for struct

2012-07-25 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: +# The size of 'PyStructObject'  +totalsize = size(self.header + '5P') What if use totalsize = object.__sizeof__(struct_obj) ? -- ___ Python tracker rep...@bugs.python.org

[issue15402] Correct __sizeof__ support for struct

2012-07-24 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: I agree with Martin on having tests for the exact values and the s_len + 1 point. I will fix both issues. -- assignee: - meador.inge nosy: -python-dev stage: patch review - needs patch ___ Python

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: OK, I will commit this sometime today. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset dbe7f39ff341 by Meador Inge in branch '2.7': Issue #15402: Add a __sizeof__ method to struct.Struct. http://hg.python.org/cpython/rev/dbe7f39ff341 New changeset 3e7b517e1b68 by Meador Inge in branch '3.2': Issue

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: Thanks for the patch Serhiy! -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Jesús Cea Avión
Jesús Cea Avión j...@jcea.es added the comment: We collide mid-air, Meador. I was just checking-in this :-). I have changed the tests to actually verify the changes :-). Also added to Doc/ACKS.txt. Could I suggest you to take care of issue #15424 too?. -- resolution: fixed - stage:

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset b1d85a44f149 by Jesus Cea in branch '2.7': Better test for Issue #15402: Add a __sizeof__ method to struct.Struct http://hg.python.org/cpython/rev/b1d85a44f149 New changeset 1911e192af0d by Jesus Cea in branch

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: Hi Jesús, I replied to python-dev, but the Doc/ACKS.txt changes aren't necessary and I was OK with the way Serhiy submitted the tests. -- ___ Python tracker rep...@bugs.python.org

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: The patch that Meador committed is incorrect: METH_NOARGS functions still take a PyObject* args argument, which will be NULL. I'm puzzled, as Serhiy's original patch was correct. As for the tests, I really wish there were tests that tested

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Also, I wonder why this loops over s_codes, instead of just looking at s_len+1. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402

[issue15402] Correct __sizeof__ support for struct

2012-07-23 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: On Mon, Jul 23, 2012 at 5:04 PM, Martin v. Löwis rep...@bugs.python.org wrote: The patch that Meador committed is incorrect: METH_NOARGS functions still take a PyObject* args argument, which will be NULL. I'm puzzled, as Serhiy's original

[issue15402] Correct __sizeof__ support for struct

2012-07-22 Thread Andrew Svetlov
Andrew Svetlov andrew.svet...@gmail.com added the comment: +1 for patch applying in 3.3 at least -- nosy: +asvetlov ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___

[issue15402] Correct __sizeof__ support for struct

2012-07-20 Thread Serhiy Storchaka
New submission from Serhiy Storchaka storch...@gmail.com: Here is a patch that implements __sizeof__ for struct.Struct. See also issue14596. -- components: Library (Lib) files: struct_sizeof-2.patch keywords: patch messages: 165902 nosy: mark.dickinson, meador.inge, storchaka priority:

[issue15402] Correct __sizeof__ support for struct

2012-07-20 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402 ___ ___ Python-bugs-list mailing list

[issue15402] Correct __sizeof__ support for struct

2012-07-20 Thread Meador Inge
Meador Inge mead...@gmail.com added the comment: Module a few cosmetic changes (variable names and doc string tweaks), the patch looks good. Having a correct answer for `sys.getsizeof(struct.Struct('100B'))` is definitely better. Per the documentation for 'sys.getsizeof' [1]: All built-in

[issue15402] Correct __sizeof__ support for struct

2012-07-20 Thread Jesús Cea Avión
Jesús Cea Avión j...@jcea.es added the comment: The patch is easy. I want this in 3.3. Reluctant to touch 2.7 and 3.2, thought. I would be +0 to it. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15402

[issue15402] Correct __sizeof__ support for struct

2012-07-20 Thread Gregory P. Smith
Gregory P. Smith g...@krypto.org added the comment: makes sense for 3.3 as i would consider it a bug. i think it is reasonable for 2.7 and 3.2 as well, it is an actual bug that the value reported to getsizeof on struct.Struct is meaningless. -- nosy: +gregory.p.smith