Bugs item #1455357, was opened at 2006-03-21 08:08
Message generated for change (Comment added) made by tim_one
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1455357&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Python 2.4
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Michael Yanowitz (yanowitz)
Assigned to: Nobody/Anonymous (nobody)
Summary: Incompatible size for long (int) in Python Win and Linux?
Initial Comment:
There appears to be a problem with
packing/unpacking long (and int) values when sending
data from Windows to Linux.
I am not sure if it is a bug or just due to
incompatibleness. Normally we think of long as being 4
bytes. However, on Linux, it might be 8 bytes (in
Python).
Here are good results in Windows, packing and
unpacking a long:
$ python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import struct
>>> p = struct.pack("L", 12345)
>>> p
'90\x00\x00'
>>> u = struct.unpack("L",p)
>>> u
(12345L,)
However, on Linux, I get slightly different results:
Python 2.4.1 (#1, May 16 2005, 15:15:14)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for
more information>>> import struct
>>> p = struct.pack("L", 12345)
>>> p
'90\x00\x00\x00\x00\x00\x00'
>>> u = struct.unpack("L",p)
>>> u
(12345L,)
This is annoying, because I want to be able to
send data from Windows to Linux (and vice-versa)
over a socket. I am new to Python, and the only
way I know of of doing that is by packing and
unpacking the data.
Please email me [EMAIL PROTECTED] if this
isn't a bug or there is a known work-around for
this problem.
Thanks in advance:
Michael Yanowitz
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2006-03-21 13:07
Message:
Logged In: YES
user_id=31435
I agree with closing this report, but we should point out
that Python _does_ solve most of this problem: don't use
"native mode" pack/unpack, use "standard mode" pack/unpack,
to transport values across architectures. Read the `struct`
docs for details. For example, struct.pack("!L", 12345)
uses 4-byte big-endian ("network") format regardless of the
platform it runs on.
----------------------------------------------------------------------
Comment By: Hye-Shik Chang (perky)
Date: 2006-03-21 08:30
Message:
Logged In: YES
user_id=55188
In C, the size of long depends on platform ABI. If you are
on a 64bit platform, long may be 8 bytes while you got 4
bytes in 32bit platforms. It's not Python's problem.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1455357&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com