[Python-bugs-list] [ python-Bugs-815062 ] Py_OVERFLOWED should be isinf() on openbsd

SourceForge.net noreply at sourceforge.net
Tue Sep 30 11:05:51 EDT 2003


Bugs item #815062, was opened at 2003-09-30 22:09
Message generated for change (Comment added) made by anthonybaxter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=815062&group_id=5470

Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Anthony Baxter (anthonybaxter)
Assigned to: Anthony Baxter (anthonybaxter)
Summary: Py_OVERFLOWED should be isinf() on openbsd

Initial Comment:
test_long and test_complex both fail on OpenBSD/x86.

The problem is essentially that:



>>> shuge = '12345' * 120 

>>> float(int(shuge))

Inf



while on everything else, this raises an OverflowError.



Making the #ifdef in Include/pyport.h that sets

Py_OVERFLOWED to isinf() also do the same for OpenBSD

fixes this. I'm proposing to fix this for 2.3.2,

because then we're passing all tests on openbsd (minus

the wackiness from the HP testdrive boxes).



Tim, is there any reason to not add an autoconf test

for the presence of isinf(), and always use it for

Py_OVERFLOWED if it's present? Using it on this Redhat

9 system doesn't seem to break anything (well, the test

suite passes).



Obviously not going to make the latter change for

2.3.2, but is it appropriate for the trunk?



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

>Comment By: Anthony Baxter (anthonybaxter)
Date: 2003-10-01 01:05

Message:
Logged In: YES 
user_id=29957

Have checked in the workaround. Tim, you might want to pad

out the FreeBSD note in the comment a bit, it was your

checkin that put it there in the first place ;)



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

Comment By: Tim Peters (tim_one)
Date: 2003-10-01 00:48

Message:
Logged In: YES 
user_id=31435

I would rather see it work than not work.  The problem is that 

a platform-specific #ifdef will never go away, even after the 

compiler optimization bug is fixed.  It will just sit there 

confusing future maintainers until the universe ends in heat 

death (we should only be so lucky <wink>).



So if it's put in, it needs a lot better commenting than the 

inaccurate



"""

* Some platforms have better way to spell this, so expect 

some #ifdef'ery.

"""



isinf() isn't a better way to spell HUGE_VAL, it's a non-

standard way to spell HUGE_VAL under a specific compiler 

with broken optimization.  All of that should be explained.  

Then at least a future maintainer might try, from time to time, 

to see whether the compiler in question has been fixed yet, 

so that the platform special-casing can be removed.



IOW, this is a pure hack to worm around a broken compiler, 

and should be documented as such.

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

Comment By: Anthony Baxter (anthonybaxter)
Date: 2003-10-01 00:31

Message:
Logged In: YES 
user_id=29957

Making OpenBSD use isinf() makes the compiler not screw it

up, so I'm strongly inclined toward that change for 2.3.2.

Tim, is this ok with you?



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

Comment By: Michael Hudson (mwh)
Date: 2003-09-30 23:39

Message:
Logged In: YES 
user_id=6656

*groan*



HUGE_VAL seems to be defined like so:



extern char __infinity[];

#define HUGE_VAL        (*(double *) __infinity)



adding what you suggest to pyport.h doesn't make any difference.



I can attach the -O and the -O2 assembler for the suspect

code if anyone's interested, but I'm no wizz at x86 assembly.

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

Comment By: Tim Peters (tim_one)
Date: 2003-09-30 23:31

Message:
Logged In: YES 
user_id=31435

I can't like the #ifdef solution because C99 says HUGE_VAL is 

returned in overflow cases, not necessarily an infinity.  That's 

why the original macro checks against HUGE_VAL instead of 

using Py_IS_INFINITY(X) (btw, replacing *that* with isinf() 

when possible would be wholly unobjectionable).



Michael, the reason optimization level makes a difference is 

probably an optimization bug:  some platforms define 

HUGE_VAL as a God-awful casted mess, so complicated that 

their own compilers can't deal with it correctly.  So it's 

possible that #define'ing Py_HUGE_VAL to a saner expression 

on this platform would have solved the problem too; as the 

comments before Py_HUGE_VAL say, we use Py_HUGE_VAL 

instead of HUGE_VAL because some platforms screw up 

HUGE_VAL.



An experiment:  with the original definition of 

Py_OVERFLOWED, try #define'ing



#define Py_HUGE_VAL ((double)(HUGE_VAL))



on this box and see what happens.  The thinking is that if 

HUGE_VAL expands to a float expression on this box, 

optimization is most likely to screw up an implicit conversion 

to double; making that conversion explicit may worm around 

an optimization bug then.

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

Comment By: Michael Hudson (mwh)
Date: 2003-09-30 23:09

Message:
Logged In: YES 
user_id=6656

it's compiler bogusness, it seems, unless the code in

PyLong_AsDouble is non-ansi in some way that currently

escapes the eye.  compiling -O2 or higher makes test_long

fail; -O or lower makes it pass.



gcc is 2.95.3 fwiw.

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

Comment By: Michael Hudson (mwh)
Date: 2003-09-30 22:41

Message:
Logged In: YES 
user_id=6656

while setting Py_OVERFLOWED to use isinf does indeed make

the tests pass on openbad, i'd be happier if i understood

why the other definition *doesn't* work...

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

Comment By: Anthony Baxter (anthonybaxter)
Date: 2003-09-30 22:23

Message:
Logged In: YES 
user_id=29957

--- pyport.h    4 Sep 2003 11:59:50 -0000       2.63

+++ pyport.h    30 Sep 2003 12:22:14 -0000

@@ -258,7 +258,7 @@

  *    X is evaluated more than once.

  * Some platforms have better way to spell this, so expect

some #ifdef'ery.

  */

-#ifdef __FreeBSD__

+#if defined(__FreeBSD__) || defined(__OpenBSD__)

 #define Py_OVERFLOWED(X) isinf(X)

 #else



makes test_long and test_complex pass on OpenBSD.



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

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



More information about the Python-bugs-list mailing list