[Python-bugs-list] [ python-Bugs-538361 ] packing double yields garbage

SourceForge.net noreply@sourceforge.net
Tue, 07 Jan 2003 18:22:33 -0800


Bugs item #538361, was opened at 2002-04-02 12:54
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=538361&group_id=5470

Category: Python Library
Group: 3rd Party
Status: Open
Resolution: Invalid
Priority: 5
Submitted By: Mike Carifio (carifio)
Assigned to: Neal Norwitz (nnorwitz)
Summary: packing double yields garbage

Initial Comment:
On RH Linux 6.2/alpha (kernal 2.2.14-6.0), egcs-
2.91.66, python 2.2.1c2. I build python
from source and test_struct.py dies with
a floating point exception. I believe I've
found out why:


>>> import struct
>>> s = struct.pack("d", 3.14e20)
>>> struct.unpack("d", s)
(1.69270791053e-307,)


----------------------------------------------------------------------

>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-07 21:22

Message:
Logged In: YES 
user_id=33168

> Is our evidence that it's a compiler bug solely that turning
> optimization off made the problem go away?

Yes.  The test is failing right now:

http://www.lysator.liu.se/xenofarm/python/files/2437_6/testlog.txt

I built the test normally and got the same failure.  I built
python with -O0 and the test passed.

Python's code may have had a problem.  On 9/3/2002, rev 2.57
to Module/structmodule.c changed to use memcpy "to avoid
alignment errors."  That was from patch 601369 which
appeared to be necessary for MIPS.

The same code does work on a different alpha, running a
different kernel, different glibc, and different compiler. 
(It works with optimization.)

http://www.lysator.liu.se/xenofarm/python/files/2479_31/testlog.txt

Suggestions?


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-01-07 21:12

Message:
Logged In: YES 
user_id=31435

Is our evidence that it's a compiler bug solely that turning 
optimization off made the problem go away?  If so, that's a 
good clue but not definitive.  It could be that Python's C 
code is ill-defined in such a way that optimizing or not 
changes which kind of undefined behavior obtains.  To nail 
this really requires determining exactly which piece of the 
Python code changed behavior.  This may not be easy, and 
in some cases may even require digging into the generated 
machine code.

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-01-07 20:23

Message:
Logged In: YES 
user_id=33168

This same problem exists in the snake farm (RedHat 6.2/alpha
egcs 2.91.66).  It turned out to be a compiler bug.  Turning
optimization off fixed the problem.  Unless I hear
otherwise, I will close this bug report.

----------------------------------------------------------------------

Comment By: Christos Georgiou (tzot)
Date: 2002-09-04 12:41

Message:
Logged In: YES 
user_id=539787

I think it is something that might have been solved by patch
601369.  carifio, can you try downloading the latest
Modules/structmodule.c and try again?

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-04-07 18:19

Message:
Logged In: YES 
user_id=6380

- Does the same error occur in earlier versions (2.2,
2.1.2)?

- I'm relabeling this as platform-specific because it only
fails on alphas (not the world's most popular CPU
architecture).

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-04-02 16:24

Message:
Logged In: YES 
user_id=31435

Can you show what's in s?  As is, it's impossible to guess 
whether the problem is in pack() or unpack().  Life would 
be simpler if you started with a simpler float too (like, 
say, 1.0).

Something random that might help:  recompile structmodule.c 
with optimization turned off.

One other:  is this Alpha configured to run in big-endian 
or little-endian mode?

----------------------------------------------------------------------

Comment By: Mike Carifio (carifio)
Date: 2002-04-02 13:59

Message:
Logged In: YES 
user_id=503643

EV6 I think. Can I run a command to find out?


----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-04-02 13:51

Message:
Logged In: YES 
user_id=6656

Oh.  That means it might be our fault.  Damn.

Erm, clutching at straws: what flavour of alpha is this?  I'm 
guessing this is some kind of alignment problem.



----------------------------------------------------------------------

Comment By: Mike Carifio (carifio)
Date: 2002-04-02 13:48

Message:
Logged In: YES 
user_id=503643

I also tried this on RH7.*/alpha/2.4.something kernel
and gcc 2.95.something and got the same error. Actually,
it started with test_struct.py core dumping. I don't
actually need to pack doubles. I was just being a good
doobie.

----------------------------------------------------------------------

Comment By: Mike Carifio (carifio)
Date: 2002-04-02 13:47

Message:
Logged In: YES 
user_id=503643

I also tried this on RH7.*/alpha/2.4.something kernel
and gcc 2.95.something and got the same error. Actually,
it started with test_struct.py core dumping. I don't
actually need to pack doubles. I was just being a good
doobie.

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-04-02 13:33

Message:
Logged In: YES 
user_id=6656

Hmm, that looks broke.

However, I don't see this behaviour on sf's compile farm with 
221c1; I'm building 221c2 now, but I'd be amazed if it's 
different.

That machine has kernel 2.4.something and gcc 2.95.something, 
so is it possible that this is a now-fixed bug in one those 
(most likely the compiler)?


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=538361&group_id=5470