diff Modules/_decimal/_decimal.c @ 78707:1a7abcdff030

In the 32-bit build, dec_hash() raised InvalidOperation if the operand had a coefficient with MAX_PREC=425000000 digits and a negative exponent. Increasing the context limits above the official values fixes the issue and is safe (in this case!).
author Stefan Krah <skrah@bytereef.org>
date Wed, 22 Aug 2012 19:11:50 +0200
parents bd6f9315a0f0
children fcc1e7ca9a48
line wrap: on
line diff
--- a/Modules/_decimal/_decimal.c	Wed Aug 22 18:54:37 2012 +0200
+++ b/Modules/_decimal/_decimal.c	Wed Aug 22 19:11:50 2012 +0200
@@ -4338,6 +4338,11 @@
     }
     tmp->exp = 0;
     mpd_set_positive(tmp);
+
+    maxctx.prec = MPD_MAX_PREC + 21;
+    maxctx.emax = MPD_MAX_EMAX + 21;
+    maxctx.emin = MPD_MIN_EMIN - 21;
+
     mpd_qmul(tmp, tmp, exp_hash, &maxctx, &status);
     mpd_qrem(tmp, tmp, &p, &maxctx, &status);
 
@@ -4346,11 +4351,14 @@
     result = (result == -1) ? -2 : result;
 
     if (status != 0) {
-        status |= MPD_Invalid_operation;
-        if (dec_addstatus(context, status)) {
-            result = -1;
-            goto finish;
+        if (status & MPD_Malloc_error) {
+            goto malloc_error;
         }
+        else {
+            PyErr_SetString(PyExc_RuntimeError,
+                "dec_hash: internal error: please report");
+        }
+        result = -1;
     }