From: Neal Norwitz Date: Tue, 28 Jan 2003 19:40:35 +0000 (+0000) Subject: backport: X-Git-Tag: v2.2.3c1~164 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89d08cbd397537986ee3cfceb2a1afa3189f43ce;p=thirdparty%2FPython%2Fcpython.git backport: Fix SF bug# 676155, RuntimeWarning with tp_compare Check return value of PyLong_AsDouble(), it can return an error. --- diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index 15c93e577bde..8fcc8664a8e6 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -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') diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 573ef75f2201..e6c4a35db96b 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index 091501c9ed65..b30adea2a97d 100644 --- 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. diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 5fd13bcc1e83..0d07a02a45bf 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -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; }