Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r84691:9008c74dc4a6
Date: 2016-05-25 17:27 -0700
http://bitbucket.org/pypy/pypy/changeset/9008c74dc4a6/

Log:    add 32bit only unsafe setters for test_decimal

diff --git a/lib_pypy/_decimal.py b/lib_pypy/_decimal.py
--- a/lib_pypy/_decimal.py
+++ b/lib_pypy/_decimal.py
@@ -161,6 +161,15 @@
 _codecs.register_error('_decimal_encode', _handle_decimaldigits)
 
 
+def _unsafe_check(name, lo, hi, value):
+    if not -_sys.maxsize-1 <= value <= _sys.maxsize:
+        raise OverflowError(
+            "Python int too large to convert to C ssize_t")
+    if not lo <= value <= hi:
+        raise ValueError("valid range for unsafe %s is [%d, %d]" %
+                         (name, lo, hi))
+
+
 # Decimal class
 
 _DEC_MINALLOC = 4
@@ -298,7 +307,8 @@
                 raise ValueError("exponent must be an integer")
             if not -_sys.maxsize-1 <= exponent <= _sys.maxsize:
                 # Compatibility with CPython
-                raise OverflowError()
+                raise OverflowError(
+                    "Python int too large to convert to C ssize_t")
 
         # coefficients
         if not digits and not is_special:
@@ -1501,6 +1511,19 @@
             _mpdec.mpd_free(output)
         return result.decode()
 
+    if _sys.maxsize < 2**63-1:
+        def _unsafe_setprec(self, value):
+            _unsafe_check('prec', 1, 1070000000, value)
+            self.ctx.prec = value
+
+        def _unsafe_setemin(self, value):
+            _unsafe_check('emin', -1070000000, 0, value)
+            self.ctx.emin = value
+
+        def _unsafe_setemax(self, value):
+            _unsafe_check('emax', 0, 1070000000, value)
+            self.ctx.emax = value
+
 
 class _SignalDict(_collections.abc.MutableMapping):
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to