Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: Changeset: r93761:deaebc8ec57a Date: 2018-02-05 12:52 +0100 http://bitbucket.org/pypy/pypy/changeset/deaebc8ec57a/
Log: argh!!! Fix 0l % 0l and 0l % 0 to raise ZeroDivisionError :-( diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -782,10 +782,12 @@ @jit.elidable def mod(self, other): + if other.sign == 0: + raise ZeroDivisionError("long division or modulo by zero") if self.sign == 0: return NULLRBIGINT - if other.sign != 0 and other.numdigits() == 1: + if other.numdigits() == 1: digit = other.digit(0) if digit == 1: return NULLRBIGINT @@ -819,6 +821,8 @@ @jit.elidable def int_mod(self, other): + if other == 0: + raise ZeroDivisionError("long division or modulo by zero") if self.sign == 0: return NULLRBIGINT @@ -826,7 +830,7 @@ # Fallback to long. return self.mod(rbigint.fromint(other)) - elif other != 0: + if 1: # preserve indentation to preserve history digit = abs(other) if digit == 1: return NULLRBIGINT @@ -852,8 +856,6 @@ if rem == 0: return NULLRBIGINT mod = rbigint([_store_digit(rem)], -1 if self.sign < 0 else 1, 1) - else: - raise ZeroDivisionError("long division or modulo by zero") if mod.sign * (-1 if other < 0 else 1) == -1: mod = mod.int_add(other) diff --git a/rpython/rlib/test/test_rbigint.py b/rpython/rlib/test/test_rbigint.py --- a/rpython/rlib/test/test_rbigint.py +++ b/rpython/rlib/test/test_rbigint.py @@ -131,11 +131,12 @@ def test_mod(self): for op1 in gen_signs(long_vals): + rl_op1 = rbigint.fromlong(op1) for op2 in gen_signs(long_vals): + rl_op2 = rbigint.fromlong(op2) if not op2: + py.test.raises(ZeroDivisionError, rl_op1.mod, rl_op2) continue - rl_op1 = rbigint.fromlong(op1) - rl_op2 = rbigint.fromlong(op2) r1 = rl_op1.mod(rl_op2) r2 = op1 % op2 @@ -143,10 +144,11 @@ def test_int_mod(self): for x in gen_signs(long_vals): + op1 = rbigint.fromlong(x) for y in signed_int_vals: if not y: + py.test.raises(ZeroDivisionError, op1.int_mod, 0) continue - op1 = rbigint.fromlong(x) r1 = op1.int_mod(y) r2 = x % y assert r1.tolong() == r2 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit