Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r65358:1151bfc2e7f9 Date: 2013-07-11 22:33 +0200 http://bitbucket.org/pypy/pypy/changeset/1151bfc2e7f9/
Log: merge diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py --- a/pypy/module/_rawffi/test/test__rawffi.py +++ b/pypy/module/_rawffi/test/test__rawffi.py @@ -1107,6 +1107,14 @@ S2E = _rawffi.Structure([('bah', (EMPTY, 1))]) S2E.get_ffi_type() # does not hang + def test_overflow_error(self): + import _rawffi + A = _rawffi.Array('d') + arg1 = A(1) + raises(OverflowError, "arg1[0] = 10**900") + arg1.free() + + class AppTestAutoFree: spaceconfig = dict(usemodules=['_rawffi', 'struct']) diff --git a/pypy/module/rctime/test/test_rctime.py b/pypy/module/rctime/test/test_rctime.py --- a/pypy/module/rctime/test/test_rctime.py +++ b/pypy/module/rctime/test/test_rctime.py @@ -43,6 +43,7 @@ assert isinstance(res, str) rctime.ctime(rctime.time()) raises(ValueError, rctime.ctime, 1E200) + raises(OverflowError, rctime.ctime, 10**900) def test_gmtime(self): import time as rctime diff --git a/pypy/objspace/std/complexobject.py b/pypy/objspace/std/complexobject.py --- a/pypy/objspace/std/complexobject.py +++ b/pypy/objspace/std/complexobject.py @@ -126,10 +126,7 @@ return W_ComplexObject(w_int.intval, 0.0) def delegate_Long2Complex(space, w_long): - try: - dval = w_long.tofloat() - except OverflowError, e: - raise OperationError(space.w_OverflowError, space.wrap(str(e))) + dval = w_long.tofloat(space) return W_ComplexObject(dval, 0.0) def delegate_Float2Complex(space, w_float): diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py --- a/pypy/objspace/std/floatobject.py +++ b/pypy/objspace/std/floatobject.py @@ -62,11 +62,7 @@ # long-to-float delegation def delegate_Long2Float(space, w_longobj): - try: - return W_FloatObject(w_longobj.tofloat()) - except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("long int too large to convert to float")) + return W_FloatObject(w_longobj.tofloat(space)) # float__Float is supposed to do nothing, unless it has diff --git a/pypy/objspace/std/longobject.py b/pypy/objspace/std/longobject.py --- a/pypy/objspace/std/longobject.py +++ b/pypy/objspace/std/longobject.py @@ -26,8 +26,12 @@ def longval(self): return self.num.tolong() - def tofloat(self): - return self.num.tofloat() + def tofloat(self, space): + try: + return self.num.tofloat() + except OverflowError: + raise OperationError(space.w_OverflowError, + space.wrap("long int too large to convert to float")) def toint(self): return self.num.toint() @@ -66,7 +70,7 @@ return w_self.num def float_w(self, space): - return self.num.tofloat() + return self.tofloat(space) def int(self, space): if (type(self) is not W_LongObject and @@ -124,11 +128,7 @@ return long__Long(space, w_value) def float__Long(space, w_longobj): - try: - return space.newfloat(w_longobj.num.tofloat()) - except OverflowError: - raise OperationError(space.w_OverflowError, - space.wrap("long int too large to convert to float")) + return space.newfloat(w_longobj.tofloat(space)) def repr__Long(space, w_long): return space.wrap(w_long.num.repr()) diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py --- a/pypy/objspace/std/test/test_longobject.py +++ b/pypy/objspace/std/test/test_longobject.py @@ -18,6 +18,12 @@ w_obj = fromlong(42) assert space.unwrap(w_obj) == 42 + def test_overflow_error(self): + space = self.space + fromlong = lobj.W_LongObject.fromlong + w_big = fromlong(10**900) + space.raises_w(space.w_OverflowError, space.float_w, w_big) + def test_rint_variants(self): py.test.skip("XXX broken!") from rpython.rtyper.tool.rfficache import platform _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit