Re: A bug in struct module on the 64-bit platform?

2005-12-01 Thread jepler
I'm guessing that the expected behavior is
 struct.calcsize('idi')
20
because the double should be aligned to an 8-byte boundary.
This is the case on my linux/x86_64 machine:
$ python -c 'import struct; print struct.calcsize(idi)'
20
I don't know much about 'itanium', but i'd be surprised if they
chose 4-byte alignment for doubles.

http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,180,00.html

Jeff


pgpgMOnsB8Jx5.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: A bug in struct module on the 64-bit platform?

2005-12-01 Thread Fredrik Lundh
Neal Norwitz wrote:

 I have a user who complained about how struct module computes C
 struct data size on Itanium2 based 64-bit machine.

 I wouldn't be surprised, but I don't understand the problem.

struct.calcsize('idi')
16
struct.calcsize('idid')
24
struct.calcsize('did')
20

 These are what I would expect on a 32 or 64 bit platform.  i == int, d
 == float.  ints are typically 4 bytes on 64 bit platforms.  If you want
 8 byte integers, you typically need to use longs (format letter is ell,
 l).

except that the 64-bit double should, on most 64-bit platforms, have
64-bit alignment, so

struct.calcsize('idi')

should be 4 bytes integer plus 4 bytes padding plus 8 bytes double plus
4 bytes integer, or 20 bytes.

I'd expect

struct.calcsize('idi')
20
struct.calcsize('idid')
32
struct.calcsize('did')
24

but I have no 64-bit box within reach just now...

or isn't native alignment the default?

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A bug in struct module on the 64-bit platform?

2005-12-01 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 This is the case on my linux/x86_64 machine:
 $ python -c 'import struct; print struct.calcsize(idi)'
 20
 I don't know much about 'itanium', but i'd be surprised if they
 chose 4-byte alignment for doubles.

oops.  missed your reply.

 http://h21007.www2.hp.com/dspp/tech/tech_TechDocumentDetailPage_IDX/1,1701,180,00.html

fwiw, the same applies to HP-UX:
http://devresource.hp.com/drc/STK/docs/refs/64concepts.jsp

maybe this is a Windows issue?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win64/win64/storing_a_64_bit_value.asp

I couldn't find anything on alignment, but maybe it's the LLP64 model
that's messing things up for the struct module?  running the following
snippet with different values for TYPE might help us figure this out:

#define TYPE char // try short, int, long, float
typedef struct { TYPE c; double x; } st_double;
main() {
printf(align = %d\n, (sizeof(st_double) - sizeof(double)));
}

/F 



-- 
http://mail.python.org/mailman/listinfo/python-list


A bug in struct module on the 64-bit platform?

2005-11-30 Thread [EMAIL PROTECTED]
Hi,

I have a user who complained about how struct module computes C
struct data size on Itanium2 based 64-bit machine.

His first reproducer was
--
#!/usr/local/bin/python
import struct
fmthead = '12id5i5d7id5i3di12i3di'
fmtsize = struct.calcsize(fmthead)
print fmthead,fmtsize
--
And it prints 12id5i5d7id5i3di12i3di 292

And he further provided
   struct.calcsize('idi')
   16
   struct.calcsize('idid')
   24
   struct.calcsize('did')
   20

In response to those, I created corresponding C struct and computed the
data size using sizeof operation (gcc was used for compilation), but
they don't seem to match.

Is this a known problem?

Best,
-Dong

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A bug in struct module on the 64-bit platform?

2005-11-30 Thread Neal Norwitz
[EMAIL PROTECTED] wrote:
 Hi,

 I have a user who complained about how struct module computes C
 struct data size on Itanium2 based 64-bit machine.

I wouldn't be surprised, but I don't understand the problem.

struct.calcsize('idi')
16
struct.calcsize('idid')
24
struct.calcsize('did')
20

These are what I would expect on a 32 or 64 bit platform.  i == int, d
== float.  ints are typically 4 bytes on 64 bit platforms.  If you want
8 byte integers, you typically need to use longs (format letter is ell,
l).

You didn't say which version of python, so it's possible this was a bug
that was fixed too.

On my system:

python: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for
GNU/Linux 2.4.1, dynamically linked (uses shared libs), not stripped

 struct.calcsize('l') #that's a lowercase ell
8

If you think it's a bug, you should file a bug report on source forge.

n

-- 
http://mail.python.org/mailman/listinfo/python-list