]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Tue, 28 Jan 2003 19:40:35 +0000 (19:40 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Tue, 28 Jan 2003 19:40:35 +0000 (19:40 +0000)
Fix SF bug# 676155, RuntimeWarning with tp_compare

Check return value of PyLong_AsDouble(), it can return an error.

Lib/test/test_b1.py
Lib/test/test_long.py
Misc/NEWS
Objects/floatobject.c

index 15c93e577bdee8e4f50c2854bf6a5724932cb267..8fcc8664a8e6b6b8263aaeb174293cb7228f59a2 100644 (file)
@@ -97,6 +97,10 @@ if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
 if coerce(1, 1L) != (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
 if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
 
+try: coerce(0.5, long("12345" * 1000))
+except OverflowError: pass
+else: raise TestFailed, 'coerce(0.5, long("12345" * 1000))'
+
 print 'compile'
 compile('print 1\n', '', 'exec')
 
index 573ef75f2201c7d28101e239156660a5a2d2aeba..e6c4a35db96b7212c977eb3b8b9dded98bdf9f7a 100644 (file)
@@ -339,9 +339,10 @@ def test_float_overflow():
     for x in -2.0, -1.0, 0.0, 1.0, 2.0:
         verify(float(long(x)) == x)
 
+    shuge = '12345' * 1000
     huge = 1L << 30000
     mhuge = -huge
-    namespace = {'huge': huge, 'mhuge': mhuge, 'math': math}
+    namespace = {'huge': huge, 'mhuge': mhuge, 'shuge': shuge, 'math': math}
     for test in ["float(huge)", "float(mhuge)",
                  "complex(huge)", "complex(mhuge)",
                  "complex(huge, 1)", "complex(mhuge, 1)",
@@ -354,7 +355,8 @@ def test_float_overflow():
                  "1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.",
                  "math.sin(huge)", "math.sin(mhuge)",
                  "math.sqrt(huge)", "math.sqrt(mhuge)", # should do better
-                 "math.floor(huge)", "math.floor(mhuge)"]:
+                 "math.floor(huge)", "math.floor(mhuge)",
+                 "float(shuge) == long(shuge)"]:
 
         try:
             eval(test, namespace)
index 091501c9ed6557c5ee5ac900587d1aa6a271c3c0..b30adea2a97d54e8308a3810b3b8efab983ebfc2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -5,6 +5,9 @@ Release date: XX-XXX-2003
 - Bastion.py and rexec.py are disabled.  These modules are not safe in
   Python 2.2. or 2.3.
 
+- SF #676155: fixed errors when trying to convert a long integer
+  into a float which couldn't fit.
+
 - SF #660476 and #513033: broken threadstate swap in readline could
   cause fatal errors when a readline hook was being invoked while a
   background thread was active.
index 5fd13bcc1e83ddf4f3f42812c3cb14984f9a6ec9..0d07a02a45bf4043a83876da9ca33f5722c303ba 100644 (file)
@@ -625,7 +625,10 @@ float_coerce(PyObject **pv, PyObject **pw)
                return 0;
        }
        else if (PyLong_Check(*pw)) {
-               *pw = PyFloat_FromDouble(PyLong_AsDouble(*pw));
+               double x = PyLong_AsDouble(*pw);
+               if (x == -1.0 && PyErr_Occurred())
+                       return -1;
+               *pw = PyFloat_FromDouble(x);
                Py_INCREF(*pv);
                return 0;
        }