[Python-bugs-list] [ python-Bugs-404328 ] struct.calcsize returns wrong size
nobody
nobody@sourceforge.net
Mon, 26 Feb 2001 08:21:50 -0800
Artifact #404328, was updated on 2001-02-26 08:21
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=404328&group_id=5470
Category: Python Library
Group: None
Status: Open
Priority: 5
Submitted By: Nobody/Anonymous
Assigned to: Nobody/Anonymous
Summary: struct.calcsize returns wrong size
Initial Comment:
struct.calcsize returns the wrong size because it takes
into account the alignment of the type.
I needed to read a 56 packed structure and then write
it back.
Python insists that it needs 62 bytes for the fmt
'chl6s20schdhdh'
Using Python-2.1a2 source code I can get the correct
answer by
commenting out in Modules/structmodule.c
if (e == NULL)
return -1;
itemsize = e->size;
--> //size = align(size, c, e);
x = num * itemsize;
size += x;
Basically packing in a string doesn't require any
alignment. The alignment is neccesary once unpacking
takes place. However if the unpacking is done to a
local c variable then the alignment should not be a
problem e.g.
long Unpack_long(char * offset)
{
long value;
memcpy(&value,offset,sizeof(long);
return value;
}
Regards Rene de Zwart
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=404328&group_id=5470