[issue7355] Struct incorrectly compiles format strings

2009-11-19 Thread Steve Krenzel

New submission from Steve Krenzel :

The struct module has a calcsize() method which reports the size of the data 
for a specified format 
string. In some instances, to the best of my knowledge, this is wrong.

To repro:
>>> from struct import calcsize
>>> calcsize("ci")
8
>>> calcsize("ic")
5

The correct answer is 5 (a single byte character and a four byte int take up 5 
bytes of space). For 
some reason when a 'c' is followed by an 'i', this is wrong and instead 
allocates 4 bytes to the 'c'.
This has been verified in 2.6 and 2.5.

You can also repro this by using 's', '2c', and similar combinations in place 
of 'c'. as well as 'I' 
in place of 'i'. This might effect other combinations as well.

--
components: Library (Lib)
messages: 95467
nosy: sgk284
severity: normal
status: open
title: Struct incorrectly compiles format strings
type: behavior
versions: Python 2.5, Python 2.6

___
Python tracker 
<http://bugs.python.org/issue7355>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7355] Struct incorrectly compiles format strings

2009-11-19 Thread Steve Krenzel

Steve Krenzel  added the comment:

Just for clarification, why does "ci" get padded but "ic" doesn't? 
While I agree that updating the documentation would help clarify, 
perhaps either everything should be padded to word boundaries or 
nothing should.

It is weird behavior that "ic" != "ci". If both formats were 8 bytes 
then my first thought would have been "Oh, it's just getting padded", 
but with this inconsistency it appeared as a bug.

Whatever the reason behind this discrepancy is, it should definitely be 
included in the doc updates.

--

___
Python tracker 
<http://bugs.python.org/issue7355>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com