[Python-Dev] struct.pack inconsistencies between platforms

2012-02-26 Thread pmon mail
Hi

I have found myself in the following troubling situation.

I'm running the following code on a Python 2.6.5 on Linux x86:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> len(struct.pack('L',0))
4

Works as expected and documented (http://docs.python.org/library/struct.html
).

I'm running the same code on a MacPro (OS X 10.7.3) and I'm getting the
following:
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on
darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> len(struct.pack('L',0))
8

Documentation clearly states that the 'L' is a 4 byte integer.

Is this a bug? I'm I missing something?

Thanks
PMon
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] struct.pack inconsistencies between platforms

2012-02-26 Thread pmon mail
Sounds reasonable for me. Thanks!

On Sun, Feb 26, 2012 at 3:16 PM, Eli Bendersky  wrote:

>
>
> On Sun, Feb 26, 2012 at 15:09, Paul Moore  wrote:
>
>> On 26 February 2012 12:34, Eli Bendersky  wrote:
>> > On Sun, Feb 26, 2012 at 12:33, pmon mail  wrote:
>> >> Documentation clearly states that the 'L' is a 4 byte integer.
>> >>
>> >> Is this a bug? I'm I missing something?
>> >>
>> >
>> > By default pack uses native size, not standard size. On a 64-bit
>> machine:
>>
>> As the OP points out, the documentation says that the "Standard Size"
>> is 4 bytes (http://docs.python.org/library/struct.html). While
>> "Standard Size" doesn't appear to be defined in the documentation, and
>> the start of the previous section (7.3.2.1. Byte Order, Size, and
>> Alignment) clearly states that C types are represented in native
>> format by default, the documentation could probably do with some
>> clarification.
>>
>>
> 7.2.3.1 says, shortly after the first table:
>
> "
>
> Native size and alignment are determined using the C compiler’s 
> sizeofexpression. This is always combined with native byte order.
>
> Standard size depends only on the format character; see the table in the 
> *Format
> Characters* 
> <http://docs.python.org/library/struct.html#format-characters>section.
> "
>
> To me this appears to be a reasonable definition of what "standard size"
> is.
>
> 7.3.2.2 says before the size table:
>
> "Format characters have the following meaning; the conversion between C
> and Python values should be obvious given their types. The ‘Standard size’
> column refers to the size of the packed value in bytes when using standard
> size; that is, when the format string starts with one of '<', '>', '!' or
> '='. When using native size, the size of the packed value is
> platform-dependent."
>
> Again, taken together with the previous quote, IMHO this defines the
> difference between standard and native sizes clearly. If you feel
> differently, feel free to open an issue suggesting a better explanation.
>
> Eli
>
>
>
>
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com